@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param string $target_dir Path of target dir |
35 | 35 | * @param string $filter Regex to filter files. If file matches this regex, the file is not copied. |
36 | 36 | * @param string $type If set as 'force'. Even if the file exists in target, the file is copied. |
37 | - * @return void |
|
37 | + * @return false|null |
|
38 | 38 | */ |
39 | 39 | function copyDir($source_dir, $target_dir, $filter = null, $type = null) |
40 | 40 | { |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * This function creates directories recursively, which means that if ancestors of the target directory does not exist, they will be created too. |
276 | 276 | * |
277 | 277 | * @param string $path_string Path of target directory |
278 | - * @return bool TRUE if success. It might return nothing when ftp is used and connection to the ftp address failed. |
|
278 | + * @return boolean|null TRUE if success. It might return nothing when ftp is used and connection to the ftp address failed. |
|
279 | 279 | */ |
280 | 280 | function makeDir($path_string) |
281 | 281 | { |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * @param string $url The address of the target file |
616 | 616 | * @param string $target_filename The location to store |
617 | 617 | * @param string $body HTTP request body |
618 | - * @param string $timeout Connection timeout |
|
618 | + * @param integer $timeout Connection timeout |
|
619 | 619 | * @param string $method GET/POST |
620 | 620 | * @param string $content_type Content type header of HTTP request |
621 | 621 | * @param string[] $headers Headers key value array. |
@@ -636,8 +636,8 @@ discard block |
||
636 | 636 | * Convert size in string into numeric value |
637 | 637 | * |
638 | 638 | * @see self::filesize() |
639 | - * @param $val Size in string (ex., 10, 10K, 10M, 10G ) |
|
640 | - * @return int converted size |
|
639 | + * @param string $val Size in string (ex., 10, 10K, 10M, 10G ) |
|
640 | + * @return double converted size |
|
641 | 641 | */ |
642 | 642 | function returnBytes($val) |
643 | 643 | { |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | * @param int $resize_height Height to resize |
688 | 688 | * @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type |
689 | 689 | * @param string $thumbnail_type Thumbnail type(crop, ratio) |
690 | - * @return bool TRUE: success, FALSE: failed |
|
690 | + * @return null|boolean TRUE: success, FALSE: failed |
|
691 | 691 | */ |
692 | 692 | function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop') |
693 | 693 | { |
@@ -1000,7 +1000,7 @@ discard block |
||
1000 | 1000 | * Check file exists. |
1001 | 1001 | * |
1002 | 1002 | * @param string $filename Target file name |
1003 | - * @return bool Returns FALSE if the file does not exists, or Returns full path file(string). |
|
1003 | + * @return string|false Returns FALSE if the file does not exists, or Returns full path file(string). |
|
1004 | 1004 | */ |
1005 | 1005 | function exists($filename) |
1006 | 1006 | { |
@@ -1011,8 +1011,8 @@ discard block |
||
1011 | 1011 | /** |
1012 | 1012 | * Check it is dir |
1013 | 1013 | * |
1014 | - * @param string $dir Target dir path |
|
1015 | - * @return bool Returns FALSE if the dir is not dir, or Returns full path of dir(string). |
|
1014 | + * @param string $path |
|
1015 | + * @return string|false Returns FALSE if the dir is not dir, or Returns full path of dir(string). |
|
1016 | 1016 | */ |
1017 | 1017 | function isDir($path) |
1018 | 1018 | { |
@@ -17,9 +17,9 @@ discard block |
||
17 | 17 | */ |
18 | 18 | function getRealPath($source) |
19 | 19 | { |
20 | - if(strlen($source) >= 2 && substr_compare($source, './', 0, 2) === 0) |
|
20 | + if (strlen($source) >= 2 && substr_compare($source, './', 0, 2) === 0) |
|
21 | 21 | { |
22 | - return _XE_PATH_ . substr($source, 2); |
|
22 | + return _XE_PATH_.substr($source, 2); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | return $source; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | { |
41 | 41 | $source_dir = self::getRealPath($source_dir); |
42 | 42 | $target_dir = self::getRealPath($target_dir); |
43 | - if(!is_dir($source_dir)) |
|
43 | + if (!is_dir($source_dir)) |
|
44 | 44 | { |
45 | 45 | return FALSE; |
46 | 46 | } |
@@ -48,44 +48,44 @@ discard block |
||
48 | 48 | // generate when no target exists |
49 | 49 | self::makeDir($target_dir); |
50 | 50 | |
51 | - if(substr($source_dir, -1) != DIRECTORY_SEPARATOR) |
|
51 | + if (substr($source_dir, -1) != DIRECTORY_SEPARATOR) |
|
52 | 52 | { |
53 | 53 | $source_dir .= DIRECTORY_SEPARATOR; |
54 | 54 | } |
55 | 55 | |
56 | - if(substr($target_dir, -1) != DIRECTORY_SEPARATOR) |
|
56 | + if (substr($target_dir, -1) != DIRECTORY_SEPARATOR) |
|
57 | 57 | { |
58 | 58 | $target_dir .= DIRECTORY_SEPARATOR; |
59 | 59 | } |
60 | 60 | |
61 | 61 | $oDir = dir($source_dir); |
62 | - while($file = $oDir->read()) |
|
62 | + while ($file = $oDir->read()) |
|
63 | 63 | { |
64 | - if($file{0} == '.') |
|
64 | + if ($file{0} == '.') |
|
65 | 65 | { |
66 | 66 | continue; |
67 | 67 | } |
68 | 68 | |
69 | - if($filter && preg_match($filter, $file)) |
|
69 | + if ($filter && preg_match($filter, $file)) |
|
70 | 70 | { |
71 | 71 | continue; |
72 | 72 | } |
73 | 73 | |
74 | - if(is_dir($source_dir . $file)) |
|
74 | + if (is_dir($source_dir.$file)) |
|
75 | 75 | { |
76 | - self::copyDir($source_dir . $file, $target_dir . $file, $type); |
|
76 | + self::copyDir($source_dir.$file, $target_dir.$file, $type); |
|
77 | 77 | } |
78 | 78 | else |
79 | 79 | { |
80 | - if($type == 'force') |
|
80 | + if ($type == 'force') |
|
81 | 81 | { |
82 | - @unlink($target_dir . $file); |
|
82 | + @unlink($target_dir.$file); |
|
83 | 83 | } |
84 | 84 | else |
85 | 85 | { |
86 | - if(!file_exists($target_dir . $file)) |
|
86 | + if (!file_exists($target_dir.$file)) |
|
87 | 87 | { |
88 | - @copy($source_dir . $file, $target_dir . $file); |
|
88 | + @copy($source_dir.$file, $target_dir.$file); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | |
111 | 111 | self::makeDir($target_dir); |
112 | 112 | |
113 | - if($force == 'Y') |
|
113 | + if ($force == 'Y') |
|
114 | 114 | { |
115 | - @unlink($target_dir . DIRECTORY_SEPARATOR . $target); |
|
115 | + @unlink($target_dir.DIRECTORY_SEPARATOR.$target); |
|
116 | 116 | } |
117 | 117 | |
118 | - @copy($source, $target_dir . DIRECTORY_SEPARATOR . $target); |
|
118 | + @copy($source, $target_dir.DIRECTORY_SEPARATOR.$target); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | function readFile($filename) |
128 | 128 | { |
129 | - if(($filename = self::exists($filename)) === FALSE || filesize($filename) < 1) |
|
129 | + if (($filename = self::exists($filename)) === FALSE || filesize($filename) < 1) |
|
130 | 130 | { |
131 | 131 | return; |
132 | 132 | } |
@@ -149,12 +149,12 @@ discard block |
||
149 | 149 | self::makeDir($pathinfo['dirname']); |
150 | 150 | |
151 | 151 | $flags = 0; |
152 | - if(strtolower($mode) == 'a') |
|
152 | + if (strtolower($mode) == 'a') |
|
153 | 153 | { |
154 | 154 | $flags = FILE_APPEND; |
155 | 155 | } |
156 | 156 | |
157 | - @file_put_contents($filename, $buff, $flags|LOCK_EX); |
|
157 | + @file_put_contents($filename, $buff, $flags | LOCK_EX); |
|
158 | 158 | @chmod($filename, 0644); |
159 | 159 | self::clearStatCache($filename); |
160 | 160 | self::invalidateOpcache($filename); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | function moveFile($source, $target) |
196 | 196 | { |
197 | - if(($source = self::exists($source)) !== FALSE) |
|
197 | + if (($source = self::exists($source)) !== FALSE) |
|
198 | 198 | { |
199 | 199 | self::removeFile($target); |
200 | 200 | return self::rename($source, $target); |
@@ -232,35 +232,35 @@ discard block |
||
232 | 232 | $path = self::getRealPath($path); |
233 | 233 | $output = array(); |
234 | 234 | |
235 | - if(substr($path, -1) != '/') |
|
235 | + if (substr($path, -1) != '/') |
|
236 | 236 | { |
237 | 237 | $path .= '/'; |
238 | 238 | } |
239 | 239 | |
240 | - if(!is_dir($path)) |
|
240 | + if (!is_dir($path)) |
|
241 | 241 | { |
242 | 242 | return $output; |
243 | 243 | } |
244 | 244 | |
245 | 245 | $files = scandir($path); |
246 | - foreach($files as $file) |
|
246 | + foreach ($files as $file) |
|
247 | 247 | { |
248 | - if($file{0} == '.' || ($filter && !preg_match($filter, $file))) |
|
248 | + if ($file{0} == '.' || ($filter && !preg_match($filter, $file))) |
|
249 | 249 | { |
250 | 250 | continue; |
251 | 251 | } |
252 | 252 | |
253 | - if($to_lower) |
|
253 | + if ($to_lower) |
|
254 | 254 | { |
255 | 255 | $file = strtolower($file); |
256 | 256 | } |
257 | 257 | |
258 | - if($filter) |
|
258 | + if ($filter) |
|
259 | 259 | { |
260 | 260 | $file = preg_replace($filter, '$1', $file); |
261 | 261 | } |
262 | 262 | |
263 | - if($concat_prefix) |
|
263 | + if ($concat_prefix) |
|
264 | 264 | { |
265 | 265 | $file = sprintf('%s%s', str_replace(_XE_PATH_, '', $path), $file); |
266 | 266 | } |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | */ |
282 | 282 | function makeDir($path_string) |
283 | 283 | { |
284 | - if(self::exists($path_string) !== FALSE) |
|
284 | + if (self::exists($path_string) !== FALSE) |
|
285 | 285 | { |
286 | 286 | return TRUE; |
287 | 287 | } |
288 | 288 | |
289 | - if(!ini_get('safe_mode')) |
|
289 | + if (!ini_get('safe_mode')) |
|
290 | 290 | { |
291 | 291 | @mkdir($path_string, 0755, TRUE); |
292 | 292 | @chmod($path_string, 0755); |
@@ -297,35 +297,35 @@ discard block |
||
297 | 297 | static $oFtp = NULL; |
298 | 298 | |
299 | 299 | $ftp_info = Context::getFTPInfo(); |
300 | - if($oFtp == NULL) |
|
300 | + if ($oFtp == NULL) |
|
301 | 301 | { |
302 | - if(!Context::isFTPRegisted()) |
|
302 | + if (!Context::isFTPRegisted()) |
|
303 | 303 | { |
304 | 304 | return; |
305 | 305 | } |
306 | 306 | |
307 | - require_once(_XE_PATH_ . 'libs/ftp.class.php'); |
|
307 | + require_once(_XE_PATH_.'libs/ftp.class.php'); |
|
308 | 308 | $oFtp = new ftp(); |
309 | - if(!$ftp_info->ftp_host) |
|
309 | + if (!$ftp_info->ftp_host) |
|
310 | 310 | { |
311 | 311 | $ftp_info->ftp_host = "127.0.0.1"; |
312 | 312 | } |
313 | - if(!$ftp_info->ftp_port) |
|
313 | + if (!$ftp_info->ftp_port) |
|
314 | 314 | { |
315 | 315 | $ftp_info->ftp_port = 21; |
316 | 316 | } |
317 | - if(!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) |
|
317 | + if (!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) |
|
318 | 318 | { |
319 | 319 | return; |
320 | 320 | } |
321 | - if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) |
|
321 | + if (!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) |
|
322 | 322 | { |
323 | 323 | $oFtp->ftp_quit(); |
324 | 324 | return; |
325 | 325 | } |
326 | 326 | } |
327 | 327 | |
328 | - if(!($ftp_path = $ftp_info->ftp_root_path)) |
|
328 | + if (!($ftp_path = $ftp_info->ftp_root_path)) |
|
329 | 329 | { |
330 | 330 | $ftp_path = DIRECTORY_SEPARATOR; |
331 | 331 | } |
@@ -334,19 +334,19 @@ discard block |
||
334 | 334 | $path_list = explode(DIRECTORY_SEPARATOR, $path_string); |
335 | 335 | |
336 | 336 | $path = _XE_PATH_; |
337 | - for($i = 0, $c = count($path_list); $i < $c; $i++) |
|
337 | + for ($i = 0, $c = count($path_list); $i < $c; $i++) |
|
338 | 338 | { |
339 | - if(!$path_list[$i]) |
|
339 | + if (!$path_list[$i]) |
|
340 | 340 | { |
341 | 341 | continue; |
342 | 342 | } |
343 | 343 | |
344 | - $path .= $path_list[$i] . DIRECTORY_SEPARATOR; |
|
345 | - $ftp_path .= $path_list[$i] . DIRECTORY_SEPARATOR; |
|
346 | - if(!is_dir($path)) |
|
344 | + $path .= $path_list[$i].DIRECTORY_SEPARATOR; |
|
345 | + $ftp_path .= $path_list[$i].DIRECTORY_SEPARATOR; |
|
346 | + if (!is_dir($path)) |
|
347 | 347 | { |
348 | 348 | $oFtp->ftp_mkdir($ftp_path); |
349 | - $oFtp->ftp_site("CHMOD 777 " . $ftp_path); |
|
349 | + $oFtp->ftp_site("CHMOD 777 ".$ftp_path); |
|
350 | 350 | } |
351 | 351 | } |
352 | 352 | } |
@@ -362,23 +362,23 @@ discard block |
||
362 | 362 | */ |
363 | 363 | function removeDir($path) |
364 | 364 | { |
365 | - if(($path = self::isDir($path)) === FALSE) |
|
365 | + if (($path = self::isDir($path)) === FALSE) |
|
366 | 366 | { |
367 | 367 | return; |
368 | 368 | } |
369 | 369 | |
370 | - if(self::isDir($path)) |
|
370 | + if (self::isDir($path)) |
|
371 | 371 | { |
372 | 372 | $files = array_diff(scandir($path), array('..', '.')); |
373 | 373 | |
374 | - foreach($files as $file) |
|
374 | + foreach ($files as $file) |
|
375 | 375 | { |
376 | - if(($target = self::getRealPath($path . DIRECTORY_SEPARATOR . $file)) === FALSE) |
|
376 | + if (($target = self::getRealPath($path.DIRECTORY_SEPARATOR.$file)) === FALSE) |
|
377 | 377 | { |
378 | 378 | continue; |
379 | 379 | } |
380 | 380 | |
381 | - if(is_dir($target)) |
|
381 | + if (is_dir($target)) |
|
382 | 382 | { |
383 | 383 | self::removeDir($target); |
384 | 384 | } |
@@ -403,22 +403,22 @@ discard block |
||
403 | 403 | */ |
404 | 404 | function removeBlankDir($path) |
405 | 405 | { |
406 | - if(($path = self::isDir($path)) === FALSE) |
|
406 | + if (($path = self::isDir($path)) === FALSE) |
|
407 | 407 | { |
408 | 408 | return; |
409 | 409 | } |
410 | 410 | |
411 | 411 | $files = array_diff(scandir($path), array('..', '.')); |
412 | 412 | |
413 | - if(count($files) < 1) |
|
413 | + if (count($files) < 1) |
|
414 | 414 | { |
415 | 415 | rmdir($path); |
416 | 416 | return; |
417 | 417 | } |
418 | 418 | |
419 | - foreach($files as $file) |
|
419 | + foreach ($files as $file) |
|
420 | 420 | { |
421 | - if(($target = self::isDir($path . DIRECTORY_SEPARATOR . $file)) === FALSE) |
|
421 | + if (($target = self::isDir($path.DIRECTORY_SEPARATOR.$file)) === FALSE) |
|
422 | 422 | { |
423 | 423 | continue; |
424 | 424 | } |
@@ -437,23 +437,23 @@ discard block |
||
437 | 437 | */ |
438 | 438 | function removeFilesInDir($path) |
439 | 439 | { |
440 | - if(($path = self::getRealPath($path)) === FALSE) |
|
440 | + if (($path = self::getRealPath($path)) === FALSE) |
|
441 | 441 | { |
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
445 | - if(is_dir($path)) |
|
445 | + if (is_dir($path)) |
|
446 | 446 | { |
447 | 447 | $files = array_diff(scandir($path), array('..', '.')); |
448 | 448 | |
449 | - foreach($files as $file) |
|
449 | + foreach ($files as $file) |
|
450 | 450 | { |
451 | - if(($target = self::getRealPath($path . DIRECTORY_SEPARATOR . $file)) === FALSE) |
|
451 | + if (($target = self::getRealPath($path.DIRECTORY_SEPARATOR.$file)) === FALSE) |
|
452 | 452 | { |
453 | 453 | continue; |
454 | 454 | } |
455 | 455 | |
456 | - if(is_dir($target)) |
|
456 | + if (is_dir($target)) |
|
457 | 457 | { |
458 | 458 | self::removeFilesInDir($target); |
459 | 459 | } |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | } |
466 | 466 | else |
467 | 467 | { |
468 | - if(self::exists($path)) unlink($path); |
|
468 | + if (self::exists($path)) unlink($path); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | } |
@@ -479,22 +479,22 @@ discard block |
||
479 | 479 | */ |
480 | 480 | function filesize($size) |
481 | 481 | { |
482 | - if(!$size) |
|
482 | + if (!$size) |
|
483 | 483 | { |
484 | 484 | return '0Byte'; |
485 | 485 | } |
486 | 486 | |
487 | - if($size === 1) |
|
487 | + if ($size === 1) |
|
488 | 488 | { |
489 | 489 | return '1Byte'; |
490 | 490 | } |
491 | 491 | |
492 | - if($size < 1024) |
|
492 | + if ($size < 1024) |
|
493 | 493 | { |
494 | - return $size . 'Bytes'; |
|
494 | + return $size.'Bytes'; |
|
495 | 495 | } |
496 | 496 | |
497 | - if($size >= 1024 && $size < 1024 * 1024) |
|
497 | + if ($size >= 1024 && $size < 1024 * 1024) |
|
498 | 498 | { |
499 | 499 | return sprintf("%0.1fKB", $size / 1024); |
500 | 500 | } |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | */ |
520 | 520 | function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array()) |
521 | 521 | { |
522 | - require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php'); |
|
522 | + require_once(_XE_PATH_.'libs/idna_convert/idna_convert.class.php'); |
|
523 | 523 | $IDN = new idna_convert(array('idn_version' => 2008)); |
524 | 524 | $url = $IDN->encode($url); |
525 | 525 | |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | require_once('HTTP/Request.php'); |
530 | 530 | |
531 | 531 | $parsed_url = parse_url(__PROXY_SERVER__); |
532 | - if($parsed_url["host"] && $parsed_url["path"]) |
|
532 | + if ($parsed_url["host"] && $parsed_url["path"]) |
|
533 | 533 | { |
534 | 534 | // Old style proxy server support (POST payload to proxy script) |
535 | 535 | $oRequest = new HTTP_Request(__PROXY_SERVER__); |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | $oRequest = new HTTP_Request($url); |
542 | 542 | |
543 | 543 | // New style proxy server support (Use HTTP_Request2 native config format) |
544 | - if($parsed_url['host']) |
|
544 | + if ($parsed_url['host']) |
|
545 | 545 | { |
546 | 546 | $request_config['proxy_host'] = $parsed_url['host']; |
547 | 547 | $request_config['proxy_port'] = $parsed_url['port'] ? $parsed_url['port'] : ''; |
@@ -550,13 +550,13 @@ discard block |
||
550 | 550 | $request_config['proxy_type'] = $parsed_url['scheme'] ? $parsed_url['scheme'] : 'http'; |
551 | 551 | } |
552 | 552 | |
553 | - if(count($request_config) && method_exists($oRequest, 'setConfig')) |
|
553 | + if (count($request_config) && method_exists($oRequest, 'setConfig')) |
|
554 | 554 | { |
555 | - foreach($request_config as $key=>$val) |
|
555 | + foreach ($request_config as $key=>$val) |
|
556 | 556 | { |
557 | - if($key === 'observers') |
|
557 | + if ($key === 'observers') |
|
558 | 558 | { |
559 | - foreach($val as $observer) |
|
559 | + foreach ($val as $observer) |
|
560 | 560 | { |
561 | 561 | $oRequest->attach($observer); |
562 | 562 | } |
@@ -567,58 +567,58 @@ discard block |
||
567 | 567 | } |
568 | 568 | } |
569 | 569 | } |
570 | - if(method_exists($oRequest, 'setConfig')) |
|
570 | + if (method_exists($oRequest, 'setConfig')) |
|
571 | 571 | { |
572 | - if(extension_loaded('curl')) |
|
572 | + if (extension_loaded('curl')) |
|
573 | 573 | { |
574 | 574 | $oRequest->setConfig('adapter', 'curl'); |
575 | 575 | } |
576 | - elseif(version_compare(PHP_VERSION, '5.6', '<')) |
|
576 | + elseif (version_compare(PHP_VERSION, '5.6', '<')) |
|
577 | 577 | { |
578 | 578 | $oRequest->setConfig('ssl_verify_host', false); |
579 | 579 | } |
580 | - if(file_exists(_XE_PATH_ . 'libs/cacert/cacert.pem')) |
|
580 | + if (file_exists(_XE_PATH_.'libs/cacert/cacert.pem')) |
|
581 | 581 | { |
582 | - $oRequest->setConfig('ssl_cafile', _XE_PATH_ . 'libs/cacert/cacert.pem'); |
|
582 | + $oRequest->setConfig('ssl_cafile', _XE_PATH_.'libs/cacert/cacert.pem'); |
|
583 | 583 | } |
584 | 584 | } |
585 | 585 | |
586 | - if(count($headers) > 0) |
|
586 | + if (count($headers) > 0) |
|
587 | 587 | { |
588 | - foreach($headers as $key => $val) |
|
588 | + foreach ($headers as $key => $val) |
|
589 | 589 | { |
590 | 590 | $oRequest->addHeader($key, $val); |
591 | 591 | } |
592 | 592 | } |
593 | 593 | $host = parse_url($url, PHP_URL_HOST); |
594 | - if($cookies[$host]) |
|
594 | + if ($cookies[$host]) |
|
595 | 595 | { |
596 | - foreach($cookies[$host] as $key => $val) |
|
596 | + foreach ($cookies[$host] as $key => $val) |
|
597 | 597 | { |
598 | 598 | $oRequest->addCookie($key, $val); |
599 | 599 | } |
600 | 600 | } |
601 | - if(count($post_data) > 0) |
|
601 | + if (count($post_data) > 0) |
|
602 | 602 | { |
603 | - foreach($post_data as $key => $val) |
|
603 | + foreach ($post_data as $key => $val) |
|
604 | 604 | { |
605 | 605 | $oRequest->addPostData($key, $val); |
606 | 606 | } |
607 | 607 | } |
608 | - if(!$content_type) |
|
608 | + if (!$content_type) |
|
609 | 609 | $oRequest->addHeader('Content-Type', 'text/html'); |
610 | 610 | else |
611 | 611 | $oRequest->addHeader('Content-Type', $content_type); |
612 | 612 | $oRequest->setMethod($method); |
613 | - if($body) |
|
613 | + if ($body) |
|
614 | 614 | $oRequest->setBody($body); |
615 | 615 | } |
616 | 616 | |
617 | - if(method_exists($oRequest, 'setConfig')) |
|
617 | + if (method_exists($oRequest, 'setConfig')) |
|
618 | 618 | { |
619 | 619 | $oRequest->setConfig('timeout', $timeout); |
620 | 620 | } |
621 | - elseif(property_exists($oRequest, '_timeout')) |
|
621 | + elseif (property_exists($oRequest, '_timeout')) |
|
622 | 622 | { |
623 | 623 | $oRequest->_timeout = $timeout; |
624 | 624 | } |
@@ -628,25 +628,25 @@ discard block |
||
628 | 628 | $code = $oRequest->getResponseCode(); |
629 | 629 | $header = $oRequest->getResponseHeader(); |
630 | 630 | $response = $oRequest->getResponseBody(); |
631 | - if($c = $oRequest->getResponseCookies()) |
|
631 | + if ($c = $oRequest->getResponseCookies()) |
|
632 | 632 | { |
633 | - foreach($c as $k => $v) |
|
633 | + foreach ($c as $k => $v) |
|
634 | 634 | { |
635 | 635 | $cookies[$host][$v['name']] = $v['value']; |
636 | 636 | } |
637 | 637 | } |
638 | 638 | |
639 | - if($code > 300 && $code < 399 && $header['location']) |
|
639 | + if ($code > 300 && $code < 399 && $header['location']) |
|
640 | 640 | { |
641 | 641 | return self::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data); |
642 | 642 | } |
643 | 643 | |
644 | - if($code != 200) |
|
644 | + if ($code != 200) |
|
645 | 645 | { |
646 | 646 | return; |
647 | 647 | } |
648 | 648 | |
649 | - if(isset($request_config['store_body']) && !$request_config['store_body']) |
|
649 | + if (isset($request_config['store_body']) && !$request_config['store_body']) |
|
650 | 650 | { |
651 | 651 | return TRUE; |
652 | 652 | } |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | return $response; |
656 | 656 | } |
657 | 657 | } |
658 | - catch(Exception $e) |
|
658 | + catch (Exception $e) |
|
659 | 659 | { |
660 | 660 | return NULL; |
661 | 661 | } |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | self::clearStatCache($target_filename); |
690 | 690 | self::invalidateOpcache($target_filename); |
691 | 691 | } |
692 | - catch(Exception $e) |
|
692 | + catch (Exception $e) |
|
693 | 693 | { |
694 | 694 | return FALSE; |
695 | 695 | } |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | function returnBytes($val) |
707 | 707 | { |
708 | 708 | $unit = strtoupper(substr($val, -1)); |
709 | - $val = (float)$val; |
|
709 | + $val = (float) $val; |
|
710 | 710 | |
711 | 711 | switch ($unit) |
712 | 712 | { |
@@ -729,13 +729,13 @@ discard block |
||
729 | 729 | $K64 = 65536; |
730 | 730 | $TWEAKFACTOR = 2.0; |
731 | 731 | $channels = $imageInfo['channels']; |
732 | - if(!$channels) |
|
732 | + if (!$channels) |
|
733 | 733 | { |
734 | 734 | $channels = 6; //for png |
735 | 735 | } |
736 | - $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $channels / 8 + $K64 ) * $TWEAKFACTOR); |
|
736 | + $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $channels / 8 + $K64) * $TWEAKFACTOR); |
|
737 | 737 | $availableMemory = self::returnBytes(ini_get('memory_limit')) - memory_get_usage(); |
738 | - if($availableMemory < $memoryNeeded) |
|
738 | + if ($availableMemory < $memoryNeeded) |
|
739 | 739 | { |
740 | 740 | return FALSE; |
741 | 741 | } |
@@ -762,30 +762,30 @@ discard block |
||
762 | 762 | } |
763 | 763 | |
764 | 764 | $target_file = self::getRealPath($target_file); |
765 | - if(!$resize_width) |
|
765 | + if (!$resize_width) |
|
766 | 766 | { |
767 | 767 | $resize_width = 100; |
768 | 768 | } |
769 | 769 | |
770 | - if(!$resize_height) |
|
770 | + if (!$resize_height) |
|
771 | 771 | { |
772 | 772 | $resize_height = $resize_width; |
773 | 773 | } |
774 | 774 | |
775 | 775 | // retrieve source image's information |
776 | 776 | $imageInfo = getimagesize($source_file); |
777 | - if(!self::checkMemoryLoadImage($imageInfo)) |
|
777 | + if (!self::checkMemoryLoadImage($imageInfo)) |
|
778 | 778 | { |
779 | 779 | return FALSE; |
780 | 780 | } |
781 | 781 | |
782 | 782 | list($width, $height, $type, $attrs) = $imageInfo; |
783 | - if($width < 1 || $height < 1) |
|
783 | + if ($width < 1 || $height < 1) |
|
784 | 784 | { |
785 | 785 | return; |
786 | 786 | } |
787 | 787 | |
788 | - switch($type) |
|
788 | + switch ($type) |
|
789 | 789 | { |
790 | 790 | case '1' : |
791 | 791 | $type = 'gif'; |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | return; |
804 | 804 | } |
805 | 805 | |
806 | - if(!$target_type) |
|
806 | + if (!$target_type) |
|
807 | 807 | { |
808 | 808 | $target_type = $type; |
809 | 809 | } |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | $height_per = ($resize_height > 0 && $height >= $resize_height) ? $resize_height / $height : 1; |
815 | 815 | |
816 | 816 | $per = NULL; |
817 | - if($thumbnail_type == 'ratio') |
|
817 | + if ($thumbnail_type == 'ratio') |
|
818 | 818 | { |
819 | 819 | $per = ($width_per > $height_per) ? $height_per : $width_per; |
820 | 820 | $resize_width = $width * $per; |
@@ -827,16 +827,16 @@ discard block |
||
827 | 827 | |
828 | 828 | // create temporary image with target size |
829 | 829 | $thumb = NULL; |
830 | - if(function_exists('imagecreateTRUEcolor')) |
|
830 | + if (function_exists('imagecreateTRUEcolor')) |
|
831 | 831 | { |
832 | 832 | $thumb = imagecreateTRUEcolor($resize_width, $resize_height); |
833 | 833 | } |
834 | - else if(function_exists('imagecreate')) |
|
834 | + else if (function_exists('imagecreate')) |
|
835 | 835 | { |
836 | 836 | $thumb = imagecreate($resize_width, $resize_height); |
837 | 837 | } |
838 | 838 | |
839 | - if(!$thumb) |
|
839 | + if (!$thumb) |
|
840 | 840 | { |
841 | 841 | return FALSE; |
842 | 842 | } |
@@ -845,37 +845,37 @@ discard block |
||
845 | 845 | |
846 | 846 | // create temporary image having original type |
847 | 847 | $source = NULL; |
848 | - switch($type) |
|
848 | + switch ($type) |
|
849 | 849 | { |
850 | 850 | case 'gif' : |
851 | - if(function_exists('imagecreatefromgif')) |
|
851 | + if (function_exists('imagecreatefromgif')) |
|
852 | 852 | { |
853 | 853 | $source = @imagecreatefromgif($source_file); |
854 | 854 | } |
855 | 855 | break; |
856 | 856 | case 'jpeg' : |
857 | 857 | case 'jpg' : |
858 | - if(function_exists('imagecreatefromjpeg')) |
|
858 | + if (function_exists('imagecreatefromjpeg')) |
|
859 | 859 | { |
860 | 860 | $source = @imagecreatefromjpeg($source_file); |
861 | 861 | } |
862 | 862 | break; |
863 | 863 | case 'png' : |
864 | - if(function_exists('imagecreatefrompng')) |
|
864 | + if (function_exists('imagecreatefrompng')) |
|
865 | 865 | { |
866 | 866 | $source = @imagecreatefrompng($source_file); |
867 | 867 | } |
868 | 868 | break; |
869 | 869 | case 'wbmp' : |
870 | 870 | case 'bmp' : |
871 | - if(function_exists('imagecreatefromwbmp')) |
|
871 | + if (function_exists('imagecreatefromwbmp')) |
|
872 | 872 | { |
873 | 873 | $source = @imagecreatefromwbmp($source_file); |
874 | 874 | } |
875 | 875 | break; |
876 | 876 | } |
877 | 877 | |
878 | - if(!$source) |
|
878 | + if (!$source) |
|
879 | 879 | { |
880 | 880 | imagedestroy($thumb); |
881 | 881 | return FALSE; |
@@ -887,13 +887,13 @@ discard block |
||
887 | 887 | |
888 | 888 | $x = 0; |
889 | 889 | $y = 0; |
890 | - if($thumbnail_type == 'crop') |
|
890 | + if ($thumbnail_type == 'crop') |
|
891 | 891 | { |
892 | 892 | $x = (int) ($resize_width / 2 - $new_width / 2); |
893 | 893 | $y = (int) ($resize_height / 2 - $new_height / 2); |
894 | 894 | } |
895 | 895 | |
896 | - if(function_exists('imagecopyresampled')) |
|
896 | + if (function_exists('imagecopyresampled')) |
|
897 | 897 | { |
898 | 898 | imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); |
899 | 899 | } |
@@ -907,30 +907,30 @@ discard block |
||
907 | 907 | |
908 | 908 | // write into the file |
909 | 909 | $output = NULL; |
910 | - switch($target_type) |
|
910 | + switch ($target_type) |
|
911 | 911 | { |
912 | 912 | case 'gif' : |
913 | - if(function_exists('imagegif')) |
|
913 | + if (function_exists('imagegif')) |
|
914 | 914 | { |
915 | 915 | $output = imagegif($thumb, $target_file); |
916 | 916 | } |
917 | 917 | break; |
918 | 918 | case 'jpeg' : |
919 | 919 | case 'jpg' : |
920 | - if(function_exists('imagejpeg')) |
|
920 | + if (function_exists('imagejpeg')) |
|
921 | 921 | { |
922 | 922 | $output = imagejpeg($thumb, $target_file, 100); |
923 | 923 | } |
924 | 924 | break; |
925 | 925 | case 'png' : |
926 | - if(function_exists('imagepng')) |
|
926 | + if (function_exists('imagepng')) |
|
927 | 927 | { |
928 | 928 | $output = imagepng($thumb, $target_file, 9); |
929 | 929 | } |
930 | 930 | break; |
931 | 931 | case 'wbmp' : |
932 | 932 | case 'bmp' : |
933 | - if(function_exists('imagewbmp')) |
|
933 | + if (function_exists('imagewbmp')) |
|
934 | 934 | { |
935 | 935 | $output = imagewbmp($thumb, $target_file, 100); |
936 | 936 | } |
@@ -940,7 +940,7 @@ discard block |
||
940 | 940 | imagedestroy($thumb); |
941 | 941 | imagedestroy($source); |
942 | 942 | |
943 | - if(!$output) |
|
943 | + if (!$output) |
|
944 | 944 | { |
945 | 945 | return FALSE; |
946 | 946 | } |
@@ -958,12 +958,12 @@ discard block |
||
958 | 958 | */ |
959 | 959 | function readIniFile($filename) |
960 | 960 | { |
961 | - if(($filename = self::exists($filename)) === FALSE) |
|
961 | + if (($filename = self::exists($filename)) === FALSE) |
|
962 | 962 | { |
963 | 963 | return FALSE; |
964 | 964 | } |
965 | 965 | $arr = parse_ini_file($filename, TRUE); |
966 | - if(is_array($arr) && count($arr) > 0) |
|
966 | + if (is_array($arr) && count($arr) > 0) |
|
967 | 967 | { |
968 | 968 | return $arr; |
969 | 969 | } |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | */ |
990 | 990 | function writeIniFile($filename, $arr) |
991 | 991 | { |
992 | - if(!is_array($arr) || count($arr) == 0) |
|
992 | + if (!is_array($arr) || count($arr) == 0) |
|
993 | 993 | { |
994 | 994 | return FALSE; |
995 | 995 | } |
@@ -1006,19 +1006,19 @@ discard block |
||
1006 | 1006 | function _makeIniBuff($arr) |
1007 | 1007 | { |
1008 | 1008 | $return = array(); |
1009 | - foreach($arr as $key => $val) |
|
1009 | + foreach ($arr as $key => $val) |
|
1010 | 1010 | { |
1011 | 1011 | // section |
1012 | - if(is_array($val)) |
|
1012 | + if (is_array($val)) |
|
1013 | 1013 | { |
1014 | 1014 | $return[] = sprintf("[%s]", $key); |
1015 | - foreach($val as $k => $v) |
|
1015 | + foreach ($val as $k => $v) |
|
1016 | 1016 | { |
1017 | 1017 | $return[] = sprintf("%s=\"%s\"", $k, $v); |
1018 | 1018 | } |
1019 | 1019 | // value |
1020 | 1020 | } |
1021 | - else if(is_object($val)) |
|
1021 | + else if (is_object($val)) |
|
1022 | 1022 | { |
1023 | 1023 | continue; |
1024 | 1024 | } |
@@ -1093,15 +1093,15 @@ discard block |
||
1093 | 1093 | function isWritableDir($path) |
1094 | 1094 | { |
1095 | 1095 | $path = self::getRealPath($path); |
1096 | - if(is_dir($path)==FALSE) |
|
1096 | + if (is_dir($path) == FALSE) |
|
1097 | 1097 | { |
1098 | 1098 | return FALSE; |
1099 | 1099 | } |
1100 | 1100 | |
1101 | - $checkFile = $path . '/_CheckWritableDir'; |
|
1101 | + $checkFile = $path.'/_CheckWritableDir'; |
|
1102 | 1102 | |
1103 | 1103 | $fp = fopen($checkFile, 'w'); |
1104 | - if(!is_resource($fp)) |
|
1104 | + if (!is_resource($fp)) |
|
1105 | 1105 | { |
1106 | 1106 | return FALSE; |
1107 | 1107 | } |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | **/ |
1120 | 1120 | static public function clearStatCache($target, $include = false) |
1121 | 1121 | { |
1122 | - if(is_array($target)) |
|
1122 | + if (is_array($target)) |
|
1123 | 1123 | { |
1124 | 1124 | array_map('self::clearStatCache', $target); |
1125 | 1125 | return; |
@@ -1127,7 +1127,7 @@ discard block |
||
1127 | 1127 | |
1128 | 1128 | $target = self::getRealPath($target); |
1129 | 1129 | |
1130 | - if($include && self::isDir($target)) |
|
1130 | + if ($include && self::isDir($target)) |
|
1131 | 1131 | { |
1132 | 1132 | self::clearStatCache(self::readDir($target, '', false, true), $include); |
1133 | 1133 | } |
@@ -1145,27 +1145,27 @@ discard block |
||
1145 | 1145 | { |
1146 | 1146 | static $opcache = null; |
1147 | 1147 | |
1148 | - if($opcache === null) |
|
1148 | + if ($opcache === null) |
|
1149 | 1149 | { |
1150 | 1150 | $opcache = (function_exists('opcache_get_status') && function_exists('opcache_invalidate')); |
1151 | 1151 | } |
1152 | 1152 | |
1153 | - if($opcache === false) |
|
1153 | + if ($opcache === false) |
|
1154 | 1154 | { |
1155 | 1155 | return; |
1156 | 1156 | } |
1157 | 1157 | |
1158 | - if(is_array($target)) |
|
1158 | + if (is_array($target)) |
|
1159 | 1159 | { |
1160 | 1160 | array_map('self::invalidateOpcache', $target); |
1161 | 1161 | return; |
1162 | 1162 | } |
1163 | 1163 | |
1164 | - if(substr($target, -4) === '.php') |
|
1164 | + if (substr($target, -4) === '.php') |
|
1165 | 1165 | { |
1166 | 1166 | opcache_invalidate(self::getRealPath($target), $force); |
1167 | 1167 | } |
1168 | - else if($path = self::isDir($target)) |
|
1168 | + else if ($path = self::isDir($target)) |
|
1169 | 1169 | { |
1170 | 1170 | self::invalidateOpcache(self::readDir($path, '', false, true)); |
1171 | 1171 | } |
@@ -74,14 +74,12 @@ discard block |
||
74 | 74 | if(is_dir($source_dir . $file)) |
75 | 75 | { |
76 | 76 | self::copyDir($source_dir . $file, $target_dir . $file, $type); |
77 | - } |
|
78 | - else |
|
77 | + } else |
|
79 | 78 | { |
80 | 79 | if($type == 'force') |
81 | 80 | { |
82 | 81 | @unlink($target_dir . $file); |
83 | - } |
|
84 | - else |
|
82 | + } else |
|
85 | 83 | { |
86 | 84 | if(!file_exists($target_dir . $file)) |
87 | 85 | { |
@@ -381,15 +379,13 @@ discard block |
||
381 | 379 | if(is_dir($target)) |
382 | 380 | { |
383 | 381 | self::removeDir($target); |
384 | - } |
|
385 | - else |
|
382 | + } else |
|
386 | 383 | { |
387 | 384 | unlink($target); |
388 | 385 | } |
389 | 386 | } |
390 | 387 | rmdir($path); |
391 | - } |
|
392 | - else |
|
388 | + } else |
|
393 | 389 | { |
394 | 390 | unlink($path); |
395 | 391 | } |
@@ -456,16 +452,16 @@ discard block |
||
456 | 452 | if(is_dir($target)) |
457 | 453 | { |
458 | 454 | self::removeFilesInDir($target); |
459 | - } |
|
460 | - else |
|
455 | + } else |
|
461 | 456 | { |
462 | 457 | unlink($target); |
463 | 458 | } |
464 | 459 | } |
465 | - } |
|
466 | - else |
|
460 | + } else |
|
467 | 461 | { |
468 | - if(self::exists($path)) unlink($path); |
|
462 | + if(self::exists($path)) { |
|
463 | + unlink($path); |
|
464 | + } |
|
469 | 465 | } |
470 | 466 | |
471 | 467 | } |
@@ -535,8 +531,7 @@ discard block |
||
535 | 531 | $oRequest = new HTTP_Request(__PROXY_SERVER__); |
536 | 532 | $oRequest->setMethod('POST'); |
537 | 533 | $oRequest->addPostData('arg', serialize(array('Destination' => $url, 'method' => $method, 'body' => $body, 'content_type' => $content_type, "headers" => $headers, "post_data" => $post_data))); |
538 | - } |
|
539 | - else |
|
534 | + } else |
|
540 | 535 | { |
541 | 536 | $oRequest = new HTTP_Request($url); |
542 | 537 | |
@@ -560,8 +555,7 @@ discard block |
||
560 | 555 | { |
561 | 556 | $oRequest->attach($observer); |
562 | 557 | } |
563 | - } |
|
564 | - else |
|
558 | + } else |
|
565 | 559 | { |
566 | 560 | $oRequest->setConfig($key, $val); |
567 | 561 | } |
@@ -572,8 +566,7 @@ discard block |
||
572 | 566 | if(extension_loaded('curl')) |
573 | 567 | { |
574 | 568 | $oRequest->setConfig('adapter', 'curl'); |
575 | - } |
|
576 | - elseif(version_compare(PHP_VERSION, '5.6', '<')) |
|
569 | + } elseif(version_compare(PHP_VERSION, '5.6', '<')) |
|
577 | 570 | { |
578 | 571 | $oRequest->setConfig('ssl_verify_host', false); |
579 | 572 | } |
@@ -605,20 +598,21 @@ discard block |
||
605 | 598 | $oRequest->addPostData($key, $val); |
606 | 599 | } |
607 | 600 | } |
608 | - if(!$content_type) |
|
609 | - $oRequest->addHeader('Content-Type', 'text/html'); |
|
610 | - else |
|
611 | - $oRequest->addHeader('Content-Type', $content_type); |
|
601 | + if(!$content_type) { |
|
602 | + $oRequest->addHeader('Content-Type', 'text/html'); |
|
603 | + } else { |
|
604 | + $oRequest->addHeader('Content-Type', $content_type); |
|
605 | + } |
|
612 | 606 | $oRequest->setMethod($method); |
613 | - if($body) |
|
614 | - $oRequest->setBody($body); |
|
607 | + if($body) { |
|
608 | + $oRequest->setBody($body); |
|
609 | + } |
|
615 | 610 | } |
616 | 611 | |
617 | 612 | if(method_exists($oRequest, 'setConfig')) |
618 | 613 | { |
619 | 614 | $oRequest->setConfig('timeout', $timeout); |
620 | - } |
|
621 | - elseif(property_exists($oRequest, '_timeout')) |
|
615 | + } elseif(property_exists($oRequest, '_timeout')) |
|
622 | 616 | { |
623 | 617 | $oRequest->_timeout = $timeout; |
624 | 618 | } |
@@ -649,13 +643,11 @@ discard block |
||
649 | 643 | if(isset($request_config['store_body']) && !$request_config['store_body']) |
650 | 644 | { |
651 | 645 | return TRUE; |
652 | - } |
|
653 | - else |
|
646 | + } else |
|
654 | 647 | { |
655 | 648 | return $response; |
656 | 649 | } |
657 | - } |
|
658 | - catch(Exception $e) |
|
650 | + } catch(Exception $e) |
|
659 | 651 | { |
660 | 652 | return NULL; |
661 | 653 | } |
@@ -688,8 +680,7 @@ discard block |
||
688 | 680 | $result = self::getRemoteResource($url, $body, $timeout, $method, $content_type, $headers, $cookies, $post_data, $request_config); |
689 | 681 | self::clearStatCache($target_filename); |
690 | 682 | self::invalidateOpcache($target_filename); |
691 | - } |
|
692 | - catch(Exception $e) |
|
683 | + } catch(Exception $e) |
|
693 | 684 | { |
694 | 685 | return FALSE; |
695 | 686 | } |
@@ -819,8 +810,7 @@ discard block |
||
819 | 810 | $per = ($width_per > $height_per) ? $height_per : $width_per; |
820 | 811 | $resize_width = $width * $per; |
821 | 812 | $resize_height = $height * $per; |
822 | - } |
|
823 | - else |
|
813 | + } else |
|
824 | 814 | { |
825 | 815 | $per = ($width_per < $height_per) ? $height_per : $width_per; |
826 | 816 | } |
@@ -830,8 +820,7 @@ discard block |
||
830 | 820 | if(function_exists('imagecreateTRUEcolor')) |
831 | 821 | { |
832 | 822 | $thumb = imagecreateTRUEcolor($resize_width, $resize_height); |
833 | - } |
|
834 | - else if(function_exists('imagecreate')) |
|
823 | + } else if(function_exists('imagecreate')) |
|
835 | 824 | { |
836 | 825 | $thumb = imagecreate($resize_width, $resize_height); |
837 | 826 | } |
@@ -896,8 +885,7 @@ discard block |
||
896 | 885 | if(function_exists('imagecopyresampled')) |
897 | 886 | { |
898 | 887 | imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); |
899 | - } |
|
900 | - else |
|
888 | + } else |
|
901 | 889 | { |
902 | 890 | imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); |
903 | 891 | } |
@@ -966,8 +954,7 @@ discard block |
||
966 | 954 | if(is_array($arr) && count($arr) > 0) |
967 | 955 | { |
968 | 956 | return $arr; |
969 | - } |
|
970 | - else |
|
957 | + } else |
|
971 | 958 | { |
972 | 959 | return array(); |
973 | 960 | } |
@@ -1017,12 +1004,10 @@ discard block |
||
1017 | 1004 | $return[] = sprintf("%s=\"%s\"", $k, $v); |
1018 | 1005 | } |
1019 | 1006 | // value |
1020 | - } |
|
1021 | - else if(is_object($val)) |
|
1007 | + } else if(is_object($val)) |
|
1022 | 1008 | { |
1023 | 1009 | continue; |
1024 | - } |
|
1025 | - else |
|
1010 | + } else |
|
1026 | 1011 | { |
1027 | 1012 | $return[] = sprintf("%s=\"%s\"", $key, $val); |
1028 | 1013 | } |
@@ -1164,8 +1149,7 @@ discard block |
||
1164 | 1149 | if(substr($target, -4) === '.php') |
1165 | 1150 | { |
1166 | 1151 | opcache_invalidate(self::getRealPath($target), $force); |
1167 | - } |
|
1168 | - else if($path = self::isDir($target)) |
|
1152 | + } else if($path = self::isDir($target)) |
|
1169 | 1153 | { |
1170 | 1154 | self::invalidateOpcache(self::readDir($path, '', false, true)); |
1171 | 1155 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Mether to add key/value pair to the HTTP request header |
54 | - * @param int|string $key HTTP header element |
|
54 | + * @param string $key HTTP header element |
|
55 | 55 | * @param string $value value string for HTTP header element |
56 | 56 | * @return void |
57 | 57 | */ |
@@ -97,8 +97,7 @@ discard block |
||
97 | 97 | if(FALSE && is_callable('curl_init')) |
98 | 98 | { |
99 | 99 | return $this->sendWithCurl($target, $method, $timeout, $post_vars); |
100 | - } |
|
101 | - else |
|
100 | + } else |
|
102 | 101 | { |
103 | 102 | return $this->sendWithSock($target, $method, $timeout, $post_vars); |
104 | 103 | } |
@@ -179,8 +178,7 @@ discard block |
||
179 | 178 | { |
180 | 179 | $body .= fgets($sock, $chunk_size+1); |
181 | 180 | } |
182 | - } |
|
183 | - else |
|
181 | + } else |
|
184 | 182 | { |
185 | 183 | $body .= fgets($sock, 512); |
186 | 184 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * constructor |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - function XEHttpRequest($host, $port, $scheme='') |
|
44 | + function XEHttpRequest($host, $port, $scheme = '') |
|
45 | 45 | { |
46 | 46 | $this->m_host = $host; |
47 | 47 | $this->m_port = $port; |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | $this->addToHeader('Connection', 'close'); |
77 | 77 | |
78 | 78 | $method = strtoupper($method); |
79 | - if(!$allow_methods) |
|
79 | + if (!$allow_methods) |
|
80 | 80 | { |
81 | 81 | $allow_methods = explode(' ', 'GET POST PUT'); |
82 | 82 | } |
83 | - if(!in_array($method, $allow_methods)) |
|
83 | + if (!in_array($method, $allow_methods)) |
|
84 | 84 | { |
85 | 85 | $method = $allow_methods[0]; |
86 | 86 | } |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | $timout = max((int) $timeout, 0); |
90 | 90 | |
91 | 91 | // list of post variables |
92 | - if(!is_array($post_vars)) |
|
92 | + if (!is_array($post_vars)) |
|
93 | 93 | { |
94 | 94 | $post_vars = array(); |
95 | 95 | } |
96 | 96 | |
97 | - if(FALSE && is_callable('curl_init')) |
|
97 | + if (FALSE && is_callable('curl_init')) |
|
98 | 98 | { |
99 | 99 | return $this->sendWithCurl($target, $method, $timeout, $post_vars); |
100 | 100 | } |
@@ -117,30 +117,30 @@ discard block |
||
117 | 117 | static $crlf = "\r\n"; |
118 | 118 | |
119 | 119 | $scheme = ''; |
120 | - if($this->m_scheme=='https') |
|
120 | + if ($this->m_scheme == 'https') |
|
121 | 121 | { |
122 | 122 | $scheme = 'ssl://'; |
123 | 123 | } |
124 | 124 | |
125 | - $sock = @fsockopen($scheme . $this->m_host, $this->m_port, $errno, $errstr, $timeout); |
|
126 | - if(!$sock) |
|
125 | + $sock = @fsockopen($scheme.$this->m_host, $this->m_port, $errno, $errstr, $timeout); |
|
126 | + if (!$sock) |
|
127 | 127 | { |
128 | 128 | return new BaseObject(-1, 'socket_connect_failed'); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $headers = $this->m_headers + array(); |
132 | - if(!isset($headers['Accept-Encoding'])) |
|
132 | + if (!isset($headers['Accept-Encoding'])) |
|
133 | 133 | { |
134 | 134 | $headers['Accept-Encoding'] = 'identity'; |
135 | 135 | } |
136 | 136 | |
137 | 137 | // post body |
138 | 138 | $post_body = ''; |
139 | - if($method == 'POST' && count($post_vars)) |
|
139 | + if ($method == 'POST' && count($post_vars)) |
|
140 | 140 | { |
141 | - foreach($post_vars as $key => $value) |
|
141 | + foreach ($post_vars as $key => $value) |
|
142 | 142 | { |
143 | - $post_body .= urlencode($key) . '=' . urlencode($value) . '&'; |
|
143 | + $post_body .= urlencode($key).'='.urlencode($value).'&'; |
|
144 | 144 | } |
145 | 145 | $post_body = substr($post_body, 0, -1); |
146 | 146 | |
@@ -149,35 +149,35 @@ discard block |
||
149 | 149 | } |
150 | 150 | |
151 | 151 | $request = "$method $target HTTP/1.1$crlf"; |
152 | - foreach($headers as $equiv => $content) |
|
152 | + foreach ($headers as $equiv => $content) |
|
153 | 153 | { |
154 | 154 | $request .= "$equiv: $content$crlf"; |
155 | 155 | } |
156 | - $request .= $crlf . $post_body; |
|
156 | + $request .= $crlf.$post_body; |
|
157 | 157 | fwrite($sock, $request); |
158 | 158 | |
159 | 159 | list($httpver, $code, $status) = preg_split('/ +/', rtrim(fgets($sock)), 3); |
160 | 160 | |
161 | 161 | // read response headers |
162 | 162 | $is_chunked = FALSE; |
163 | - while(strlen(trim($line = fgets($sock)))) |
|
163 | + while (strlen(trim($line = fgets($sock)))) |
|
164 | 164 | { |
165 | 165 | list($equiv, $content) = preg_split('/ *: */', rtrim($line), 2); |
166 | - if(!strcasecmp($equiv, 'Transfer-Encoding') && $content == 'chunked') |
|
166 | + if (!strcasecmp($equiv, 'Transfer-Encoding') && $content == 'chunked') |
|
167 | 167 | { |
168 | 168 | $is_chunked = TRUE; |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | 172 | $body = ''; |
173 | - while(!feof($sock)) |
|
173 | + while (!feof($sock)) |
|
174 | 174 | { |
175 | - if($is_chunked) |
|
175 | + if ($is_chunked) |
|
176 | 176 | { |
177 | 177 | $chunk_size = hexdec(fgets($sock)); |
178 | - if($chunk_size) |
|
178 | + if ($chunk_size) |
|
179 | 179 | { |
180 | - $body .= fgets($sock, $chunk_size+1); |
|
180 | + $body .= fgets($sock, $chunk_size + 1); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | else |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
220 | 220 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
221 | 221 | |
222 | - switch($method) |
|
222 | + switch ($method) |
|
223 | 223 | { |
224 | 224 | case 'GET': curl_setopt($ch, CURLOPT_HTTPGET, true); |
225 | 225 | break; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | $arr_headers = array(); |
235 | - foreach($headers as $key => $value) |
|
235 | + foreach ($headers as $key => $value) |
|
236 | 236 | { |
237 | 237 | $arr_headers[] = "$key: $value"; |
238 | 238 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_headers); |
241 | 241 | |
242 | 242 | $body = curl_exec($ch); |
243 | - if(curl_errno($ch)) |
|
243 | + if (curl_errno($ch)) |
|
244 | 244 | { |
245 | 245 | return new BaseObject(-1, 'socket_connect_failed'); |
246 | 246 | } |
@@ -128,7 +128,7 @@ |
||
128 | 128 | /** |
129 | 129 | * Constructor function |
130 | 130 | * |
131 | - * @return void |
|
131 | + * @return string |
|
132 | 132 | */ |
133 | 133 | function Mail() |
134 | 134 | { |
@@ -151,8 +151,7 @@ discard block |
||
151 | 151 | if($this->isVaildMailAddress($account_name)) |
152 | 152 | { |
153 | 153 | $this->Username = $account_name; |
154 | - } |
|
155 | - else |
|
154 | + } else |
|
156 | 155 | { |
157 | 156 | $this->Username = $account_name . '@gmail.com'; |
158 | 157 | } |
@@ -190,8 +189,7 @@ discard block |
||
190 | 189 | $this->IsSMTP(); |
191 | 190 | $this->AltBody = "To view the message, please use an HTML compatible email viewer!"; |
192 | 191 | return TRUE; |
193 | - } |
|
194 | - else |
|
192 | + } else |
|
195 | 193 | { |
196 | 194 | $this->IsMail(); |
197 | 195 | return FALSE; |
@@ -246,8 +244,7 @@ discard block |
||
246 | 244 | { |
247 | 245 | $this->sender_name = $name; |
248 | 246 | $this->sender_email = $email; |
249 | - } |
|
250 | - else |
|
247 | + } else |
|
251 | 248 | { |
252 | 249 | $this->SetFrom($email, $name); |
253 | 250 | } |
@@ -280,8 +277,7 @@ discard block |
||
280 | 277 | { |
281 | 278 | $this->receiptor_name = $name; |
282 | 279 | $this->receiptor_email = $email; |
283 | - } |
|
284 | - else |
|
280 | + } else |
|
285 | 281 | { |
286 | 282 | $this->AddAddress($email, $name); |
287 | 283 | } |
@@ -312,8 +308,7 @@ discard block |
||
312 | 308 | if($this->Mailer == "mail") |
313 | 309 | { |
314 | 310 | $this->title = $title; |
315 | - } |
|
316 | - else |
|
311 | + } else |
|
317 | 312 | { |
318 | 313 | $this->Subject = $title; |
319 | 314 | } |
@@ -340,8 +335,7 @@ discard block |
||
340 | 335 | if($this->Mailer == "mail") |
341 | 336 | { |
342 | 337 | $this->bcc = $bcc; |
343 | - } |
|
344 | - else |
|
338 | + } else |
|
345 | 339 | { |
346 | 340 | $this->AddBCC($bcc); |
347 | 341 | } |
@@ -380,8 +374,7 @@ discard block |
||
380 | 374 | if($this->Mailer == "mail") |
381 | 375 | { |
382 | 376 | $this->replyTo = $replyTo; |
383 | - } |
|
384 | - else |
|
377 | + } else |
|
385 | 378 | { |
386 | 379 | $this->AddReplyTo($replyTo); |
387 | 380 | } |
@@ -399,8 +392,7 @@ discard block |
||
399 | 392 | if($this->Mailer == "mail") |
400 | 393 | { |
401 | 394 | $this->content = $content; |
402 | - } |
|
403 | - else |
|
395 | + } else |
|
404 | 396 | { |
405 | 397 | $this->MsgHTML($content); |
406 | 398 | } |
@@ -486,8 +478,7 @@ discard block |
||
486 | 478 | $this->body = implode("", $res); |
487 | 479 | $this->body .= "--" . $boundary . "--"; |
488 | 480 | } |
489 | - } |
|
490 | - else |
|
481 | + } else |
|
491 | 482 | { |
492 | 483 | if(count($this->attachments) > 0) |
493 | 484 | { |
@@ -578,8 +569,7 @@ discard block |
||
578 | 569 | return mail($this->getReceiptor(), $this->getTitle(), $this->body, $headers, $this->additional_params); |
579 | 570 | } |
580 | 571 | return mail($this->getReceiptor(), $this->getTitle(), $this->body, $headers); |
581 | - } |
|
582 | - else |
|
572 | + } else |
|
583 | 573 | { |
584 | 574 | $this->procAttachments(); |
585 | 575 | return parent::Send(); |
@@ -604,8 +594,7 @@ discard block |
||
604 | 594 | if(checkdnsrr($host, "MX") || checkdnsrr($host, "A")) |
605 | 595 | { |
606 | 596 | return TRUE; |
607 | - } |
|
608 | - else |
|
597 | + } else |
|
609 | 598 | { |
610 | 599 | return FALSE; |
611 | 600 | } |
@@ -624,8 +613,7 @@ discard block |
||
624 | 613 | if(preg_match("/([a-z0-9\_\-\.]+)@([a-z0-9\_\-\.]+)/i", $email_address)) |
625 | 614 | { |
626 | 615 | return $email_address; |
627 | - } |
|
628 | - else |
|
616 | + } else |
|
629 | 617 | { |
630 | 618 | return ''; |
631 | 619 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /* Copyright (C) NAVER <http://www.navercorp.com> */ |
3 | 3 | |
4 | -require_once _XE_PATH_ . "libs/phpmailer/phpmailer.php"; |
|
4 | +require_once _XE_PATH_."libs/phpmailer/phpmailer.php"; |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * Mailing class for XpressEngine |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | $this->SMTPSecure = "tls"; |
149 | 149 | $this->Host = 'smtp.gmail.com'; |
150 | 150 | $this->Port = '587'; |
151 | - if($this->isVaildMailAddress($account_name)) |
|
151 | + if ($this->isVaildMailAddress($account_name)) |
|
152 | 152 | { |
153 | 153 | $this->Username = $account_name; |
154 | 154 | } |
155 | 155 | else |
156 | 156 | { |
157 | - $this->Username = $account_name . '@gmail.com'; |
|
157 | + $this->Username = $account_name.'@gmail.com'; |
|
158 | 158 | } |
159 | 159 | $this->Password = $account_passwd; |
160 | 160 | $this->IsSMTP(); |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | $this->Password = $pass; |
181 | 181 | $this->Port = $port; |
182 | 182 | |
183 | - if($secure == 'ssl' || $secure == 'tls') |
|
183 | + if ($secure == 'ssl' || $secure == 'tls') |
|
184 | 184 | { |
185 | 185 | $this->SMTPSecure = $secure; |
186 | 186 | } |
187 | 187 | |
188 | - if(($this->SMTPAuth !== NULL && $this->Host !== NULL && $this->Username !== NULL && $this->Password !== NULL) || ($this->SMTPAuth === NULL && $this->Host !== NULL)) |
|
188 | + if (($this->SMTPAuth !== NULL && $this->Host !== NULL && $this->Username !== NULL && $this->Password !== NULL) || ($this->SMTPAuth === NULL && $this->Host !== NULL)) |
|
189 | 189 | { |
190 | 190 | $this->IsSMTP(); |
191 | 191 | $this->AltBody = "To view the message, please use an HTML compatible email viewer!"; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | */ |
243 | 243 | function setSender($name, $email) |
244 | 244 | { |
245 | - if($this->Mailer == "mail") |
|
245 | + if ($this->Mailer == "mail") |
|
246 | 246 | { |
247 | 247 | $this->sender_name = $name; |
248 | 248 | $this->sender_email = $email; |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | */ |
261 | 261 | function getSender() |
262 | 262 | { |
263 | - if(!stristr(PHP_OS, 'win') && $this->sender_name) |
|
263 | + if (!stristr(PHP_OS, 'win') && $this->sender_name) |
|
264 | 264 | { |
265 | - return sprintf("%s <%s>", '=?utf-8?b?' . base64_encode($this->sender_name) . '?=', $this->sender_email); |
|
265 | + return sprintf("%s <%s>", '=?utf-8?b?'.base64_encode($this->sender_name).'?=', $this->sender_email); |
|
266 | 266 | } |
267 | 267 | return $this->sender_email; |
268 | 268 | } |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | */ |
277 | 277 | function setReceiptor($name, $email) |
278 | 278 | { |
279 | - if($this->Mailer == "mail") |
|
279 | + if ($this->Mailer == "mail") |
|
280 | 280 | { |
281 | 281 | $this->receiptor_name = $name; |
282 | 282 | $this->receiptor_email = $email; |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | */ |
295 | 295 | function getReceiptor() |
296 | 296 | { |
297 | - if(!stristr(PHP_OS, 'win') && $this->receiptor_name && $this->receiptor_name != $this->receiptor_email) |
|
297 | + if (!stristr(PHP_OS, 'win') && $this->receiptor_name && $this->receiptor_name != $this->receiptor_email) |
|
298 | 298 | { |
299 | - return sprintf("%s <%s>", '=?utf-8?b?' . base64_encode($this->receiptor_name) . '?=', $this->receiptor_email); |
|
299 | + return sprintf("%s <%s>", '=?utf-8?b?'.base64_encode($this->receiptor_name).'?=', $this->receiptor_email); |
|
300 | 300 | } |
301 | 301 | return $this->receiptor_email; |
302 | 302 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | */ |
310 | 310 | function setTitle($title) |
311 | 311 | { |
312 | - if($this->Mailer == "mail") |
|
312 | + if ($this->Mailer == "mail") |
|
313 | 313 | { |
314 | 314 | $this->title = $title; |
315 | 315 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | */ |
327 | 327 | function getTitle() |
328 | 328 | { |
329 | - return '=?utf-8?b?' . base64_encode($this->title) . '?='; |
|
329 | + return '=?utf-8?b?'.base64_encode($this->title).'?='; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | */ |
338 | 338 | function setBCC($bcc) |
339 | 339 | { |
340 | - if($this->Mailer == "mail") |
|
340 | + if ($this->Mailer == "mail") |
|
341 | 341 | { |
342 | 342 | $this->bcc = $bcc; |
343 | 343 | } |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | */ |
378 | 378 | function setReplyTo($replyTo) |
379 | 379 | { |
380 | - if($this->Mailer == "mail") |
|
380 | + if ($this->Mailer == "mail") |
|
381 | 381 | { |
382 | 382 | $this->replyTo = $replyTo; |
383 | 383 | } |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | function setContent($content) |
397 | 397 | { |
398 | 398 | $content = preg_replace_callback('/<img([^>]+)>/i', array($this, 'replaceResourceRealPath'), $content); |
399 | - if($this->Mailer == "mail") |
|
399 | + if ($this->Mailer == "mail") |
|
400 | 400 | { |
401 | 401 | $this->content = $content; |
402 | 402 | } |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | */ |
416 | 416 | function replaceResourceRealPath($matches) |
417 | 417 | { |
418 | - return preg_replace('/src=(["\']?)files/i', 'src=$1' . Context::getRequestUri() . 'files', $matches[0]); |
|
418 | + return preg_replace('/src=(["\']?)files/i', 'src=$1'.Context::getRequestUri().'files', $matches[0]); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -456,42 +456,42 @@ discard block |
||
456 | 456 | */ |
457 | 457 | function procAttachments() |
458 | 458 | { |
459 | - if($this->Mailer == "mail") |
|
459 | + if ($this->Mailer == "mail") |
|
460 | 460 | { |
461 | - if(count($this->attachments) > 0) |
|
461 | + if (count($this->attachments) > 0) |
|
462 | 462 | { |
463 | - $this->body = $this->header . $this->body; |
|
464 | - $boundary = '----==' . uniqid(rand(), TRUE); |
|
465 | - $this->header = "Content-Type: multipart/mixed;" . $this->eol . "\tboundary=\"" . $boundary . "\"" . $this->eol . $this->eol; |
|
466 | - $this->body = "--" . $boundary . $this->eol . $this->body . $this->eol . $this->eol; |
|
463 | + $this->body = $this->header.$this->body; |
|
464 | + $boundary = '----=='.uniqid(rand(), TRUE); |
|
465 | + $this->header = "Content-Type: multipart/mixed;".$this->eol."\tboundary=\"".$boundary."\"".$this->eol.$this->eol; |
|
466 | + $this->body = "--".$boundary.$this->eol.$this->body.$this->eol.$this->eol; |
|
467 | 467 | $res = array(); |
468 | 468 | $res[] = $this->body; |
469 | - foreach($this->attachments as $filename => $attachment) |
|
469 | + foreach ($this->attachments as $filename => $attachment) |
|
470 | 470 | { |
471 | 471 | $type = $this->returnMIMEType($filename); |
472 | 472 | $file_handler = new FileHandler(); |
473 | 473 | $file_str = $file_handler->readFile($attachment); |
474 | 474 | $chunks = chunk_split(base64_encode($file_str)); |
475 | 475 | $tempBody = sprintf( |
476 | - "--" . $boundary . $this->eol . |
|
477 | - "Content-Type: %s;" . $this->eol . |
|
478 | - "\tname=\"%s\"" . $this->eol . |
|
479 | - "Content-Transfer-Encoding: base64" . $this->eol . |
|
480 | - "Content-Description: %s" . $this->eol . |
|
481 | - "Content-Disposition: attachment;" . $this->eol . |
|
482 | - "\tfilename=\"%s\"" . $this->eol . $this->eol . |
|
483 | - "%s" . $this->eol . $this->eol, $type, $filename, $filename, $filename, $chunks); |
|
476 | + "--".$boundary.$this->eol. |
|
477 | + "Content-Type: %s;".$this->eol. |
|
478 | + "\tname=\"%s\"".$this->eol. |
|
479 | + "Content-Transfer-Encoding: base64".$this->eol. |
|
480 | + "Content-Description: %s".$this->eol. |
|
481 | + "Content-Disposition: attachment;".$this->eol. |
|
482 | + "\tfilename=\"%s\"".$this->eol.$this->eol. |
|
483 | + "%s".$this->eol.$this->eol, $type, $filename, $filename, $filename, $chunks); |
|
484 | 484 | $res[] = $tempBody; |
485 | 485 | } |
486 | 486 | $this->body = implode("", $res); |
487 | - $this->body .= "--" . $boundary . "--"; |
|
487 | + $this->body .= "--".$boundary."--"; |
|
488 | 488 | } |
489 | 489 | } |
490 | 490 | else |
491 | 491 | { |
492 | - if(count($this->attachments) > 0) |
|
492 | + if (count($this->attachments) > 0) |
|
493 | 493 | { |
494 | - foreach($this->attachments as $filename => $attachment) |
|
494 | + foreach ($this->attachments as $filename => $attachment) |
|
495 | 495 | { |
496 | 496 | parent::AddAttachment($attachment); |
497 | 497 | } |
@@ -506,33 +506,33 @@ discard block |
||
506 | 506 | */ |
507 | 507 | function procCidAttachments() |
508 | 508 | { |
509 | - if(count($this->cidAttachments) > 0) |
|
509 | + if (count($this->cidAttachments) > 0) |
|
510 | 510 | { |
511 | - $this->body = $this->header . $this->body; |
|
512 | - $boundary = '----==' . uniqid(rand(), TRUE); |
|
513 | - $this->header = "Content-Type: multipart/relative;" . $this->eol . "\ttype=\"multipart/alternative\";" . $this->eol . "\tboundary=\"" . $boundary . "\"" . $this->eol . $this->eol; |
|
514 | - $this->body = "--" . $boundary . $this->eol . $this->body . $this->eol . $this->eol; |
|
511 | + $this->body = $this->header.$this->body; |
|
512 | + $boundary = '----=='.uniqid(rand(), TRUE); |
|
513 | + $this->header = "Content-Type: multipart/relative;".$this->eol."\ttype=\"multipart/alternative\";".$this->eol."\tboundary=\"".$boundary."\"".$this->eol.$this->eol; |
|
514 | + $this->body = "--".$boundary.$this->eol.$this->body.$this->eol.$this->eol; |
|
515 | 515 | $res = array(); |
516 | 516 | $res[] = $this->body; |
517 | - foreach($this->cidAttachments as $cid => $attachment) |
|
517 | + foreach ($this->cidAttachments as $cid => $attachment) |
|
518 | 518 | { |
519 | 519 | $filename = basename($attachment); |
520 | 520 | $type = $this->returnMIMEType(FileHandler::getRealPath($attachment)); |
521 | 521 | $file_str = FileHandler::readFile($attachment); |
522 | 522 | $chunks = chunk_split(base64_encode($file_str)); |
523 | 523 | $tempBody = sprintf( |
524 | - "--" . $boundary . $this->eol . |
|
525 | - "Content-Type: %s;" . $this->eol . |
|
526 | - "\tname=\"%s\"" . $this->eol . |
|
527 | - "Content-Transfer-Encoding: base64" . $this->eol . |
|
528 | - "Content-ID: <%s>" . $this->eol . |
|
529 | - "Content-Description: %s" . $this->eol . |
|
530 | - "Content-Location: %s" . $this->eol . $this->eol . |
|
531 | - "%s" . $this->eol . $this->eol, $type, $filename, $cid, $filename, $filename, $chunks); |
|
524 | + "--".$boundary.$this->eol. |
|
525 | + "Content-Type: %s;".$this->eol. |
|
526 | + "\tname=\"%s\"".$this->eol. |
|
527 | + "Content-Transfer-Encoding: base64".$this->eol. |
|
528 | + "Content-ID: <%s>".$this->eol. |
|
529 | + "Content-Description: %s".$this->eol. |
|
530 | + "Content-Location: %s".$this->eol.$this->eol. |
|
531 | + "%s".$this->eol.$this->eol, $type, $filename, $cid, $filename, $filename, $chunks); |
|
532 | 532 | $res[] = $tempBody; |
533 | 533 | } |
534 | 534 | $this->body = implode("", $res); |
535 | - $this->body .= "--" . $boundary . "--"; |
|
535 | + $this->body .= "--".$boundary."--"; |
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
@@ -543,37 +543,37 @@ discard block |
||
543 | 543 | */ |
544 | 544 | function send() |
545 | 545 | { |
546 | - if($this->Mailer == "mail") |
|
546 | + if ($this->Mailer == "mail") |
|
547 | 547 | { |
548 | - $boundary = '----==' . uniqid(rand(), TRUE); |
|
548 | + $boundary = '----=='.uniqid(rand(), TRUE); |
|
549 | 549 | $this->eol = $GLOBALS['_qmail_compatibility'] == "Y" ? "\n" : "\r\n"; |
550 | - $this->header = "Content-Type: multipart/alternative;" . $this->eol . "\tboundary=\"" . $boundary . "\"" . $this->eol . $this->eol; |
|
550 | + $this->header = "Content-Type: multipart/alternative;".$this->eol."\tboundary=\"".$boundary."\"".$this->eol.$this->eol; |
|
551 | 551 | $this->body = sprintf( |
552 | - "--%s" . $this->eol . |
|
553 | - "Content-Type: text/plain; charset=utf-8; format=flowed" . $this->eol . |
|
554 | - "Content-Transfer-Encoding: base64" . $this->eol . |
|
555 | - "Content-Disposition: inline" . $this->eol . $this->eol . |
|
556 | - "%s" . |
|
557 | - "--%s" . $this->eol . |
|
558 | - "Content-Type: text/html; charset=utf-8" . $this->eol . |
|
559 | - "Content-Transfer-Encoding: base64" . $this->eol . |
|
560 | - "Content-Disposition: inline" . $this->eol . $this->eol . |
|
561 | - "%s" . |
|
562 | - "--%s--" . |
|
552 | + "--%s".$this->eol. |
|
553 | + "Content-Type: text/plain; charset=utf-8; format=flowed".$this->eol. |
|
554 | + "Content-Transfer-Encoding: base64".$this->eol. |
|
555 | + "Content-Disposition: inline".$this->eol.$this->eol. |
|
556 | + "%s". |
|
557 | + "--%s".$this->eol. |
|
558 | + "Content-Type: text/html; charset=utf-8".$this->eol. |
|
559 | + "Content-Transfer-Encoding: base64".$this->eol. |
|
560 | + "Content-Disposition: inline".$this->eol.$this->eol. |
|
561 | + "%s". |
|
562 | + "--%s--". |
|
563 | 563 | "", $boundary, $this->getPlainContent(), $boundary, $this->getHTMLContent(), $boundary |
564 | 564 | ); |
565 | 565 | $this->procCidAttachments(); |
566 | 566 | $this->procAttachments(); |
567 | 567 | $headers = sprintf( |
568 | - "From: %s" . $this->eol . |
|
569 | - "%s" . |
|
570 | - "%s" . |
|
571 | - "%s" . |
|
572 | - "%s" . |
|
573 | - "MIME-Version: 1.0" . $this->eol . "", $this->getSender(), $this->messageId ? ("Message-ID: <" . $this->messageId . ">" . $this->eol) : "", $this->replyTo ? ("Reply-To: <" . $this->replyTo . ">" . $this->eol) : "", $this->bcc ? ("Bcc: " . $this->bcc . $this->eol) : "", $this->references ? ("References: <" . $this->references . ">" . $this->eol . "In-Reply-To: <" . $this->references . ">" . $this->eol) : "" |
|
568 | + "From: %s".$this->eol. |
|
569 | + "%s". |
|
570 | + "%s". |
|
571 | + "%s". |
|
572 | + "%s". |
|
573 | + "MIME-Version: 1.0".$this->eol."", $this->getSender(), $this->messageId ? ("Message-ID: <".$this->messageId.">".$this->eol) : "", $this->replyTo ? ("Reply-To: <".$this->replyTo.">".$this->eol) : "", $this->bcc ? ("Bcc: ".$this->bcc.$this->eol) : "", $this->references ? ("References: <".$this->references.">".$this->eol."In-Reply-To: <".$this->references.">".$this->eol) : "" |
|
574 | 574 | ); |
575 | 575 | $headers .= $this->header; |
576 | - if($this->additional_params) |
|
576 | + if ($this->additional_params) |
|
577 | 577 | { |
578 | 578 | return mail($this->getReceiptor(), $this->getTitle(), $this->body, $headers, $this->additional_params); |
579 | 579 | } |
@@ -594,14 +594,14 @@ discard block |
||
594 | 594 | */ |
595 | 595 | function checkMailMX($email_address) |
596 | 596 | { |
597 | - if(!Mail::isVaildMailAddress($email_address)) |
|
597 | + if (!Mail::isVaildMailAddress($email_address)) |
|
598 | 598 | { |
599 | 599 | return FALSE; |
600 | 600 | } |
601 | 601 | list($user, $host) = explode("@", $email_address); |
602 | - if(function_exists('checkdnsrr')) |
|
602 | + if (function_exists('checkdnsrr')) |
|
603 | 603 | { |
604 | - if(checkdnsrr($host, "MX") || checkdnsrr($host, "A")) |
|
604 | + if (checkdnsrr($host, "MX") || checkdnsrr($host, "A")) |
|
605 | 605 | { |
606 | 606 | return TRUE; |
607 | 607 | } |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | */ |
622 | 622 | function isVaildMailAddress($email_address) |
623 | 623 | { |
624 | - if(preg_match("/([a-z0-9\_\-\.]+)@([a-z0-9\_\-\.]+)/i", $email_address)) |
|
624 | + if (preg_match("/([a-z0-9\_\-\.]+)@([a-z0-9\_\-\.]+)/i", $email_address)) |
|
625 | 625 | { |
626 | 626 | return $email_address; |
627 | 627 | } |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | function returnMIMEType($filename) |
641 | 641 | { |
642 | 642 | preg_match("|\.([a-z0-9]{2,4})$|i", $filename, $fileSuffix); |
643 | - switch(strtolower($fileSuffix[1])) |
|
643 | + switch (strtolower($fileSuffix[1])) |
|
644 | 644 | { |
645 | 645 | case "js" : |
646 | 646 | return "application/x-javascript"; |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | case "gif" : |
655 | 655 | case "bmp" : |
656 | 656 | case "tiff" : |
657 | - return "image/" . strtolower($fileSuffix[1]); |
|
657 | + return "image/".strtolower($fileSuffix[1]); |
|
658 | 658 | case "css" : |
659 | 659 | return "text/css"; |
660 | 660 | case "xml" : |
@@ -708,11 +708,11 @@ discard block |
||
708 | 708 | case "swf" : |
709 | 709 | return "application/x-shockwave-flash"; |
710 | 710 | default : |
711 | - if(function_exists("mime_content_type")) |
|
711 | + if (function_exists("mime_content_type")) |
|
712 | 712 | { |
713 | 713 | $fileSuffix = mime_content_type($filename); |
714 | 714 | } |
715 | - return "unknown/" . trim($fileSuffix[0], "."); |
|
715 | + return "unknown/".trim($fileSuffix[0], "."); |
|
716 | 716 | } |
717 | 717 | } |
718 | 718 |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Initialization. It finds the target module based on module, mid, document_srl, and prepares to execute an action |
115 | - * @return boolean true: OK, false: redirected |
|
115 | + * @return string|boolean true: OK, false: redirected |
|
116 | 116 | * */ |
117 | 117 | function init() |
118 | 118 | { |
@@ -1128,6 +1128,10 @@ discard block |
||
1128 | 1128 | return $GLOBALS['_loaded_module'][$module][$type][$kind]; |
1129 | 1129 | } |
1130 | 1130 | |
1131 | + /** |
|
1132 | + * @param string $type |
|
1133 | + * @param string $kind |
|
1134 | + */ |
|
1131 | 1135 | function _getModuleFilePath($module, $type, $kind, &$classPath, &$highClassFile, &$classFile, &$instanceName) |
1132 | 1136 | { |
1133 | 1137 | $classPath = ModuleHandler::getModulePath($module); |
@@ -59,10 +59,10 @@ |
||
59 | 59 | $this->mid = $mid ? $mid : Context::get('mid'); |
60 | 60 | $this->document_srl = $document_srl ? (int) $document_srl : (int) Context::get('document_srl'); |
61 | 61 | $this->module_srl = $module_srl ? (int) $module_srl : (int) Context::get('module_srl'); |
62 | - if($entry = Context::get('entry')) |
|
63 | - { |
|
64 | - $this->entry = Context::convertEncodingStr($entry); |
|
65 | - } |
|
62 | + if($entry = Context::get('entry')) |
|
63 | + { |
|
64 | + $this->entry = Context::convertEncodingStr($entry); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | // Validate variables to prevent XSS |
68 | 68 | $isInvalid = NULL; |
@@ -115,7 +115,9 @@ discard block |
||
115 | 115 | $called_position = 'before_module_init'; |
116 | 116 | $oAddonController = getController('addon'); |
117 | 117 | $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? 'mobile' : 'pc'); |
118 | - if(file_exists($addon_file)) include($addon_file); |
|
118 | + if(file_exists($addon_file)) { |
|
119 | + include($addon_file); |
|
120 | + } |
|
119 | 121 | } |
120 | 122 | |
121 | 123 | public static function xeErrorLog($errnumber, $errormassage, $errorfile, $errorline, $errorcontext) |
@@ -257,8 +259,7 @@ discard block |
||
257 | 259 | if(!$module_info) |
258 | 260 | { |
259 | 261 | unset($this->document_srl); |
260 | - } |
|
261 | - else |
|
262 | + } else |
|
262 | 263 | { |
263 | 264 | // If it exists, compare mid based on the module information |
264 | 265 | // if mids are not matching, set it as the document's mid |
@@ -270,8 +271,7 @@ discard block |
||
270 | 271 | $this->mid = $module_info->mid; |
271 | 272 | header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl)); |
272 | 273 | return FALSE; |
273 | - } |
|
274 | - else |
|
274 | + } else |
|
275 | 275 | { |
276 | 276 | $this->mid = $module_info->mid; |
277 | 277 | Context::set('mid', $this->mid); |
@@ -322,15 +322,13 @@ discard block |
||
322 | 322 | $site_info = $oModuleModel->getSiteInfo($module_info->site_srl); |
323 | 323 | $redirect_url = getNotEncodedSiteUrl($site_info->domain, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry')); |
324 | 324 | // If it's called from a virtual site, though it's not a module of the virtual site |
325 | - } |
|
326 | - else |
|
325 | + } else |
|
327 | 326 | { |
328 | 327 | $db_info = Context::getDBInfo(); |
329 | 328 | if(!$db_info->default_url) |
330 | 329 | { |
331 | 330 | return Context::getLang('msg_default_url_is_not_defined'); |
332 | - } |
|
333 | - else |
|
331 | + } else |
|
334 | 332 | { |
335 | 333 | $redirect_url = getNotEncodedSiteUrl($db_info->default_url, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry')); |
336 | 334 | } |
@@ -355,8 +353,7 @@ discard block |
||
355 | 353 | { |
356 | 354 | $oLayoutAdminModel = getAdminModel('layout'); |
357 | 355 | $layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl); |
358 | - } |
|
359 | - else |
|
356 | + } else |
|
360 | 357 | { |
361 | 358 | $layoutSrl = $module_info->{$targetSrl}; |
362 | 359 | } |
@@ -483,8 +480,7 @@ discard block |
||
483 | 480 | if(!$allowedMethod) |
484 | 481 | { |
485 | 482 | $allowedMethodList[0] = 'POST'; |
486 | - } |
|
487 | - else |
|
483 | + } else |
|
488 | 484 | { |
489 | 485 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
490 | 486 | } |
@@ -542,8 +538,7 @@ discard block |
||
542 | 538 | Mobile::setMobile(FALSE); |
543 | 539 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
544 | 540 | } |
545 | - } |
|
546 | - else |
|
541 | + } else |
|
547 | 542 | { |
548 | 543 | // create a module instance |
549 | 544 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
@@ -596,8 +591,7 @@ discard block |
||
596 | 591 | $forward->type = $xml_info->action->{$this->act}->type; |
597 | 592 | $forward->ruleset = $xml_info->action->{$this->act}->ruleset; |
598 | 593 | $forward->act = $this->act; |
599 | - } |
|
600 | - else |
|
594 | + } else |
|
601 | 595 | { |
602 | 596 | $this->error = 'msg_invalid_request'; |
603 | 597 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -633,8 +627,7 @@ discard block |
||
633 | 627 | if(!$allowedMethod) |
634 | 628 | { |
635 | 629 | $allowedMethodList[0] = 'POST'; |
636 | - } |
|
637 | - else |
|
630 | + } else |
|
638 | 631 | { |
639 | 632 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
640 | 633 | } |
@@ -662,8 +655,7 @@ discard block |
||
662 | 655 | Mobile::setMobile(FALSE); |
663 | 656 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
664 | 657 | } |
665 | - } |
|
666 | - else |
|
658 | + } else |
|
667 | 659 | { |
668 | 660 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
669 | 661 | } |
@@ -693,8 +685,7 @@ discard block |
||
693 | 685 | $oModule->setLayoutPath("./modules/admin/tpl"); |
694 | 686 | $oModule->setLayoutFile("layout.html"); |
695 | 687 | } |
696 | - } |
|
697 | - else |
|
688 | + } else |
|
698 | 689 | { |
699 | 690 | $this->_setInputErrorToContext(); |
700 | 691 | |
@@ -718,8 +709,7 @@ discard block |
||
718 | 709 | $oMessageObject->setMessage($this->error); |
719 | 710 | $oMessageObject->dispMessage(); |
720 | 711 | return $oMessageObject; |
721 | - } |
|
722 | - else |
|
712 | + } else |
|
723 | 713 | { |
724 | 714 | if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
725 | 715 | { |
@@ -733,12 +723,10 @@ discard block |
||
733 | 723 | } |
734 | 724 | } |
735 | 725 | } |
736 | - } |
|
737 | - else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
|
726 | + } else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
|
738 | 727 | { |
739 | 728 | $this->act = $xml_info->default_index_act; |
740 | - } |
|
741 | - else |
|
729 | + } else |
|
742 | 730 | { |
743 | 731 | $this->error = 'msg_invalid_request'; |
744 | 732 | $oModule->setError(-1); |
@@ -836,7 +824,9 @@ discard block |
||
836 | 824 | $message = $oModule->getMessage(); |
837 | 825 | $messageType = $oModule->getMessageType(); |
838 | 826 | $redirectUrl = $oModule->getRedirectUrl(); |
839 | - if($messageType == 'error') debugPrint($message, 'ERROR'); |
|
827 | + if($messageType == 'error') { |
|
828 | + debugPrint($message, 'ERROR'); |
|
829 | + } |
|
840 | 830 | |
841 | 831 | if(!$procResult) |
842 | 832 | { |
@@ -846,8 +836,7 @@ discard block |
||
846 | 836 | $redirectUrl = Context::get('error_return_url'); |
847 | 837 | } |
848 | 838 | $this->_setInputValueToSession(); |
849 | - } |
|
850 | - else |
|
839 | + } else |
|
851 | 840 | { |
852 | 841 | |
853 | 842 | } |
@@ -995,8 +984,7 @@ discard block |
||
995 | 984 | $oModule->setTemplatePath($oMessageObject->getTemplatePath()); |
996 | 985 | $oModule->setTemplateFile($oMessageObject->getTemplateFile()); |
997 | 986 | // Otherwise, set message instance as the target module |
998 | - } |
|
999 | - else |
|
987 | + } else |
|
1000 | 988 | { |
1001 | 989 | $oModule = $oMessageObject; |
1002 | 990 | } |
@@ -1008,8 +996,7 @@ discard block |
||
1008 | 996 | if(Mobile::isFromMobilePhone()) |
1009 | 997 | { |
1010 | 998 | $layout_srl = $oModule->module_info->mlayout_srl; |
1011 | - } |
|
1012 | - else |
|
999 | + } else |
|
1013 | 1000 | { |
1014 | 1001 | $layout_srl = $oModule->module_info->layout_srl; |
1015 | 1002 | } |
@@ -1068,8 +1055,7 @@ discard block |
||
1068 | 1055 | $menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file); |
1069 | 1056 | $menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file); |
1070 | 1057 | $layout_info->menu->{$menu_id}->menu_srl = $homeMenuSrl; |
1071 | - } |
|
1072 | - else |
|
1058 | + } else |
|
1073 | 1059 | { |
1074 | 1060 | $menu->xml_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->xml_file); |
1075 | 1061 | $menu->php_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->php_file); |
@@ -1106,8 +1092,7 @@ discard block |
||
1106 | 1092 | if($kind == 'admin') |
1107 | 1093 | { |
1108 | 1094 | $oModule->setLayoutFile('popup_layout'); |
1109 | - } |
|
1110 | - else |
|
1095 | + } else |
|
1111 | 1096 | { |
1112 | 1097 | $oModule->setLayoutPath('common/tpl'); |
1113 | 1098 | $oModule->setLayoutFile('default_layout'); |
@@ -1241,13 +1226,11 @@ discard block |
||
1241 | 1226 | { |
1242 | 1227 | $instanceName = '%s'; |
1243 | 1228 | $classFile = '%s%s.%s.php'; |
1244 | - } |
|
1245 | - elseif($kind == 'admin' && array_search($type, $types) < 3) |
|
1229 | + } elseif($kind == 'admin' && array_search($type, $types) < 3) |
|
1246 | 1230 | { |
1247 | 1231 | $instanceName = '%sAdmin%s'; |
1248 | 1232 | $classFile = '%s%s.admin.%s.php'; |
1249 | - } |
|
1250 | - else |
|
1233 | + } else |
|
1251 | 1234 | { |
1252 | 1235 | $instanceName = '%s%s'; |
1253 | 1236 | $classFile = '%s%s.%s.php'; |
@@ -1310,7 +1293,9 @@ discard block |
||
1310 | 1293 | $slowlog->caller = $trigger_name . '.' . $called_position; |
1311 | 1294 | $slowlog->called = $module . '.' . $called_method; |
1312 | 1295 | $slowlog->called_extension = $module; |
1313 | - if($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog); |
|
1296 | + if($trigger_name != 'XE.writeSlowlog') { |
|
1297 | + writeSlowlog('trigger', $elapsed_time_trigger, $slowlog); |
|
1298 | + } |
|
1314 | 1299 | |
1315 | 1300 | if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) |
1316 | 1301 | { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | function ModuleHandler($module = '', $act = '', $mid = '', $document_srl = '', $module_srl = '') |
36 | 36 | { |
37 | 37 | // If XE has not installed yet, set module as install |
38 | - if(!Context::isInstalled()) |
|
38 | + if (!Context::isInstalled()) |
|
39 | 39 | { |
40 | 40 | $this->module = 'install'; |
41 | 41 | $this->act = Context::get('act'); |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | $oContext = Context::getInstance(); |
46 | - if($oContext->isSuccessInit == FALSE) |
|
46 | + if ($oContext->isSuccessInit == FALSE) |
|
47 | 47 | { |
48 | 48 | $logged_info = Context::get('logged_info'); |
49 | - if($logged_info->is_admin != "Y") |
|
49 | + if ($logged_info->is_admin != "Y") |
|
50 | 50 | { |
51 | 51 | $this->error = 'msg_invalid_request'; |
52 | 52 | return; |
@@ -59,26 +59,26 @@ discard block |
||
59 | 59 | $this->mid = $mid ? $mid : Context::get('mid'); |
60 | 60 | $this->document_srl = $document_srl ? (int) $document_srl : (int) Context::get('document_srl'); |
61 | 61 | $this->module_srl = $module_srl ? (int) $module_srl : (int) Context::get('module_srl'); |
62 | - if($entry = Context::get('entry')) |
|
62 | + if ($entry = Context::get('entry')) |
|
63 | 63 | { |
64 | 64 | $this->entry = Context::convertEncodingStr($entry); |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Validate variables to prevent XSS |
68 | 68 | $isInvalid = NULL; |
69 | - if($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module)) |
|
69 | + if ($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module)) |
|
70 | 70 | { |
71 | 71 | $isInvalid = TRUE; |
72 | 72 | } |
73 | - if($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid)) |
|
73 | + if ($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid)) |
|
74 | 74 | { |
75 | 75 | $isInvalid = TRUE; |
76 | 76 | } |
77 | - if($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act)) |
|
77 | + if ($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act)) |
|
78 | 78 | { |
79 | 79 | $isInvalid = TRUE; |
80 | 80 | } |
81 | - if($isInvalid) |
|
81 | + if ($isInvalid) |
|
82 | 82 | { |
83 | 83 | htmlHeader(); |
84 | 84 | echo Context::getLang("msg_invalid_request"); |
@@ -87,14 +87,14 @@ discard block |
||
87 | 87 | exit; |
88 | 88 | } |
89 | 89 | |
90 | - if(isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0)) |
|
90 | + if (isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0)) |
|
91 | 91 | { |
92 | - if(Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on') |
|
92 | + if (Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on') |
|
93 | 93 | { |
94 | - if(Context::get('_https_port')!=null) { |
|
95 | - header('location:https://' . $_SERVER['HTTP_HOST'] . ':' . Context::get('_https_port') . $_SERVER['REQUEST_URI']); |
|
94 | + if (Context::get('_https_port') != null) { |
|
95 | + header('location:https://'.$_SERVER['HTTP_HOST'].':'.Context::get('_https_port').$_SERVER['REQUEST_URI']); |
|
96 | 96 | } else { |
97 | - header('location:https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
|
97 | + header('location:https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
|
98 | 98 | } |
99 | 99 | return; |
100 | 100 | } |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | // call a trigger before moduleHandler init |
104 | 104 | ModuleHandler::triggerCall('moduleHandler.init', 'before', $this); |
105 | - if(__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0) |
|
105 | + if (__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0) |
|
106 | 106 | { |
107 | - if(__DEBUG_PROTECT__ === 0 || __DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR']) |
|
107 | + if (__DEBUG_PROTECT__ === 0 || __DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR']) |
|
108 | 108 | { |
109 | 109 | set_error_handler(array($this, 'xeErrorLog'), E_WARNING); |
110 | 110 | register_shutdown_function(array($this, 'shutdownHandler')); |
@@ -115,40 +115,40 @@ discard block |
||
115 | 115 | $called_position = 'before_module_init'; |
116 | 116 | $oAddonController = getController('addon'); |
117 | 117 | $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? 'mobile' : 'pc'); |
118 | - if(file_exists($addon_file)) include($addon_file); |
|
118 | + if (file_exists($addon_file)) include($addon_file); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | public static function xeErrorLog($errnumber, $errormassage, $errorfile, $errorline, $errorcontext) |
122 | 122 | { |
123 | - if(($errnumber & 3) == 0 || error_reporting() == 0) |
|
123 | + if (($errnumber & 3) == 0 || error_reporting() == 0) |
|
124 | 124 | { |
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | |
128 | 128 | set_error_handler(function() { }, ~0); |
129 | 129 | |
130 | - $debug_file = _XE_PATH_ . 'files/_debug_message.php'; |
|
131 | - if(!file_exists($debug_file)) |
|
130 | + $debug_file = _XE_PATH_.'files/_debug_message.php'; |
|
131 | + if (!file_exists($debug_file)) |
|
132 | 132 | { |
133 | 133 | $print[] = '<?php exit() ?>'; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $errorname = self::getErrorType($errnumber); |
137 | - $print[] = '['.date('Y-m-d H:i:s').'] ' . $errorname . ' : ' . $errormassage; |
|
137 | + $print[] = '['.date('Y-m-d H:i:s').'] '.$errorname.' : '.$errormassage; |
|
138 | 138 | $backtrace_args = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? \DEBUG_BACKTRACE_IGNORE_ARGS : 0; |
139 | 139 | $backtrace = debug_backtrace($backtrace_args); |
140 | - if(count($backtrace) > 1 && $backtrace[1]['function'] === 'xeErrorLog' && !$backtrace[1]['class']) |
|
140 | + if (count($backtrace) > 1 && $backtrace[1]['function'] === 'xeErrorLog' && !$backtrace[1]['class']) |
|
141 | 141 | { |
142 | 142 | array_shift($backtrace); |
143 | 143 | } |
144 | 144 | |
145 | - foreach($backtrace as $key => $value) |
|
145 | + foreach ($backtrace as $key => $value) |
|
146 | 146 | { |
147 | - $message = ' - ' . $value['file'] . ' : ' . $value['line']; |
|
147 | + $message = ' - '.$value['file'].' : '.$value['line']; |
|
148 | 148 | $print[] = $message; |
149 | 149 | } |
150 | 150 | $print[] = PHP_EOL; |
151 | - @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX); |
|
151 | + @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND | LOCK_EX); |
|
152 | 152 | restore_error_handler(); |
153 | 153 | |
154 | 154 | return true; |
@@ -164,21 +164,21 @@ discard block |
||
164 | 164 | |
165 | 165 | set_error_handler(function() { }, ~0); |
166 | 166 | |
167 | - $debug_file = _XE_PATH_ . 'files/_debug_message.php'; |
|
168 | - if(!file_exists($debug_file)) |
|
167 | + $debug_file = _XE_PATH_.'files/_debug_message.php'; |
|
168 | + if (!file_exists($debug_file)) |
|
169 | 169 | { |
170 | 170 | $print[] = '<?php exit() ?>'; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $errorname = self::getErrorType($errinfo['type']); |
174 | 174 | $print[] = '['.date('Y-m-d H:i:s').']'; |
175 | - $print[] = $errorname . ' : ' . $errinfo['message']; |
|
175 | + $print[] = $errorname.' : '.$errinfo['message']; |
|
176 | 176 | |
177 | - $message = ' - ' . $errinfo['file'] . ' : ' . $errinfo['line']; |
|
177 | + $message = ' - '.$errinfo['file'].' : '.$errinfo['line']; |
|
178 | 178 | $print[] = $message; |
179 | 179 | |
180 | 180 | $print[] = PHP_EOL; |
181 | - @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX); |
|
181 | + @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND | LOCK_EX); |
|
182 | 182 | set_error_handler(array($this, 'dummyHandler'), ~0); |
183 | 183 | |
184 | 184 | return true; |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | $defaultUrlInfo = parse_url($dbInfo->default_url); |
223 | 223 | $defaultHost = $defaultUrlInfo['host']; |
224 | 224 | |
225 | - foreach($urls as $url) |
|
225 | + foreach ($urls as $url) |
|
226 | 226 | { |
227 | - if(empty($url)) |
|
227 | + if (empty($url)) |
|
228 | 228 | { |
229 | 229 | continue; |
230 | 230 | } |
@@ -232,29 +232,29 @@ discard block |
||
232 | 232 | $urlInfo = parse_url($url); |
233 | 233 | $host = $urlInfo['host']; |
234 | 234 | |
235 | - if($host && ($host != $defaultHost && $host != $site_module_info->domain)) |
|
235 | + if ($host && ($host != $defaultHost && $host != $site_module_info->domain)) |
|
236 | 236 | { |
237 | 237 | throw new Exception('msg_default_url_is_null'); |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - if(!$this->document_srl && $this->mid && $this->entry) |
|
241 | + if (!$this->document_srl && $this->mid && $this->entry) |
|
242 | 242 | { |
243 | 243 | $oDocumentModel = getModel('document'); |
244 | 244 | $this->document_srl = $oDocumentModel->getDocumentSrlByAlias($this->mid, $this->entry); |
245 | - if($this->document_srl) |
|
245 | + if ($this->document_srl) |
|
246 | 246 | { |
247 | 247 | Context::set('document_srl', $this->document_srl); |
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | 251 | // Get module's information based on document_srl, if it's specified |
252 | - if($this->document_srl) |
|
252 | + if ($this->document_srl) |
|
253 | 253 | { |
254 | 254 | |
255 | 255 | $module_info = $oModuleModel->getModuleInfoByDocumentSrl($this->document_srl); |
256 | 256 | // If the document does not exist, remove document_srl |
257 | - if(!$module_info) |
|
257 | + if (!$module_info) |
|
258 | 258 | { |
259 | 259 | unset($this->document_srl); |
260 | 260 | } |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | { |
263 | 263 | // If it exists, compare mid based on the module information |
264 | 264 | // if mids are not matching, set it as the document's mid |
265 | - if(!$this->mid || ($this->mid != $module_info->mid)) |
|
265 | + if (!$this->mid || ($this->mid != $module_info->mid)) |
|
266 | 266 | { |
267 | 267 | |
268 | - if(Context::getRequestMethod() == 'GET') |
|
268 | + if (Context::getRequestMethod() == 'GET') |
|
269 | 269 | { |
270 | 270 | $this->mid = $module_info->mid; |
271 | - header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl)); |
|
271 | + header('location:'.getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl)); |
|
272 | 272 | return FALSE; |
273 | 273 | } |
274 | 274 | else |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | |
280 | 280 | } |
281 | 281 | // if requested module is different from one of the document, remove the module information retrieved based on the document number |
282 | - if($this->module && $module_info->module != $this->module) |
|
282 | + if ($this->module && $module_info->module != $this->module) |
|
283 | 283 | { |
284 | 284 | unset($module_info); |
285 | 285 | } |
@@ -288,36 +288,36 @@ discard block |
||
288 | 288 | } |
289 | 289 | |
290 | 290 | // If module_info is not set yet, and there exists mid information, get module information based on the mid |
291 | - if(!$module_info && $this->mid) |
|
291 | + if (!$module_info && $this->mid) |
|
292 | 292 | { |
293 | 293 | $module_info = $oModuleModel->getModuleInfoByMid($this->mid, $site_module_info->site_srl); |
294 | 294 | //if($this->module && $module_info->module != $this->module) unset($module_info); |
295 | 295 | } |
296 | 296 | |
297 | 297 | // redirect, if module_site_srl and site_srl are different |
298 | - if(!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0) |
|
298 | + if (!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0) |
|
299 | 299 | { |
300 | 300 | $site_info = $oModuleModel->getSiteInfo($site_module_info->module_site_srl); |
301 | - header("location:" . getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid)); |
|
301 | + header("location:".getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid)); |
|
302 | 302 | return FALSE; |
303 | 303 | } |
304 | 304 | |
305 | 305 | // If module_info is not set still, and $module does not exist, find the default module |
306 | - if(!$module_info && !$this->module && !$this->mid) |
|
306 | + if (!$module_info && !$this->module && !$this->mid) |
|
307 | 307 | { |
308 | 308 | $module_info = $site_module_info; |
309 | 309 | } |
310 | 310 | |
311 | - if(!$module_info && !$this->module && $site_module_info->module_site_srl) |
|
311 | + if (!$module_info && !$this->module && $site_module_info->module_site_srl) |
|
312 | 312 | { |
313 | 313 | $module_info = $site_module_info; |
314 | 314 | } |
315 | 315 | |
316 | 316 | // redirect, if site_srl of module_info is different from one of site's module_info |
317 | - if($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler()) |
|
317 | + if ($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler()) |
|
318 | 318 | { |
319 | 319 | // If the module is of virtual site |
320 | - if($module_info->site_srl) |
|
320 | + if ($module_info->site_srl) |
|
321 | 321 | { |
322 | 322 | $site_info = $oModuleModel->getSiteInfo($module_info->site_srl); |
323 | 323 | $redirect_url = getNotEncodedSiteUrl($site_info->domain, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry')); |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | else |
327 | 327 | { |
328 | 328 | $db_info = Context::getDBInfo(); |
329 | - if(!$db_info->default_url) |
|
329 | + if (!$db_info->default_url) |
|
330 | 330 | { |
331 | 331 | return Context::getLang('msg_default_url_is_not_defined'); |
332 | 332 | } |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | $redirect_url = getNotEncodedSiteUrl($db_info->default_url, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry')); |
336 | 336 | } |
337 | 337 | } |
338 | - header("location:" . $redirect_url); |
|
338 | + header("location:".$redirect_url); |
|
339 | 339 | return FALSE; |
340 | 340 | } |
341 | 341 | |
342 | 342 | // If module info was set, retrieve variables from the module information |
343 | - if($module_info) |
|
343 | + if ($module_info) |
|
344 | 344 | { |
345 | 345 | $this->module = $module_info->module; |
346 | 346 | $this->mid = $module_info->mid; |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $targetSrl = (Mobile::isFromMobilePhone()) ? 'mlayout_srl' : 'layout_srl'; |
352 | 352 | |
353 | 353 | // use the site default layout. |
354 | - if($module_info->{$targetSrl} == -1) |
|
354 | + if ($module_info->{$targetSrl} == -1) |
|
355 | 355 | { |
356 | 356 | $oLayoutAdminModel = getAdminModel('layout'); |
357 | 357 | $layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | } |
370 | 370 | |
371 | 371 | // Set module and mid into module_info |
372 | - if(!isset($this->module_info)) |
|
372 | + if (!isset($this->module_info)) |
|
373 | 373 | { |
374 | 374 | $this->module_info = new stdClass(); |
375 | 375 | } |
@@ -380,21 +380,21 @@ discard block |
||
380 | 380 | $this->module_info->site_srl = $site_module_info->site_srl; |
381 | 381 | |
382 | 382 | // Still no module? it's an error |
383 | - if(!$this->module) |
|
383 | + if (!$this->module) |
|
384 | 384 | { |
385 | 385 | $this->error = 'msg_module_is_not_exists'; |
386 | 386 | $this->httpStatusCode = '404'; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // If mid exists, set mid into context |
390 | - if($this->mid) |
|
390 | + if ($this->mid) |
|
391 | 391 | { |
392 | 392 | Context::set('mid', $this->mid, TRUE); |
393 | 393 | } |
394 | 394 | |
395 | 395 | // Call a trigger after moduleHandler init |
396 | 396 | $output = ModuleHandler::triggerCall('moduleHandler.init', 'after', $this->module_info); |
397 | - if(!$output->toBool()) |
|
397 | + if (!$output->toBool()) |
|
398 | 398 | { |
399 | 399 | $this->error = $output->getMessage(); |
400 | 400 | return TRUE; |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | $display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
417 | 417 | |
418 | 418 | // If error occurred while preparation, return a message instance |
419 | - if($this->error) |
|
419 | + if ($this->error) |
|
420 | 420 | { |
421 | 421 | $this->_setInputErrorToContext(); |
422 | 422 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
423 | 423 | $oMessageObject->setError(-1); |
424 | 424 | $oMessageObject->setMessage($this->error); |
425 | 425 | $oMessageObject->dispMessage(); |
426 | - if($this->httpStatusCode) |
|
426 | + if ($this->httpStatusCode) |
|
427 | 427 | { |
428 | 428 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
429 | 429 | } |
@@ -434,22 +434,22 @@ discard block |
||
434 | 434 | $xml_info = $oModuleModel->getModuleActionXml($this->module); |
435 | 435 | |
436 | 436 | // If not installed yet, modify act |
437 | - if($this->module == "install") |
|
437 | + if ($this->module == "install") |
|
438 | 438 | { |
439 | - if(!$this->act || !$xml_info->action->{$this->act}) |
|
439 | + if (!$this->act || !$xml_info->action->{$this->act}) |
|
440 | 440 | { |
441 | 441 | $this->act = $xml_info->default_index_act; |
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
445 | 445 | // if act exists, find type of the action, if not use default index act |
446 | - if(!$this->act) |
|
446 | + if (!$this->act) |
|
447 | 447 | { |
448 | 448 | $this->act = $xml_info->default_index_act; |
449 | 449 | } |
450 | 450 | |
451 | 451 | // still no act means error |
452 | - if(!$this->act) |
|
452 | + if (!$this->act) |
|
453 | 453 | { |
454 | 454 | $this->error = 'msg_module_is_not_exists'; |
455 | 455 | $this->httpStatusCode = '404'; |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | $oMessageObject->setError(-1); |
460 | 460 | $oMessageObject->setMessage($this->error); |
461 | 461 | $oMessageObject->dispMessage(); |
462 | - if($this->httpStatusCode) |
|
462 | + if ($this->httpStatusCode) |
|
463 | 463 | { |
464 | 464 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
465 | 465 | } |
@@ -470,17 +470,17 @@ discard block |
||
470 | 470 | $type = $xml_info->action->{$this->act}->type; |
471 | 471 | $ruleset = $xml_info->action->{$this->act}->ruleset; |
472 | 472 | $kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; |
473 | - if(!$kind && $this->module == 'admin') |
|
473 | + if (!$kind && $this->module == 'admin') |
|
474 | 474 | { |
475 | 475 | $kind = 'admin'; |
476 | 476 | } |
477 | 477 | |
478 | 478 | // check REQUEST_METHOD in controller |
479 | - if($type == 'controller') |
|
479 | + if ($type == 'controller') |
|
480 | 480 | { |
481 | 481 | $allowedMethod = $xml_info->action->{$this->act}->method; |
482 | 482 | |
483 | - if(!$allowedMethod) |
|
483 | + if (!$allowedMethod) |
|
484 | 484 | { |
485 | 485 | $allowedMethodList[0] = 'POST'; |
486 | 486 | } |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
490 | 490 | } |
491 | 491 | |
492 | - if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
492 | + if (!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
493 | 493 | { |
494 | 494 | $this->error = "msg_invalid_request"; |
495 | 495 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
503 | - if($this->module_info->use_mobile != "Y") |
|
503 | + if ($this->module_info->use_mobile != "Y") |
|
504 | 504 | { |
505 | 505 | Mobile::setMobile(FALSE); |
506 | 506 | } |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | |
510 | 510 | // check CSRF for non-GET actions |
511 | 511 | $use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false'; |
512 | - if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
512 | + if ($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
513 | 513 | { |
514 | 514 | $this->error = 'msg_invalid_request'; |
515 | 515 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | } |
521 | 521 | |
522 | 522 | // Admin ip |
523 | - if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y') |
|
523 | + if ($kind == 'admin' && $_SESSION['denied_admin'] == 'Y') |
|
524 | 524 | { |
525 | 525 | $this->_setInputErrorToContext(); |
526 | 526 | $this->error = "msg_not_permitted_act"; |
@@ -532,13 +532,13 @@ discard block |
||
532 | 532 | } |
533 | 533 | |
534 | 534 | // if(type == view, and case for using mobilephone) |
535 | - if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled()) |
|
535 | + if ($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled()) |
|
536 | 536 | { |
537 | 537 | $orig_type = "view"; |
538 | 538 | $type = "mobile"; |
539 | 539 | // create a module instance |
540 | 540 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
541 | - if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
541 | + if (!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
542 | 542 | { |
543 | 543 | $type = $orig_type; |
544 | 544 | Mobile::setMobile(FALSE); |
@@ -551,14 +551,14 @@ discard block |
||
551 | 551 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
552 | 552 | } |
553 | 553 | |
554 | - if(!is_object($oModule)) |
|
554 | + if (!is_object($oModule)) |
|
555 | 555 | { |
556 | 556 | $this->_setInputErrorToContext(); |
557 | 557 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
558 | 558 | $oMessageObject->setError(-1); |
559 | 559 | $oMessageObject->setMessage($this->error); |
560 | 560 | $oMessageObject->dispMessage(); |
561 | - if($this->httpStatusCode) |
|
561 | + if ($this->httpStatusCode) |
|
562 | 562 | { |
563 | 563 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
564 | 564 | } |
@@ -566,10 +566,10 @@ discard block |
||
566 | 566 | } |
567 | 567 | |
568 | 568 | // If there is no such action in the module object |
569 | - if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act)) |
|
569 | + if (!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act)) |
|
570 | 570 | { |
571 | 571 | |
572 | - if(!Context::isInstalled()) |
|
572 | + if (!Context::isInstalled()) |
|
573 | 573 | { |
574 | 574 | $this->_setInputErrorToContext(); |
575 | 575 | $this->error = 'msg_invalid_request'; |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | $oMessageObject->setError(-1); |
578 | 578 | $oMessageObject->setMessage($this->error); |
579 | 579 | $oMessageObject->dispMessage(); |
580 | - if($this->httpStatusCode) |
|
580 | + if ($this->httpStatusCode) |
|
581 | 581 | { |
582 | 582 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
583 | 583 | } |
@@ -586,12 +586,12 @@ discard block |
||
586 | 586 | |
587 | 587 | $forward = NULL; |
588 | 588 | // 1. Look for the module with action name |
589 | - if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches)) |
|
589 | + if (preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches)) |
|
590 | 590 | { |
591 | - $module = strtolower($matches[2] . $matches[3]); |
|
591 | + $module = strtolower($matches[2].$matches[3]); |
|
592 | 592 | $xml_info = $oModuleModel->getModuleActionXml($module); |
593 | 593 | |
594 | - if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false')) |
|
594 | + if ($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false')) |
|
595 | 595 | { |
596 | 596 | $forward = new stdClass(); |
597 | 597 | $forward->module = $module; |
@@ -611,12 +611,12 @@ discard block |
||
611 | 611 | } |
612 | 612 | } |
613 | 613 | |
614 | - if(!$forward) |
|
614 | + if (!$forward) |
|
615 | 615 | { |
616 | 616 | $forward = $oModuleModel->getActionForward($this->act); |
617 | 617 | } |
618 | 618 | |
619 | - if($forward->module && $forward->type && $forward->act && $forward->act == $this->act) |
|
619 | + if ($forward->module && $forward->type && $forward->act && $forward->act == $this->act) |
|
620 | 620 | { |
621 | 621 | $kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : ''; |
622 | 622 | $type = $forward->type; |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | |
629 | 629 | // check CSRF for non-GET actions |
630 | 630 | $use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false'; |
631 | - if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
631 | + if ($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
632 | 632 | { |
633 | 633 | $this->error = 'msg_invalid_request'; |
634 | 634 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -640,11 +640,11 @@ discard block |
||
640 | 640 | |
641 | 641 | // SECISSUE also check foward act method |
642 | 642 | // check REQUEST_METHOD in controller |
643 | - if($type == 'controller') |
|
643 | + if ($type == 'controller') |
|
644 | 644 | { |
645 | 645 | $allowedMethod = $xml_info->action->{$forward->act}->method; |
646 | 646 | |
647 | - if(!$allowedMethod) |
|
647 | + if (!$allowedMethod) |
|
648 | 648 | { |
649 | 649 | $allowedMethodList[0] = 'POST'; |
650 | 650 | } |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
654 | 654 | } |
655 | 655 | |
656 | - if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
656 | + if (!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
657 | 657 | { |
658 | 658 | $this->error = "msg_invalid_request"; |
659 | 659 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -664,13 +664,13 @@ discard block |
||
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | - if($type == "view" && Mobile::isFromMobilePhone()) |
|
667 | + if ($type == "view" && Mobile::isFromMobilePhone()) |
|
668 | 668 | { |
669 | 669 | $orig_type = "view"; |
670 | 670 | $type = "mobile"; |
671 | 671 | // create a module instance |
672 | 672 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
673 | - if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
673 | + if (!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
674 | 674 | { |
675 | 675 | $type = $orig_type; |
676 | 676 | Mobile::setMobile(FALSE); |
@@ -682,25 +682,25 @@ discard block |
||
682 | 682 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
683 | 683 | } |
684 | 684 | |
685 | - if(!is_object($oModule)) |
|
685 | + if (!is_object($oModule)) |
|
686 | 686 | { |
687 | 687 | $this->_setInputErrorToContext(); |
688 | 688 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
689 | 689 | $oMessageObject->setError(-1); |
690 | 690 | $oMessageObject->setMessage('msg_module_is_not_exists'); |
691 | 691 | $oMessageObject->dispMessage(); |
692 | - if($this->httpStatusCode) |
|
692 | + if ($this->httpStatusCode) |
|
693 | 693 | { |
694 | 694 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
695 | 695 | } |
696 | 696 | return $oMessageObject; |
697 | 697 | } |
698 | 698 | |
699 | - if($this->module == "admin" && $type == "view") |
|
699 | + if ($this->module == "admin" && $type == "view") |
|
700 | 700 | { |
701 | - if($logged_info->is_admin == 'Y') |
|
701 | + if ($logged_info->is_admin == 'Y') |
|
702 | 702 | { |
703 | - if($this->act != 'dispLayoutAdminLayoutModify') |
|
703 | + if ($this->act != 'dispLayoutAdminLayoutModify') |
|
704 | 704 | { |
705 | 705 | $oAdminView = getAdminView('admin'); |
706 | 706 | $oAdminView->makeGnbUrl($forward->module); |
@@ -720,10 +720,10 @@ discard block |
||
720 | 720 | return $oMessageObject; |
721 | 721 | } |
722 | 722 | } |
723 | - if($kind == 'admin') |
|
723 | + if ($kind == 'admin') |
|
724 | 724 | { |
725 | 725 | $grant = $oModuleModel->getGrant($this->module_info, $logged_info); |
726 | - if(!$grant->manager) |
|
726 | + if (!$grant->manager) |
|
727 | 727 | { |
728 | 728 | $this->_setInputErrorToContext(); |
729 | 729 | $this->error = 'msg_is_not_manager'; |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | } |
736 | 736 | else |
737 | 737 | { |
738 | - if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
|
738 | + if (!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
|
739 | 739 | { |
740 | 740 | $this->_setInputErrorToContext(); |
741 | 741 | $this->error = 'msg_is_not_administrator'; |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | } |
749 | 749 | } |
750 | 750 | } |
751 | - else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
|
751 | + else if ($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
|
752 | 752 | { |
753 | 753 | $this->act = $xml_info->default_index_act; |
754 | 754 | } |
@@ -762,16 +762,16 @@ discard block |
||
762 | 762 | } |
763 | 763 | |
764 | 764 | // ruleset check... |
765 | - if(!empty($ruleset)) |
|
765 | + if (!empty($ruleset)) |
|
766 | 766 | { |
767 | 767 | $rulesetModule = $forward->module ? $forward->module : $this->module; |
768 | 768 | $rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid); |
769 | - if(!empty($rulesetFile)) |
|
769 | + if (!empty($rulesetFile)) |
|
770 | 770 | { |
771 | - if($_SESSION['XE_VALIDATOR_ERROR_LANG']) |
|
771 | + if ($_SESSION['XE_VALIDATOR_ERROR_LANG']) |
|
772 | 772 | { |
773 | 773 | $errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG']; |
774 | - foreach($errorLang as $key => $val) |
|
774 | + foreach ($errorLang as $key => $val) |
|
775 | 775 | { |
776 | 776 | Context::setLang($key, $val); |
777 | 777 | } |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | |
781 | 781 | $Validator = new Validator($rulesetFile); |
782 | 782 | $result = $Validator->validate(); |
783 | - if(!$result) |
|
783 | + if (!$result) |
|
784 | 784 | { |
785 | 785 | $lastError = $Validator->getLastError(); |
786 | 786 | $returnUrl = Context::get('error_return_url'); |
@@ -812,26 +812,26 @@ discard block |
||
812 | 812 | 'dispLayoutPreviewWithModule' => 1 |
813 | 813 | ); |
814 | 814 | $db_use_mobile = Mobile::isMobileEnabled(); |
815 | - if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true) |
|
815 | + if ($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true) |
|
816 | 816 | { |
817 | 817 | global $lang; |
818 | 818 | $header = '<style>div.xe_mobile{opacity:0.7;margin:1em 0;padding:.5em;background:#333;border:1px solid #666;border-left:0;border-right:0}p.xe_mobile{text-align:center;margin:1em 0}a.xe_mobile{color:#ff0;font-weight:bold;font-size:24px}@media only screen and (min-width:500px){a.xe_mobile{font-size:15px}}</style>'; |
819 | - $footer = '<div class="xe_mobile"><p class="xe_mobile"><a class="xe_mobile" href="' . getUrl('m', '1') . '">' . $lang->msg_pc_to_mobile . '</a></p></div>'; |
|
819 | + $footer = '<div class="xe_mobile"><p class="xe_mobile"><a class="xe_mobile" href="'.getUrl('m', '1').'">'.$lang->msg_pc_to_mobile.'</a></p></div>'; |
|
820 | 820 | Context::addHtmlHeader($header); |
821 | 821 | Context::addHtmlFooter($footer); |
822 | 822 | } |
823 | 823 | |
824 | - if($type == "view" && $kind != 'admin') |
|
824 | + if ($type == "view" && $kind != 'admin') |
|
825 | 825 | { |
826 | 826 | $module_config = $oModuleModel->getModuleConfig('module'); |
827 | - if($module_config->htmlFooter) |
|
827 | + if ($module_config->htmlFooter) |
|
828 | 828 | { |
829 | 829 | Context::addHtmlFooter($module_config->htmlFooter); |
830 | 830 | } |
831 | - if($module_config->siteTitle) |
|
831 | + if ($module_config->siteTitle) |
|
832 | 832 | { |
833 | 833 | $siteTitle = Context::getBrowserTitle(); |
834 | - if(!$siteTitle) |
|
834 | + if (!$siteTitle) |
|
835 | 835 | { |
836 | 836 | Context::setBrowserTitle($module_config->siteTitle); |
837 | 837 | } |
@@ -844,18 +844,18 @@ discard block |
||
844 | 844 | $procResult = $oModule->proc(); |
845 | 845 | |
846 | 846 | $methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
847 | - if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()])) |
|
847 | + if (!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()])) |
|
848 | 848 | { |
849 | 849 | $error = $oModule->getError(); |
850 | 850 | $message = $oModule->getMessage(); |
851 | 851 | $messageType = $oModule->getMessageType(); |
852 | 852 | $redirectUrl = $oModule->getRedirectUrl(); |
853 | - if($messageType == 'error') debugPrint($message, 'ERROR'); |
|
853 | + if ($messageType == 'error') debugPrint($message, 'ERROR'); |
|
854 | 854 | |
855 | - if(!$procResult) |
|
855 | + if (!$procResult) |
|
856 | 856 | { |
857 | 857 | $this->error = $message; |
858 | - if(!$redirectUrl && Context::get('error_return_url')) |
|
858 | + if (!$redirectUrl && Context::get('error_return_url')) |
|
859 | 859 | { |
860 | 860 | $redirectUrl = Context::get('error_return_url'); |
861 | 861 | } |
@@ -868,13 +868,13 @@ discard block |
||
868 | 868 | |
869 | 869 | $_SESSION['XE_VALIDATOR_ERROR'] = $error; |
870 | 870 | $_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
871 | - if($message != 'success') |
|
871 | + if ($message != 'success') |
|
872 | 872 | { |
873 | 873 | $_SESSION['XE_VALIDATOR_MESSAGE'] = $message; |
874 | 874 | } |
875 | 875 | $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType; |
876 | 876 | |
877 | - if(Context::get('xeVirtualRequestMethod') != 'xml') |
|
877 | + if (Context::get('xeVirtualRequestMethod') != 'xml') |
|
878 | 878 | { |
879 | 879 | $_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl; |
880 | 880 | } |
@@ -890,27 +890,27 @@ discard block |
||
890 | 890 | * */ |
891 | 891 | function _setInputErrorToContext() |
892 | 892 | { |
893 | - if($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR')) |
|
893 | + if ($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR')) |
|
894 | 894 | { |
895 | 895 | Context::set('XE_VALIDATOR_ERROR', $_SESSION['XE_VALIDATOR_ERROR']); |
896 | 896 | } |
897 | - if($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE')) |
|
897 | + if ($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE')) |
|
898 | 898 | { |
899 | 899 | Context::set('XE_VALIDATOR_MESSAGE', $_SESSION['XE_VALIDATOR_MESSAGE']); |
900 | 900 | } |
901 | - if($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE')) |
|
901 | + if ($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE')) |
|
902 | 902 | { |
903 | 903 | Context::set('XE_VALIDATOR_MESSAGE_TYPE', $_SESSION['XE_VALIDATOR_MESSAGE_TYPE']); |
904 | 904 | } |
905 | - if($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL')) |
|
905 | + if ($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL')) |
|
906 | 906 | { |
907 | 907 | Context::set('XE_VALIDATOR_RETURN_URL', $_SESSION['XE_VALIDATOR_RETURN_URL']); |
908 | 908 | } |
909 | - if($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID')) |
|
909 | + if ($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID')) |
|
910 | 910 | { |
911 | 911 | Context::set('XE_VALIDATOR_ID', $_SESSION['XE_VALIDATOR_ID']); |
912 | 912 | } |
913 | - if(count($_SESSION['INPUT_ERROR'])) |
|
913 | + if (count($_SESSION['INPUT_ERROR'])) |
|
914 | 914 | { |
915 | 915 | Context::set('INPUT_ERROR', $_SESSION['INPUT_ERROR']); |
916 | 916 | } |
@@ -940,7 +940,7 @@ discard block |
||
940 | 940 | { |
941 | 941 | $requestVars = Context::getRequestVars(); |
942 | 942 | unset($requestVars->act, $requestVars->mid, $requestVars->vid, $requestVars->success_return_url, $requestVars->error_return_url); |
943 | - foreach($requestVars AS $key => $value) |
|
943 | + foreach ($requestVars AS $key => $value) |
|
944 | 944 | { |
945 | 945 | $_SESSION['INPUT_ERROR'][$key] = $value; |
946 | 946 | } |
@@ -954,41 +954,41 @@ discard block |
||
954 | 954 | function displayContent($oModule = NULL) |
955 | 955 | { |
956 | 956 | // If the module is not set or not an object, set error |
957 | - if(!$oModule || !is_object($oModule)) |
|
957 | + if (!$oModule || !is_object($oModule)) |
|
958 | 958 | { |
959 | 959 | $this->error = 'msg_module_is_not_exists'; |
960 | 960 | $this->httpStatusCode = '404'; |
961 | 961 | } |
962 | 962 | |
963 | 963 | // If connection to DB has a problem even though it's not install module, set error |
964 | - if($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE) |
|
964 | + if ($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE) |
|
965 | 965 | { |
966 | 966 | $this->error = 'msg_dbconnect_failed'; |
967 | 967 | } |
968 | 968 | |
969 | 969 | // Call trigger after moduleHandler proc |
970 | 970 | $output = ModuleHandler::triggerCall('moduleHandler.proc', 'after', $oModule); |
971 | - if(!$output->toBool()) |
|
971 | + if (!$output->toBool()) |
|
972 | 972 | { |
973 | 973 | $this->error = $output->getMessage(); |
974 | 974 | } |
975 | 975 | |
976 | 976 | // Use message view object, if HTML call |
977 | 977 | $methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
978 | - if(!isset($methodList[Context::getRequestMethod()])) |
|
978 | + if (!isset($methodList[Context::getRequestMethod()])) |
|
979 | 979 | { |
980 | 980 | |
981 | - if($_SESSION['XE_VALIDATOR_RETURN_URL']) |
|
981 | + if ($_SESSION['XE_VALIDATOR_RETURN_URL']) |
|
982 | 982 | { |
983 | 983 | $display_handler = new DisplayHandler(); |
984 | 984 | $display_handler->_debugOutput(); |
985 | 985 | |
986 | - header('location:' . $_SESSION['XE_VALIDATOR_RETURN_URL']); |
|
986 | + header('location:'.$_SESSION['XE_VALIDATOR_RETURN_URL']); |
|
987 | 987 | return; |
988 | 988 | } |
989 | 989 | |
990 | 990 | // If error occurred, handle it |
991 | - if($this->error) |
|
991 | + if ($this->error) |
|
992 | 992 | { |
993 | 993 | // display content with message module instance |
994 | 994 | $type = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
@@ -997,14 +997,14 @@ discard block |
||
997 | 997 | $oMessageObject->setMessage($this->error); |
998 | 998 | $oMessageObject->dispMessage(); |
999 | 999 | |
1000 | - if($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200') |
|
1000 | + if ($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200') |
|
1001 | 1001 | { |
1002 | 1002 | $this->_setHttpStatusMessage($oMessageObject->getHttpStatusCode()); |
1003 | 1003 | $oMessageObject->setTemplateFile('http_status_code'); |
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | // If module was called normally, change the templates of the module into ones of the message view module |
1007 | - if($oModule) |
|
1007 | + if ($oModule) |
|
1008 | 1008 | { |
1009 | 1009 | $oModule->setTemplatePath($oMessageObject->getTemplatePath()); |
1010 | 1010 | $oModule->setTemplateFile($oMessageObject->getTemplateFile()); |
@@ -1019,7 +1019,7 @@ discard block |
||
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | // Check if layout_srl exists for the module |
1022 | - if(Mobile::isFromMobilePhone()) |
|
1022 | + if (Mobile::isFromMobilePhone()) |
|
1023 | 1023 | { |
1024 | 1024 | $layout_srl = $oModule->module_info->mlayout_srl; |
1025 | 1025 | } |
@@ -1029,58 +1029,58 @@ discard block |
||
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | // if layout_srl is rollback by module, set default layout |
1032 | - if($layout_srl == -1) |
|
1032 | + if ($layout_srl == -1) |
|
1033 | 1033 | { |
1034 | 1034 | $viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P'; |
1035 | 1035 | $oLayoutAdminModel = getAdminModel('layout'); |
1036 | 1036 | $layout_srl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $oModule->module_info->site_srl); |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - if($layout_srl && !$oModule->getLayoutFile()) |
|
1039 | + if ($layout_srl && !$oModule->getLayoutFile()) |
|
1040 | 1040 | { |
1041 | 1041 | |
1042 | 1042 | // If layout_srl exists, get information of the layout, and set the location of layout_path/ layout_file |
1043 | 1043 | $oLayoutModel = getModel('layout'); |
1044 | 1044 | $layout_info = $oLayoutModel->getLayout($layout_srl); |
1045 | - if($layout_info) |
|
1045 | + if ($layout_info) |
|
1046 | 1046 | { |
1047 | 1047 | |
1048 | 1048 | // Input extra_vars into $layout_info |
1049 | - if($layout_info->extra_var_count) |
|
1049 | + if ($layout_info->extra_var_count) |
|
1050 | 1050 | { |
1051 | 1051 | |
1052 | - foreach($layout_info->extra_var as $var_id => $val) |
|
1052 | + foreach ($layout_info->extra_var as $var_id => $val) |
|
1053 | 1053 | { |
1054 | - if($val->type == 'image') |
|
1054 | + if ($val->type == 'image') |
|
1055 | 1055 | { |
1056 | - if(strncmp('./files/attach/images/', $val->value, 22) === 0) |
|
1056 | + if (strncmp('./files/attach/images/', $val->value, 22) === 0) |
|
1057 | 1057 | { |
1058 | - $val->value = Context::getRequestUri() . substr($val->value, 2); |
|
1058 | + $val->value = Context::getRequestUri().substr($val->value, 2); |
|
1059 | 1059 | } |
1060 | 1060 | } |
1061 | 1061 | $layout_info->{$var_id} = $val->value; |
1062 | 1062 | } |
1063 | 1063 | } |
1064 | 1064 | // Set menus into context |
1065 | - if($layout_info->menu_count) |
|
1065 | + if ($layout_info->menu_count) |
|
1066 | 1066 | { |
1067 | - foreach($layout_info->menu as $menu_id => $menu) |
|
1067 | + foreach ($layout_info->menu as $menu_id => $menu) |
|
1068 | 1068 | { |
1069 | 1069 | // set default menu set(included home menu) |
1070 | - if(!$menu->menu_srl || $menu->menu_srl == -1) |
|
1070 | + if (!$menu->menu_srl || $menu->menu_srl == -1) |
|
1071 | 1071 | { |
1072 | 1072 | $oMenuAdminController = getAdminController('menu'); |
1073 | 1073 | $homeMenuCacheFile = $oMenuAdminController->getHomeMenuCacheFile(); |
1074 | 1074 | |
1075 | - if(FileHandler::exists($homeMenuCacheFile)) |
|
1075 | + if (FileHandler::exists($homeMenuCacheFile)) |
|
1076 | 1076 | { |
1077 | 1077 | include($homeMenuCacheFile); |
1078 | 1078 | } |
1079 | 1079 | |
1080 | - if(!$menu->menu_srl) |
|
1080 | + if (!$menu->menu_srl) |
|
1081 | 1081 | { |
1082 | - $menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file); |
|
1083 | - $menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file); |
|
1082 | + $menu->xml_file = str_replace('.xml.php', $homeMenuSrl.'.xml.php', $menu->xml_file); |
|
1083 | + $menu->php_file = str_replace('.php', $homeMenuSrl.'.php', $menu->php_file); |
|
1084 | 1084 | $layout_info->menu->{$menu_id}->menu_srl = $homeMenuSrl; |
1085 | 1085 | } |
1086 | 1086 | else |
@@ -1091,7 +1091,7 @@ discard block |
||
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | $php_file = FileHandler::exists($menu->php_file); |
1094 | - if($php_file) |
|
1094 | + if ($php_file) |
|
1095 | 1095 | { |
1096 | 1096 | include($php_file); |
1097 | 1097 | } |
@@ -1107,17 +1107,17 @@ discard block |
||
1107 | 1107 | |
1108 | 1108 | // If layout was modified, use the modified version |
1109 | 1109 | $edited_layout = $oLayoutModel->getUserLayoutHtml($layout_info->layout_srl); |
1110 | - if(file_exists($edited_layout)) |
|
1110 | + if (file_exists($edited_layout)) |
|
1111 | 1111 | { |
1112 | 1112 | $oModule->setEditedLayoutFile($edited_layout); |
1113 | 1113 | } |
1114 | 1114 | } |
1115 | 1115 | } |
1116 | 1116 | $isLayoutDrop = Context::get('isLayoutDrop'); |
1117 | - if($isLayoutDrop) |
|
1117 | + if ($isLayoutDrop) |
|
1118 | 1118 | { |
1119 | 1119 | $kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; |
1120 | - if($kind == 'admin') |
|
1120 | + if ($kind == 'admin') |
|
1121 | 1121 | { |
1122 | 1122 | $oModule->setLayoutFile('popup_layout'); |
1123 | 1123 | } |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | function &getModuleInstance($module, $type = 'view', $kind = '') |
1156 | 1156 | { |
1157 | 1157 | |
1158 | - if(__DEBUG__ == 3) |
|
1158 | + if (__DEBUG__ == 3) |
|
1159 | 1159 | { |
1160 | 1160 | $start_time = getMicroTime(); |
1161 | 1161 | } |
@@ -1165,51 +1165,51 @@ discard block |
||
1165 | 1165 | $type = strtolower($type); |
1166 | 1166 | |
1167 | 1167 | $kinds = array('svc' => 1, 'admin' => 1); |
1168 | - if(!isset($kinds[$kind])) |
|
1168 | + if (!isset($kinds[$kind])) |
|
1169 | 1169 | { |
1170 | 1170 | $kind = 'svc'; |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - $key = $module . '.' . ($kind != 'admin' ? '' : 'admin') . '.' . $type; |
|
1173 | + $key = $module.'.'.($kind != 'admin' ? '' : 'admin').'.'.$type; |
|
1174 | 1174 | |
1175 | - if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__'])) |
|
1175 | + if (is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__'])) |
|
1176 | 1176 | { |
1177 | 1177 | $module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key]; |
1178 | 1178 | } |
1179 | 1179 | |
1180 | 1180 | // if there is no instance of the module in global variable, create a new one |
1181 | - if(!isset($GLOBALS['_loaded_module'][$module][$type][$kind])) |
|
1181 | + if (!isset($GLOBALS['_loaded_module'][$module][$type][$kind])) |
|
1182 | 1182 | { |
1183 | 1183 | ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name); |
1184 | 1184 | |
1185 | - if($extend_module && (!is_readable($high_class_file) || !is_readable($class_file))) |
|
1185 | + if ($extend_module && (!is_readable($high_class_file) || !is_readable($class_file))) |
|
1186 | 1186 | { |
1187 | 1187 | $module = $parent_module; |
1188 | 1188 | ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name); |
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | // Check if the base class and instance class exist |
1192 | - if(!class_exists($module, true)) |
|
1192 | + if (!class_exists($module, true)) |
|
1193 | 1193 | { |
1194 | 1194 | return NULL; |
1195 | 1195 | } |
1196 | - if(!class_exists($instance_name, true)) |
|
1196 | + if (!class_exists($instance_name, true)) |
|
1197 | 1197 | { |
1198 | 1198 | return NULL; |
1199 | 1199 | } |
1200 | 1200 | |
1201 | 1201 | // Create an instance |
1202 | 1202 | $oModule = new $instance_name(); |
1203 | - if(!is_object($oModule)) |
|
1203 | + if (!is_object($oModule)) |
|
1204 | 1204 | { |
1205 | 1205 | return NULL; |
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | // Load language files for the class |
1209 | - Context::loadLang($class_path . 'lang'); |
|
1210 | - if($extend_module) |
|
1209 | + Context::loadLang($class_path.'lang'); |
|
1210 | + if ($extend_module) |
|
1211 | 1211 | { |
1212 | - Context::loadLang(ModuleHandler::getModulePath($parent_module) . 'lang'); |
|
1212 | + Context::loadLang(ModuleHandler::getModulePath($parent_module).'lang'); |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | // Set variables to the instance |
@@ -1217,10 +1217,10 @@ discard block |
||
1217 | 1217 | $oModule->setModulePath($class_path); |
1218 | 1218 | |
1219 | 1219 | // If the module has a constructor, run it. |
1220 | - if(!isset($GLOBALS['_called_constructor'][$instance_name])) |
|
1220 | + if (!isset($GLOBALS['_called_constructor'][$instance_name])) |
|
1221 | 1221 | { |
1222 | 1222 | $GLOBALS['_called_constructor'][$instance_name] = TRUE; |
1223 | - if(@method_exists($oModule, $instance_name)) |
|
1223 | + if (@method_exists($oModule, $instance_name)) |
|
1224 | 1224 | { |
1225 | 1225 | $oModule->{$instance_name}(); |
1226 | 1226 | } |
@@ -1230,7 +1230,7 @@ discard block |
||
1230 | 1230 | $GLOBALS['_loaded_module'][$module][$type][$kind] = $oModule; |
1231 | 1231 | } |
1232 | 1232 | |
1233 | - if(__DEBUG__ == 3) |
|
1233 | + if (__DEBUG__ == 3) |
|
1234 | 1234 | { |
1235 | 1235 | $GLOBALS['__elapsed_class_load__'] += getMicroTime() - $start_time; |
1236 | 1236 | } |
@@ -1246,17 +1246,17 @@ discard block |
||
1246 | 1246 | $highClassFile = sprintf('%s%s%s.class.php', _XE_PATH_, $classPath, $module); |
1247 | 1247 | $highClassFile = FileHandler::getRealPath($highClassFile); |
1248 | 1248 | |
1249 | - $types = array('view','controller','model','api','wap','mobile','class'); |
|
1250 | - if(!in_array($type, $types)) |
|
1249 | + $types = array('view', 'controller', 'model', 'api', 'wap', 'mobile', 'class'); |
|
1250 | + if (!in_array($type, $types)) |
|
1251 | 1251 | { |
1252 | 1252 | $type = $types[0]; |
1253 | 1253 | } |
1254 | - if($type == 'class') |
|
1254 | + if ($type == 'class') |
|
1255 | 1255 | { |
1256 | 1256 | $instanceName = '%s'; |
1257 | 1257 | $classFile = '%s%s.%s.php'; |
1258 | 1258 | } |
1259 | - elseif($kind == 'admin' && array_search($type, $types) < 3) |
|
1259 | + elseif ($kind == 'admin' && array_search($type, $types) < 3) |
|
1260 | 1260 | { |
1261 | 1261 | $instanceName = '%sAdmin%s'; |
1262 | 1262 | $classFile = '%s%s.admin.%s.php'; |
@@ -1281,26 +1281,26 @@ discard block |
||
1281 | 1281 | function triggerCall($trigger_name, $called_position, &$obj) |
1282 | 1282 | { |
1283 | 1283 | // skip if not installed |
1284 | - if(!Context::isInstalled()) |
|
1284 | + if (!Context::isInstalled()) |
|
1285 | 1285 | { |
1286 | 1286 | return new BaseObject(); |
1287 | 1287 | } |
1288 | 1288 | |
1289 | 1289 | $oModuleModel = getModel('module'); |
1290 | 1290 | $triggers = $oModuleModel->getTriggers($trigger_name, $called_position); |
1291 | - if(!$triggers || count($triggers) < 1) |
|
1291 | + if (!$triggers || count($triggers) < 1) |
|
1292 | 1292 | { |
1293 | 1293 | return new BaseObject(); |
1294 | 1294 | } |
1295 | 1295 | |
1296 | 1296 | //store before trigger call time |
1297 | 1297 | $before_trigger_time = NULL; |
1298 | - if(__LOG_SLOW_TRIGGER__> 0) |
|
1298 | + if (__LOG_SLOW_TRIGGER__ > 0) |
|
1299 | 1299 | { |
1300 | 1300 | $before_trigger_time = microtime(true); |
1301 | 1301 | } |
1302 | 1302 | |
1303 | - foreach($triggers as $item) |
|
1303 | + foreach ($triggers as $item) |
|
1304 | 1304 | { |
1305 | 1305 | $module = $item->module; |
1306 | 1306 | $type = $item->type; |
@@ -1308,7 +1308,7 @@ discard block |
||
1308 | 1308 | |
1309 | 1309 | // todo why don't we call a normal class object ? |
1310 | 1310 | $oModule = getModule($module, $type); |
1311 | - if(!$oModule || !method_exists($oModule, $called_method)) |
|
1311 | + if (!$oModule || !method_exists($oModule, $called_method)) |
|
1312 | 1312 | { |
1313 | 1313 | continue; |
1314 | 1314 | } |
@@ -1321,12 +1321,12 @@ discard block |
||
1321 | 1321 | $elapsed_time_trigger = $after_each_trigger_time - $before_each_trigger_time; |
1322 | 1322 | |
1323 | 1323 | $slowlog = new stdClass; |
1324 | - $slowlog->caller = $trigger_name . '.' . $called_position; |
|
1325 | - $slowlog->called = $module . '.' . $called_method; |
|
1324 | + $slowlog->caller = $trigger_name.'.'.$called_position; |
|
1325 | + $slowlog->called = $module.'.'.$called_method; |
|
1326 | 1326 | $slowlog->called_extension = $module; |
1327 | - if($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog); |
|
1327 | + if ($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog); |
|
1328 | 1328 | |
1329 | - if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) |
|
1329 | + if (is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) |
|
1330 | 1330 | { |
1331 | 1331 | return $output; |
1332 | 1332 | } |
@@ -1411,9 +1411,9 @@ discard block |
||
1411 | 1411 | '511' => 'Network Authentication Required', |
1412 | 1412 | ); |
1413 | 1413 | $statusMessage = $statusMessageList[$code]; |
1414 | - if(!$statusMessage) |
|
1414 | + if (!$statusMessage) |
|
1415 | 1415 | { |
1416 | - $statusMessage = 'HTTP ' . $code; |
|
1416 | + $statusMessage = 'HTTP '.$code; |
|
1417 | 1417 | } |
1418 | 1418 | |
1419 | 1419 | Context::set('http_status_code', $code); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | /** |
143 | 143 | * sett to set module information |
144 | - * @param object $module_info object containing module information |
|
144 | + * @param stdClass $module_info object containing module information |
|
145 | 145 | * @param object $xml_info object containing module description |
146 | 146 | * @return void |
147 | 147 | * */ |
@@ -247,6 +247,7 @@ discard block |
||
247 | 247 | /** |
248 | 248 | * set the file name of the template file |
249 | 249 | * @param string name of file |
250 | + * @param string $filename |
|
250 | 251 | * @return void |
251 | 252 | * */ |
252 | 253 | function setTemplateFile($filename) |
@@ -270,6 +271,7 @@ discard block |
||
270 | 271 | /** |
271 | 272 | * set the directory path of the template directory |
272 | 273 | * @param string path of template directory. |
274 | + * @param string $path |
|
273 | 275 | * @return void |
274 | 276 | * */ |
275 | 277 | function setTemplatePath($path) |
@@ -325,6 +327,7 @@ discard block |
||
325 | 327 | /** |
326 | 328 | * set the file name of the layout file |
327 | 329 | * @param string name of file |
330 | + * @param string $filename |
|
328 | 331 | * @return void |
329 | 332 | * */ |
330 | 333 | function setLayoutFile($filename) |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * */ |
45 | 45 | function setModulePath($path) |
46 | 46 | { |
47 | - if(substr_compare($path, '/', -1) !== 0) |
|
47 | + if (substr_compare($path, '/', -1) !== 0) |
|
48 | 48 | { |
49 | - $path.='/'; |
|
49 | + $path .= '/'; |
|
50 | 50 | } |
51 | 51 | $this->module_path = $path; |
52 | 52 | } |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | function setRedirectUrl($url = './', $output = NULL) |
61 | 61 | { |
62 | 62 | $ajaxRequestMethod = array_flip($this->ajaxRequestMethod); |
63 | - if(!isset($ajaxRequestMethod[Context::getRequestMethod()])) |
|
63 | + if (!isset($ajaxRequestMethod[Context::getRequestMethod()])) |
|
64 | 64 | { |
65 | 65 | $this->add('redirect_url', $url); |
66 | 66 | } |
67 | 67 | |
68 | - if($output !== NULL && is_object($output)) |
|
68 | + if ($output !== NULL && is_object($output)) |
|
69 | 69 | { |
70 | 70 | return $output; |
71 | 71 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | { |
111 | 111 | $type = $this->get('message_type'); |
112 | 112 | $typeList = array('error' => 1, 'info' => 1, 'update' => 1); |
113 | - if(!isset($typeList[$type])) |
|
113 | + if (!isset($typeList[$type])) |
|
114 | 114 | { |
115 | 115 | $type = $this->getError() ? 'error' : 'info'; |
116 | 116 | } |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | $oModuleModel = getModel('module'); |
162 | 162 | // permission settings. access, manager(== is_admin) are fixed and privilege name in XE |
163 | 163 | $module_srl = Context::get('module_srl'); |
164 | - if(!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/', $module_srl)) |
|
164 | + if (!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/', $module_srl)) |
|
165 | 165 | { |
166 | 166 | $request_module = $oModuleModel->getModuleInfoByModuleSrl($module_srl); |
167 | - if($request_module->module_srl == $module_srl) |
|
167 | + if ($request_module->module_srl == $module_srl) |
|
168 | 168 | { |
169 | 169 | $grant = $oModuleModel->getGrant($request_module, $logged_info); |
170 | 170 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | { |
174 | 174 | $grant = $oModuleModel->getGrant($module_info, $logged_info, $xml_info); |
175 | 175 | // have at least access grant |
176 | - if(substr_count($this->act, 'Member') || substr_count($this->act, 'Communication')) |
|
176 | + if (substr_count($this->act, 'Member') || substr_count($this->act, 'Communication')) |
|
177 | 177 | { |
178 | 178 | $grant->access = 1; |
179 | 179 | } |
@@ -181,24 +181,24 @@ discard block |
||
181 | 181 | // display no permission if the current module doesn't have an access privilege |
182 | 182 | //if(!$grant->access) return $this->stop("msg_not_permitted"); |
183 | 183 | // checks permission and action if you don't have an admin privilege |
184 | - if(!$grant->manager) |
|
184 | + if (!$grant->manager) |
|
185 | 185 | { |
186 | 186 | // get permission types(guest, member, manager, root) of the currently requested action |
187 | 187 | $permission_target = $xml_info->permission->{$this->act}; |
188 | 188 | // check manager if a permission in module.xml otherwise action if no permission |
189 | - if(!$permission_target && substr_count($this->act, 'Admin')) |
|
189 | + if (!$permission_target && substr_count($this->act, 'Admin')) |
|
190 | 190 | { |
191 | 191 | $permission_target = 'manager'; |
192 | 192 | } |
193 | 193 | // Check permissions |
194 | - switch($permission_target) |
|
194 | + switch ($permission_target) |
|
195 | 195 | { |
196 | 196 | case 'root' : |
197 | 197 | case 'manager' : |
198 | 198 | $this->stop('msg_is_not_administrator'); |
199 | 199 | return; |
200 | 200 | case 'member' : |
201 | - if(!$is_logged) |
|
201 | + if (!$is_logged) |
|
202 | 202 | { |
203 | 203 | $this->stop('msg_not_permitted_act'); |
204 | 204 | return; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | $this->module_config = $oModuleModel->getModuleConfig($this->module, $module_info->site_srl); |
215 | 215 | |
216 | - if(method_exists($this, 'init')) |
|
216 | + if (method_exists($this, 'init')) |
|
217 | 217 | { |
218 | 218 | $this->init(); |
219 | 219 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * */ |
252 | 252 | function setTemplateFile($filename) |
253 | 253 | { |
254 | - if(isset($filename) && substr_compare($filename, '.html', -5) !== 0) |
|
254 | + if (isset($filename) && substr_compare($filename, '.html', -5) !== 0) |
|
255 | 255 | { |
256 | 256 | $filename .= '.html'; |
257 | 257 | } |
@@ -274,14 +274,14 @@ discard block |
||
274 | 274 | * */ |
275 | 275 | function setTemplatePath($path) |
276 | 276 | { |
277 | - if(!$path) return; |
|
277 | + if (!$path) return; |
|
278 | 278 | |
279 | - if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0)) |
|
279 | + if ((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0)) |
|
280 | 280 | { |
281 | - $path = './' . $path; |
|
281 | + $path = './'.$path; |
|
282 | 282 | } |
283 | 283 | |
284 | - if(substr_compare($path, '/', -1) !== 0) |
|
284 | + if (substr_compare($path, '/', -1) !== 0) |
|
285 | 285 | { |
286 | 286 | $path .= '/'; |
287 | 287 | } |
@@ -304,9 +304,9 @@ discard block |
||
304 | 304 | * */ |
305 | 305 | function setEditedLayoutFile($filename) |
306 | 306 | { |
307 | - if(!$filename) return; |
|
307 | + if (!$filename) return; |
|
308 | 308 | |
309 | - if(substr_compare($filename, '.html', -5) !== 0) |
|
309 | + if (substr_compare($filename, '.html', -5) !== 0) |
|
310 | 310 | { |
311 | 311 | $filename .= '.html'; |
312 | 312 | } |
@@ -329,9 +329,9 @@ discard block |
||
329 | 329 | * */ |
330 | 330 | function setLayoutFile($filename) |
331 | 331 | { |
332 | - if(!$filename) return; |
|
332 | + if (!$filename) return; |
|
333 | 333 | |
334 | - if(substr_compare($filename, '.html', -5) !== 0) |
|
334 | + if (substr_compare($filename, '.html', -5) !== 0) |
|
335 | 335 | { |
336 | 336 | $filename .= '.html'; |
337 | 337 | } |
@@ -353,13 +353,13 @@ discard block |
||
353 | 353 | * */ |
354 | 354 | function setLayoutPath($path) |
355 | 355 | { |
356 | - if(!$path) return; |
|
356 | + if (!$path) return; |
|
357 | 357 | |
358 | - if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0)) |
|
358 | + if ((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0)) |
|
359 | 359 | { |
360 | - $path = './' . $path; |
|
360 | + $path = './'.$path; |
|
361 | 361 | } |
362 | - if(substr_compare($path, '/', -1) !== 0) |
|
362 | + if (substr_compare($path, '/', -1) !== 0) |
|
363 | 363 | { |
364 | 364 | $path .= '/'; |
365 | 365 | } |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | function proc() |
383 | 383 | { |
384 | 384 | // pass if stop_proc is true |
385 | - if($this->stop_proc) |
|
385 | + if ($this->stop_proc) |
|
386 | 386 | { |
387 | 387 | debugPrint($this->message, 'ERROR'); |
388 | 388 | return FALSE; |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | |
391 | 391 | // trigger call |
392 | 392 | $triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'before', $this); |
393 | - if(!$triggerOutput->toBool()) |
|
393 | + if (!$triggerOutput->toBool()) |
|
394 | 394 | { |
395 | 395 | $this->setError($triggerOutput->getError()); |
396 | 396 | $this->setMessage($triggerOutput->getMessage()); |
@@ -401,12 +401,12 @@ discard block |
||
401 | 401 | $called_position = 'before_module_proc'; |
402 | 402 | $oAddonController = getController('addon'); |
403 | 403 | $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc"); |
404 | - if(FileHandler::exists($addon_file)) include($addon_file); |
|
404 | + if (FileHandler::exists($addon_file)) include($addon_file); |
|
405 | 405 | |
406 | - if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act)) |
|
406 | + if (isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act)) |
|
407 | 407 | { |
408 | 408 | // Check permissions |
409 | - if($this->module_srl && !$this->grant->access) |
|
409 | + if ($this->module_srl && !$this->grant->access) |
|
410 | 410 | { |
411 | 411 | $this->stop("msg_not_permitted_act"); |
412 | 412 | return FALSE; |
@@ -415,21 +415,21 @@ discard block |
||
415 | 415 | // integrate skin information of the module(change to sync skin info with the target module only by seperating its table) |
416 | 416 | $is_default_skin = ((!Mobile::isFromMobilePhone() && $this->module_info->is_skin_fix == 'N') || (Mobile::isFromMobilePhone() && $this->module_info->is_mskin_fix == 'N')); |
417 | 417 | $usedSkinModule = !($this->module == 'page' && ($this->module_info->page_type == 'OUTSIDE' || $this->module_info->page_type == 'WIDGET')); |
418 | - if($usedSkinModule && $is_default_skin && $this->module != 'admin' && strpos($this->act, 'Admin') === false && $this->module == $this->module_info->module) |
|
418 | + if ($usedSkinModule && $is_default_skin && $this->module != 'admin' && strpos($this->act, 'Admin') === false && $this->module == $this->module_info->module) |
|
419 | 419 | { |
420 | 420 | $dir = (Mobile::isFromMobilePhone()) ? 'm.skins' : 'skins'; |
421 | 421 | $valueName = (Mobile::isFromMobilePhone()) ? 'mskin' : 'skin'; |
422 | 422 | $oModuleModel = getModel('module'); |
423 | 423 | $skinType = (Mobile::isFromMobilePhone()) ? 'M' : 'P'; |
424 | 424 | $skinName = $oModuleModel->getModuleDefaultSkin($this->module, $skinType); |
425 | - if($this->module == 'page') |
|
425 | + if ($this->module == 'page') |
|
426 | 426 | { |
427 | 427 | $this->module_info->{$valueName} = $skinName; |
428 | 428 | } |
429 | 429 | else |
430 | 430 | { |
431 | 431 | $isTemplatPath = (strpos($this->getTemplatePath(), '/tpl/') !== FALSE); |
432 | - if(!$isTemplatPath) |
|
432 | + if (!$isTemplatPath) |
|
433 | 433 | { |
434 | 434 | $this->setTemplatePath(sprintf('%s%s/%s/', $this->module_path, $dir, $skinName)); |
435 | 435 | } |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | |
450 | 450 | // trigger call |
451 | 451 | $triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'after', $this); |
452 | - if(!$triggerOutput->toBool()) |
|
452 | + if (!$triggerOutput->toBool()) |
|
453 | 453 | { |
454 | 454 | $this->setError($triggerOutput->getError()); |
455 | 455 | $this->setMessage($triggerOutput->getMessage()); |
@@ -460,25 +460,25 @@ discard block |
||
460 | 460 | $called_position = 'after_module_proc'; |
461 | 461 | $oAddonController = getController('addon'); |
462 | 462 | $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc"); |
463 | - if(FileHandler::exists($addon_file)) include($addon_file); |
|
463 | + if (FileHandler::exists($addon_file)) include($addon_file); |
|
464 | 464 | |
465 | - if(is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject')) |
|
465 | + if (is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject')) |
|
466 | 466 | { |
467 | 467 | $this->setError($output->getError()); |
468 | 468 | $this->setMessage($output->getMessage()); |
469 | 469 | |
470 | - if(!$output->toBool()) |
|
470 | + if (!$output->toBool()) |
|
471 | 471 | { |
472 | 472 | return FALSE; |
473 | 473 | } |
474 | 474 | } |
475 | 475 | // execute api methods of the module if view action is and result is XMLRPC or JSON |
476 | - if($this->module_info->module_type == 'view' || $this->module_info->module_type == 'mobile') |
|
476 | + if ($this->module_info->module_type == 'view' || $this->module_info->module_type == 'mobile') |
|
477 | 477 | { |
478 | - if(Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON') |
|
478 | + if (Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON') |
|
479 | 479 | { |
480 | 480 | $oAPI = getAPI($this->module_info->module, 'api'); |
481 | - if(method_exists($oAPI, $this->act)) |
|
481 | + if (method_exists($oAPI, $this->act)) |
|
482 | 482 | { |
483 | 483 | $oAPI->{$this->act}($this); |
484 | 484 | } |
@@ -168,8 +168,7 @@ discard block |
||
168 | 168 | { |
169 | 169 | $grant = $oModuleModel->getGrant($request_module, $logged_info); |
170 | 170 | } |
171 | - } |
|
172 | - else |
|
171 | + } else |
|
173 | 172 | { |
174 | 173 | $grant = $oModuleModel->getGrant($module_info, $logged_info, $xml_info); |
175 | 174 | // have at least access grant |
@@ -274,7 +273,9 @@ discard block |
||
274 | 273 | * */ |
275 | 274 | function setTemplatePath($path) |
276 | 275 | { |
277 | - if(!$path) return; |
|
276 | + if(!$path) { |
|
277 | + return; |
|
278 | + } |
|
278 | 279 | |
279 | 280 | if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0)) |
280 | 281 | { |
@@ -304,7 +305,9 @@ discard block |
||
304 | 305 | * */ |
305 | 306 | function setEditedLayoutFile($filename) |
306 | 307 | { |
307 | - if(!$filename) return; |
|
308 | + if(!$filename) { |
|
309 | + return; |
|
310 | + } |
|
308 | 311 | |
309 | 312 | if(substr_compare($filename, '.html', -5) !== 0) |
310 | 313 | { |
@@ -329,7 +332,9 @@ discard block |
||
329 | 332 | * */ |
330 | 333 | function setLayoutFile($filename) |
331 | 334 | { |
332 | - if(!$filename) return; |
|
335 | + if(!$filename) { |
|
336 | + return; |
|
337 | + } |
|
333 | 338 | |
334 | 339 | if(substr_compare($filename, '.html', -5) !== 0) |
335 | 340 | { |
@@ -353,7 +358,9 @@ discard block |
||
353 | 358 | * */ |
354 | 359 | function setLayoutPath($path) |
355 | 360 | { |
356 | - if(!$path) return; |
|
361 | + if(!$path) { |
|
362 | + return; |
|
363 | + } |
|
357 | 364 | |
358 | 365 | if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0)) |
359 | 366 | { |
@@ -401,7 +408,9 @@ discard block |
||
401 | 408 | $called_position = 'before_module_proc'; |
402 | 409 | $oAddonController = getController('addon'); |
403 | 410 | $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc"); |
404 | - if(FileHandler::exists($addon_file)) include($addon_file); |
|
411 | + if(FileHandler::exists($addon_file)) { |
|
412 | + include($addon_file); |
|
413 | + } |
|
405 | 414 | |
406 | 415 | if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act)) |
407 | 416 | { |
@@ -425,8 +434,7 @@ discard block |
||
425 | 434 | if($this->module == 'page') |
426 | 435 | { |
427 | 436 | $this->module_info->{$valueName} = $skinName; |
428 | - } |
|
429 | - else |
|
437 | + } else |
|
430 | 438 | { |
431 | 439 | $isTemplatPath = (strpos($this->getTemplatePath(), '/tpl/') !== FALSE); |
432 | 440 | if(!$isTemplatPath) |
@@ -441,8 +449,7 @@ discard block |
||
441 | 449 | Context::set('module_info', $this->module_info); |
442 | 450 | // Run |
443 | 451 | $output = $this->{$this->act}(); |
444 | - } |
|
445 | - else |
|
452 | + } else |
|
446 | 453 | { |
447 | 454 | return FALSE; |
448 | 455 | } |
@@ -460,7 +467,9 @@ discard block |
||
460 | 467 | $called_position = 'after_module_proc'; |
461 | 468 | $oAddonController = getController('addon'); |
462 | 469 | $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc"); |
463 | - if(FileHandler::exists($addon_file)) include($addon_file); |
|
470 | + if(FileHandler::exists($addon_file)) { |
|
471 | + include($addon_file); |
|
472 | + } |
|
464 | 473 | |
465 | 474 | if(is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject')) |
466 | 475 | { |
@@ -295,6 +295,7 @@ discard block |
||
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Check the content. |
298 | + * @param string $content |
|
298 | 299 | * @return void |
299 | 300 | */ |
300 | 301 | function check(&$content) |
@@ -487,7 +488,7 @@ discard block |
||
487 | 488 | |
488 | 489 | /** |
489 | 490 | * Check white domain in object data attribute or embed src attribute. |
490 | - * @return string |
|
491 | + * @return boolean |
|
491 | 492 | */ |
492 | 493 | function isWhiteDomain($urlAttribute) |
493 | 494 | { |
@@ -506,7 +507,7 @@ discard block |
||
506 | 507 | |
507 | 508 | /** |
508 | 509 | * Check white domain in iframe src attribute. |
509 | - * @return string |
|
510 | + * @return boolean |
|
510 | 511 | */ |
511 | 512 | function isWhiteIframeDomain($urlAttribute) |
512 | 513 | { |
@@ -525,7 +526,7 @@ discard block |
||
525 | 526 | |
526 | 527 | /** |
527 | 528 | * Check white mime type in object type attribute or embed type attribute. |
528 | - * @return string |
|
529 | + * @return boolean |
|
529 | 530 | */ |
530 | 531 | function isWhiteMimetype($mimeType) |
531 | 532 | { |
@@ -590,7 +591,7 @@ discard block |
||
590 | 591 | |
591 | 592 | /** |
592 | 593 | * Make white domain list cache file from xml config file. |
593 | - * @param $whitelist array |
|
594 | + * @param stdClass $whitelist array |
|
594 | 595 | * @return void |
595 | 596 | */ |
596 | 597 | function _makeWhiteDomainList($whitelist = NULL) |
@@ -563,14 +563,12 @@ discard block |
||
563 | 563 | } |
564 | 564 | $this->allowscriptaccessList[count($this->allowscriptaccessList) - 1]--; |
565 | 565 | } |
566 | - } |
|
567 | - else if($m[1] == 'embed') |
|
566 | + } else if($m[1] == 'embed') |
|
568 | 567 | { |
569 | 568 | if(stripos($m[0], 'allowscriptaccess')) |
570 | 569 | { |
571 | 570 | $m[0] = preg_replace('/always|samedomain/i', 'never', $m[0]); |
572 | - } |
|
573 | - else |
|
571 | + } else |
|
574 | 572 | { |
575 | 573 | $m[0] = preg_replace('/\<embed/i', '<embed allowscriptaccess="never"', $m[0]); |
576 | 574 | } |
@@ -627,8 +625,7 @@ discard block |
||
627 | 625 | { |
628 | 626 | $whiteUrlList = $whitelist->object; |
629 | 627 | $whiteIframeUrlList = $whitelist->iframe; |
630 | - } |
|
631 | - else |
|
628 | + } else |
|
632 | 629 | { |
633 | 630 | $xmlBuff = FileHandler::readFile($this->whiteUrlXmlFile); |
634 | 631 | |
@@ -636,8 +633,12 @@ discard block |
||
636 | 633 | $domainListObj = $xmlParser->parse($xmlBuff); |
637 | 634 | $embedDomainList = $domainListObj->whiteurl->embed->domain; |
638 | 635 | $iframeDomainList = $domainListObj->whiteurl->iframe->domain; |
639 | - if(!is_array($embedDomainList)) $embedDomainList = array(); |
|
640 | - if(!is_array($iframeDomainList)) $iframeDomainList = array(); |
|
636 | + if(!is_array($embedDomainList)) { |
|
637 | + $embedDomainList = array(); |
|
638 | + } |
|
639 | + if(!is_array($iframeDomainList)) { |
|
640 | + $iframeDomainList = array(); |
|
641 | + } |
|
641 | 642 | |
642 | 643 | foreach($embedDomainList AS $key => $value) |
643 | 644 | { |
@@ -648,8 +649,7 @@ discard block |
||
648 | 649 | { |
649 | 650 | $whiteUrlList[] = $value->body; |
650 | 651 | } |
651 | - } |
|
652 | - else |
|
652 | + } else |
|
653 | 653 | { |
654 | 654 | $whiteUrlList[] = $patternList->body; |
655 | 655 | } |
@@ -664,8 +664,7 @@ discard block |
||
664 | 664 | { |
665 | 665 | $whiteIframeUrlList[] = $value->body; |
666 | 666 | } |
667 | - } |
|
668 | - else |
|
667 | + } else |
|
669 | 668 | { |
670 | 669 | $whiteIframeUrlList[] = $patternList->body; |
671 | 670 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /* Copyright (C) NAVER <http://www.navercorp.com> */ |
3 | 3 | |
4 | -include _XE_PATH_ . 'classes/security/phphtmlparser/src/htmlparser.inc'; |
|
4 | +include _XE_PATH_.'classes/security/phphtmlparser/src/htmlparser.inc'; |
|
5 | 5 | |
6 | 6 | class EmbedFilter |
7 | 7 | { |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | */ |
277 | 277 | function getInstance() |
278 | 278 | { |
279 | - if(!isset($GLOBALS['__EMBEDFILTER_INSTANCE__'])) |
|
279 | + if (!isset($GLOBALS['__EMBEDFILTER_INSTANCE__'])) |
|
280 | 280 | { |
281 | 281 | $GLOBALS['__EMBEDFILTER_INSTANCE__'] = new EmbedFilter(); |
282 | 282 | } |
@@ -316,9 +316,9 @@ discard block |
||
316 | 316 | { |
317 | 317 | preg_match_all('/<\s*object\s*[^>]+(?:\/?>?)/is', $content, $m); |
318 | 318 | $objectTagList = $m[0]; |
319 | - if($objectTagList) |
|
319 | + if ($objectTagList) |
|
320 | 320 | { |
321 | - foreach($objectTagList AS $key => $objectTag) |
|
321 | + foreach ($objectTagList AS $key => $objectTag) |
|
322 | 322 | { |
323 | 323 | $isWhiteDomain = true; |
324 | 324 | $isWhiteMimetype = true; |
@@ -326,21 +326,21 @@ discard block |
||
326 | 326 | $ext = ''; |
327 | 327 | |
328 | 328 | $parser = new HtmlParser($objectTag); |
329 | - while($parser->parse()) |
|
329 | + while ($parser->parse()) |
|
330 | 330 | { |
331 | - if(is_array($parser->iNodeAttributes)) |
|
331 | + if (is_array($parser->iNodeAttributes)) |
|
332 | 332 | { |
333 | - foreach($parser->iNodeAttributes AS $attrName => $attrValue) |
|
333 | + foreach ($parser->iNodeAttributes AS $attrName => $attrValue) |
|
334 | 334 | { |
335 | 335 | // data url check |
336 | - if($attrValue && strtolower($attrName) == 'data') |
|
336 | + if ($attrValue && strtolower($attrName) == 'data') |
|
337 | 337 | { |
338 | 338 | $ext = strtolower(substr(strrchr($attrValue, "."), 1)); |
339 | 339 | $isWhiteDomain = $this->isWhiteDomain($attrValue); |
340 | 340 | } |
341 | 341 | |
342 | 342 | // mime type check |
343 | - if(strtolower($attrName) == 'type' && $attrValue) |
|
343 | + if (strtolower($attrName) == 'type' && $attrValue) |
|
344 | 344 | { |
345 | 345 | $isWhiteMimetype = $this->isWhiteMimetype($attrValue); |
346 | 346 | } |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | } |
349 | 349 | } |
350 | 350 | |
351 | - if(!$isWhiteDomain || !$isWhiteMimetype) |
|
351 | + if (!$isWhiteDomain || !$isWhiteMimetype) |
|
352 | 352 | { |
353 | 353 | $content = str_replace($objectTag, htmlspecialchars($objectTag, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), $content); |
354 | 354 | } |
@@ -364,9 +364,9 @@ discard block |
||
364 | 364 | { |
365 | 365 | preg_match_all('/<\s*embed\s*[^>]+(?:\/?>?)/is', $content, $m); |
366 | 366 | $embedTagList = $m[0]; |
367 | - if($embedTagList) |
|
367 | + if ($embedTagList) |
|
368 | 368 | { |
369 | - foreach($embedTagList AS $key => $embedTag) |
|
369 | + foreach ($embedTagList AS $key => $embedTag) |
|
370 | 370 | { |
371 | 371 | $isWhiteDomain = TRUE; |
372 | 372 | $isWhiteMimetype = TRUE; |
@@ -374,21 +374,21 @@ discard block |
||
374 | 374 | $ext = ''; |
375 | 375 | |
376 | 376 | $parser = new HtmlParser($embedTag); |
377 | - while($parser->parse()) |
|
377 | + while ($parser->parse()) |
|
378 | 378 | { |
379 | - if(is_array($parser->iNodeAttributes)) |
|
379 | + if (is_array($parser->iNodeAttributes)) |
|
380 | 380 | { |
381 | - foreach($parser->iNodeAttributes AS $attrName => $attrValue) |
|
381 | + foreach ($parser->iNodeAttributes AS $attrName => $attrValue) |
|
382 | 382 | { |
383 | 383 | // src url check |
384 | - if($attrValue && strtolower($attrName) == 'src') |
|
384 | + if ($attrValue && strtolower($attrName) == 'src') |
|
385 | 385 | { |
386 | 386 | $ext = strtolower(substr(strrchr($attrValue, "."), 1)); |
387 | 387 | $isWhiteDomain = $this->isWhiteDomain($attrValue); |
388 | 388 | } |
389 | 389 | |
390 | 390 | // mime type check |
391 | - if(strtolower($attrName) == 'type' && $attrValue) |
|
391 | + if (strtolower($attrName) == 'type' && $attrValue) |
|
392 | 392 | { |
393 | 393 | $isWhiteMimetype = $this->isWhiteMimetype($attrValue); |
394 | 394 | } |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
399 | - if(!$isWhiteDomain || !$isWhiteMimetype) |
|
399 | + if (!$isWhiteDomain || !$isWhiteMimetype) |
|
400 | 400 | { |
401 | 401 | $content = str_replace($embedTag, htmlspecialchars($embedTag, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), $content); |
402 | 402 | } |
@@ -415,22 +415,22 @@ discard block |
||
415 | 415 | |
416 | 416 | preg_match_all('/<\s*iframe\s*[^>]+(?:\/?>?)/is', $content, $m); |
417 | 417 | $iframeTagList = $m[0]; |
418 | - if($iframeTagList) |
|
418 | + if ($iframeTagList) |
|
419 | 419 | { |
420 | - foreach($iframeTagList AS $key => $iframeTag) |
|
420 | + foreach ($iframeTagList AS $key => $iframeTag) |
|
421 | 421 | { |
422 | 422 | $isWhiteDomain = TRUE; |
423 | 423 | $ext = ''; |
424 | 424 | |
425 | 425 | $parser = new HtmlParser($iframeTag); |
426 | - while($parser->parse()) |
|
426 | + while ($parser->parse()) |
|
427 | 427 | { |
428 | - if(is_array($parser->iNodeAttributes)) |
|
428 | + if (is_array($parser->iNodeAttributes)) |
|
429 | 429 | { |
430 | - foreach($parser->iNodeAttributes AS $attrName => $attrValue) |
|
430 | + foreach ($parser->iNodeAttributes AS $attrName => $attrValue) |
|
431 | 431 | { |
432 | 432 | // src url check |
433 | - if(strtolower($attrName) == 'src' && $attrValue) |
|
433 | + if (strtolower($attrName) == 'src' && $attrValue) |
|
434 | 434 | { |
435 | 435 | $ext = strtolower(substr(strrchr($attrValue, "."), 1)); |
436 | 436 | $isWhiteDomain = $this->isWhiteIframeDomain($attrValue); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | - if(!$isWhiteDomain) |
|
442 | + if (!$isWhiteDomain) |
|
443 | 443 | { |
444 | 444 | $content = str_replace($iframeTag, htmlspecialchars($iframeTag, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), $content); |
445 | 445 | } |
@@ -455,26 +455,26 @@ discard block |
||
455 | 455 | { |
456 | 456 | preg_match_all('/<\s*param\s*[^>]+(?:\/?>?)/is', $content, $m); |
457 | 457 | $paramTagList = $m[0]; |
458 | - if($paramTagList) |
|
458 | + if ($paramTagList) |
|
459 | 459 | { |
460 | - foreach($paramTagList AS $key => $paramTag) |
|
460 | + foreach ($paramTagList AS $key => $paramTag) |
|
461 | 461 | { |
462 | 462 | $isWhiteDomain = TRUE; |
463 | 463 | $isWhiteExt = TRUE; |
464 | 464 | $ext = ''; |
465 | 465 | |
466 | 466 | $parser = new HtmlParser($paramTag); |
467 | - while($parser->parse()) |
|
467 | + while ($parser->parse()) |
|
468 | 468 | { |
469 | - if($parser->iNodeAttributes['name'] && $parser->iNodeAttributes['value']) |
|
469 | + if ($parser->iNodeAttributes['name'] && $parser->iNodeAttributes['value']) |
|
470 | 470 | { |
471 | 471 | $name = strtolower($parser->iNodeAttributes['name']); |
472 | - if($name == 'movie' || $name == 'src' || $name == 'href' || $name == 'url' || $name == 'source') |
|
472 | + if ($name == 'movie' || $name == 'src' || $name == 'href' || $name == 'url' || $name == 'source') |
|
473 | 473 | { |
474 | 474 | $ext = strtolower(substr(strrchr($parser->iNodeAttributes['value'], "."), 1)); |
475 | 475 | $isWhiteDomain = $this->isWhiteDomain($parser->iNodeAttributes['value']); |
476 | 476 | |
477 | - if(!$isWhiteDomain) |
|
477 | + if (!$isWhiteDomain) |
|
478 | 478 | { |
479 | 479 | $content = str_replace($paramTag, htmlspecialchars($paramTag, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), $content); |
480 | 480 | } |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | */ |
492 | 492 | function isWhiteDomain($urlAttribute) |
493 | 493 | { |
494 | - if(is_array($this->whiteUrlList)) |
|
494 | + if (is_array($this->whiteUrlList)) |
|
495 | 495 | { |
496 | - foreach($this->whiteUrlList AS $key => $value) |
|
496 | + foreach ($this->whiteUrlList AS $key => $value) |
|
497 | 497 | { |
498 | - if(preg_match('@^' . preg_quote($value) . '@i', $urlAttribute)) |
|
498 | + if (preg_match('@^'.preg_quote($value).'@i', $urlAttribute)) |
|
499 | 499 | { |
500 | 500 | return TRUE; |
501 | 501 | } |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | */ |
511 | 511 | function isWhiteIframeDomain($urlAttribute) |
512 | 512 | { |
513 | - if(is_array($this->whiteIframeUrlList)) |
|
513 | + if (is_array($this->whiteIframeUrlList)) |
|
514 | 514 | { |
515 | - foreach($this->whiteIframeUrlList AS $key => $value) |
|
515 | + foreach ($this->whiteIframeUrlList AS $key => $value) |
|
516 | 516 | { |
517 | - if(preg_match('@^' . preg_quote($value) . '@i', $urlAttribute)) |
|
517 | + if (preg_match('@^'.preg_quote($value).'@i', $urlAttribute)) |
|
518 | 518 | { |
519 | 519 | return TRUE; |
520 | 520 | } |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | */ |
530 | 530 | function isWhiteMimetype($mimeType) |
531 | 531 | { |
532 | - if(isset($this->mimeTypeList[$mimeType])) |
|
532 | + if (isset($this->mimeTypeList[$mimeType])) |
|
533 | 533 | { |
534 | 534 | return TRUE; |
535 | 535 | } |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | |
539 | 539 | function isWhiteExt($ext) |
540 | 540 | { |
541 | - if(isset($this->extList[$ext])) |
|
541 | + if (isset($this->extList[$ext])) |
|
542 | 542 | { |
543 | 543 | return TRUE; |
544 | 544 | } |
@@ -547,26 +547,26 @@ discard block |
||
547 | 547 | |
548 | 548 | function _checkAllowScriptAccess($m) |
549 | 549 | { |
550 | - if($m[1] == 'object') |
|
550 | + if ($m[1] == 'object') |
|
551 | 551 | { |
552 | 552 | $this->allowscriptaccessList[] = 1; |
553 | 553 | } |
554 | 554 | |
555 | - if($m[1] == 'param') |
|
555 | + if ($m[1] == 'param') |
|
556 | 556 | { |
557 | - if(stripos($m[0], 'allowscriptaccess')) |
|
557 | + if (stripos($m[0], 'allowscriptaccess')) |
|
558 | 558 | { |
559 | 559 | $m[0] = '<param name="allowscriptaccess" value="never"'; |
560 | - if(substr($m[0], -1) == '/') |
|
560 | + if (substr($m[0], -1) == '/') |
|
561 | 561 | { |
562 | 562 | $m[0] .= '/'; |
563 | 563 | } |
564 | 564 | $this->allowscriptaccessList[count($this->allowscriptaccessList) - 1]--; |
565 | 565 | } |
566 | 566 | } |
567 | - else if($m[1] == 'embed') |
|
567 | + else if ($m[1] == 'embed') |
|
568 | 568 | { |
569 | - if(stripos($m[0], 'allowscriptaccess')) |
|
569 | + if (stripos($m[0], 'allowscriptaccess')) |
|
570 | 570 | { |
571 | 571 | $m[0] = preg_replace('/always|samedomain/i', 'never', $m[0]); |
572 | 572 | } |
@@ -580,9 +580,9 @@ discard block |
||
580 | 580 | |
581 | 581 | function _addAllowScriptAccess($m) |
582 | 582 | { |
583 | - if($this->allowscriptaccessList[$this->allowscriptaccessKey] == 1) |
|
583 | + if ($this->allowscriptaccessList[$this->allowscriptaccessKey] == 1) |
|
584 | 584 | { |
585 | - $m[0] = $m[0] . '<param name="allowscriptaccess" value="never"></param>'; |
|
585 | + $m[0] = $m[0].'<param name="allowscriptaccess" value="never"></param>'; |
|
586 | 586 | } |
587 | 587 | $this->allowscriptaccessKey++; |
588 | 588 | return $m[0]; |
@@ -599,31 +599,31 @@ discard block |
||
599 | 599 | $whiteUrlCacheFile = FileHandler::getRealPath($this->whiteUrlCacheFile); |
600 | 600 | |
601 | 601 | $isMake = FALSE; |
602 | - if(!file_exists($whiteUrlCacheFile)) |
|
602 | + if (!file_exists($whiteUrlCacheFile)) |
|
603 | 603 | { |
604 | 604 | $isMake = TRUE; |
605 | 605 | } |
606 | - if(file_exists($whiteUrlCacheFile) && filemtime($whiteUrlCacheFile) < filemtime($whiteUrlXmlFile)) |
|
606 | + if (file_exists($whiteUrlCacheFile) && filemtime($whiteUrlCacheFile) < filemtime($whiteUrlXmlFile)) |
|
607 | 607 | { |
608 | 608 | $isMake = TRUE; |
609 | 609 | } |
610 | 610 | |
611 | - if(gettype($whitelist) == 'array' && gettype($whitelist['object']) == 'array' && gettype($whitelist['iframe']) == 'array') |
|
611 | + if (gettype($whitelist) == 'array' && gettype($whitelist['object']) == 'array' && gettype($whitelist['iframe']) == 'array') |
|
612 | 612 | { |
613 | 613 | $isMake = FALSE; |
614 | 614 | } |
615 | 615 | |
616 | - if(isset($whitelist) && gettype($whitelist) == 'object') |
|
616 | + if (isset($whitelist) && gettype($whitelist) == 'object') |
|
617 | 617 | { |
618 | 618 | $isMake = TRUE; |
619 | 619 | } |
620 | 620 | |
621 | - if($isMake) |
|
621 | + if ($isMake) |
|
622 | 622 | { |
623 | 623 | $whiteUrlList = array(); |
624 | 624 | $whiteIframeUrlList = array(); |
625 | 625 | |
626 | - if(gettype($whitelist->object) == 'array' && gettype($whitelist->iframe) == 'array') |
|
626 | + if (gettype($whitelist->object) == 'array' && gettype($whitelist->iframe) == 'array') |
|
627 | 627 | { |
628 | 628 | $whiteUrlList = $whitelist->object; |
629 | 629 | $whiteIframeUrlList = $whitelist->iframe; |
@@ -636,15 +636,15 @@ discard block |
||
636 | 636 | $domainListObj = $xmlParser->parse($xmlBuff); |
637 | 637 | $embedDomainList = $domainListObj->whiteurl->embed->domain; |
638 | 638 | $iframeDomainList = $domainListObj->whiteurl->iframe->domain; |
639 | - if(!is_array($embedDomainList)) $embedDomainList = array(); |
|
640 | - if(!is_array($iframeDomainList)) $iframeDomainList = array(); |
|
639 | + if (!is_array($embedDomainList)) $embedDomainList = array(); |
|
640 | + if (!is_array($iframeDomainList)) $iframeDomainList = array(); |
|
641 | 641 | |
642 | - foreach($embedDomainList AS $key => $value) |
|
642 | + foreach ($embedDomainList AS $key => $value) |
|
643 | 643 | { |
644 | 644 | $patternList = $value->pattern; |
645 | - if(is_array($patternList)) |
|
645 | + if (is_array($patternList)) |
|
646 | 646 | { |
647 | - foreach($patternList AS $key => $value) |
|
647 | + foreach ($patternList AS $key => $value) |
|
648 | 648 | { |
649 | 649 | $whiteUrlList[] = $value->body; |
650 | 650 | } |
@@ -655,12 +655,12 @@ discard block |
||
655 | 655 | } |
656 | 656 | } |
657 | 657 | |
658 | - foreach($iframeDomainList AS $key => $value) |
|
658 | + foreach ($iframeDomainList AS $key => $value) |
|
659 | 659 | { |
660 | 660 | $patternList = $value->pattern; |
661 | - if(is_array($patternList)) |
|
661 | + if (is_array($patternList)) |
|
662 | 662 | { |
663 | - foreach($patternList AS $key => $value) |
|
663 | + foreach ($patternList AS $key => $value) |
|
664 | 664 | { |
665 | 665 | $whiteIframeUrlList[] = $value->body; |
666 | 666 | } |
@@ -674,12 +674,12 @@ discard block |
||
674 | 674 | |
675 | 675 | $db_info = Context::getDBInfo(); |
676 | 676 | |
677 | - if($db_info->embed_white_object) |
|
677 | + if ($db_info->embed_white_object) |
|
678 | 678 | { |
679 | 679 | $whiteUrlList = array_merge($whiteUrlList, $db_info->embed_white_object); |
680 | 680 | } |
681 | 681 | |
682 | - if($db_info->embed_white_iframe) |
|
682 | + if ($db_info->embed_white_iframe) |
|
683 | 683 | { |
684 | 684 | $whiteIframeUrlList = array_merge($whiteIframeUrlList, $db_info->embed_white_iframe); |
685 | 685 | } |
@@ -691,8 +691,8 @@ discard block |
||
691 | 691 | |
692 | 692 | $buff = array(); |
693 | 693 | $buff[] = '<?php if(!defined("__XE__")) exit();'; |
694 | - $buff[] = '$whiteUrlList = ' . var_export($whiteUrlList, TRUE) . ';'; |
|
695 | - $buff[] = '$whiteIframeUrlList = ' . var_export($whiteIframeUrlList, TRUE) . ';'; |
|
694 | + $buff[] = '$whiteUrlList = '.var_export($whiteUrlList, TRUE).';'; |
|
695 | + $buff[] = '$whiteIframeUrlList = '.var_export($whiteIframeUrlList, TRUE).';'; |
|
696 | 696 | |
697 | 697 | FileHandler::writeFile($this->whiteUrlCacheFile, implode(PHP_EOL, $buff)); |
698 | 698 | } |
@@ -11,6 +11,7 @@ |
||
11 | 11 | /** |
12 | 12 | * @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable. |
13 | 13 | * @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable. |
14 | + * @param string $min |
|
14 | 15 | */ |
15 | 16 | public function __construct($min = null, $max = null) { |
16 | 17 | $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null; |
@@ -6,41 +6,41 @@ |
||
6 | 6 | class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef |
7 | 7 | { |
8 | 8 | |
9 | - protected $min, $max; |
|
10 | - |
|
11 | - /** |
|
12 | - * @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable. |
|
13 | - * @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable. |
|
14 | - */ |
|
15 | - public function __construct($min = null, $max = null) { |
|
16 | - $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null; |
|
17 | - $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null; |
|
18 | - } |
|
19 | - |
|
20 | - public function validate($string, $config, $context) { |
|
21 | - $string = $this->parseCDATA($string); |
|
22 | - |
|
23 | - // Optimizations |
|
24 | - if ($string === '') return false; |
|
25 | - if ($string === '0') return '0'; |
|
26 | - if (strlen($string) === 1) return false; |
|
27 | - |
|
28 | - $length = HTMLPurifier_Length::make($string); |
|
29 | - if (!$length->isValid()) return false; |
|
30 | - |
|
31 | - if ($this->min) { |
|
32 | - $c = $length->compareTo($this->min); |
|
33 | - if ($c === false) return false; |
|
34 | - if ($c < 0) return false; |
|
35 | - } |
|
36 | - if ($this->max) { |
|
37 | - $c = $length->compareTo($this->max); |
|
38 | - if ($c === false) return false; |
|
39 | - if ($c > 0) return false; |
|
40 | - } |
|
41 | - |
|
42 | - return $length->toString(); |
|
43 | - } |
|
9 | + protected $min, $max; |
|
10 | + |
|
11 | + /** |
|
12 | + * @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable. |
|
13 | + * @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable. |
|
14 | + */ |
|
15 | + public function __construct($min = null, $max = null) { |
|
16 | + $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null; |
|
17 | + $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null; |
|
18 | + } |
|
19 | + |
|
20 | + public function validate($string, $config, $context) { |
|
21 | + $string = $this->parseCDATA($string); |
|
22 | + |
|
23 | + // Optimizations |
|
24 | + if ($string === '') return false; |
|
25 | + if ($string === '0') return '0'; |
|
26 | + if (strlen($string) === 1) return false; |
|
27 | + |
|
28 | + $length = HTMLPurifier_Length::make($string); |
|
29 | + if (!$length->isValid()) return false; |
|
30 | + |
|
31 | + if ($this->min) { |
|
32 | + $c = $length->compareTo($this->min); |
|
33 | + if ($c === false) return false; |
|
34 | + if ($c < 0) return false; |
|
35 | + } |
|
36 | + if ($this->max) { |
|
37 | + $c = $length->compareTo($this->max); |
|
38 | + if ($c === false) return false; |
|
39 | + if ($c > 0) return false; |
|
40 | + } |
|
41 | + |
|
42 | + return $length->toString(); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
46 | 46 |
@@ -21,22 +21,38 @@ |
||
21 | 21 | $string = $this->parseCDATA($string); |
22 | 22 | |
23 | 23 | // Optimizations |
24 | - if ($string === '') return false; |
|
25 | - if ($string === '0') return '0'; |
|
26 | - if (strlen($string) === 1) return false; |
|
24 | + if ($string === '') { |
|
25 | + return false; |
|
26 | + } |
|
27 | + if ($string === '0') { |
|
28 | + return '0'; |
|
29 | + } |
|
30 | + if (strlen($string) === 1) { |
|
31 | + return false; |
|
32 | + } |
|
27 | 33 | |
28 | 34 | $length = HTMLPurifier_Length::make($string); |
29 | - if (!$length->isValid()) return false; |
|
35 | + if (!$length->isValid()) { |
|
36 | + return false; |
|
37 | + } |
|
30 | 38 | |
31 | 39 | if ($this->min) { |
32 | 40 | $c = $length->compareTo($this->min); |
33 | - if ($c === false) return false; |
|
34 | - if ($c < 0) return false; |
|
41 | + if ($c === false) { |
|
42 | + return false; |
|
43 | + } |
|
44 | + if ($c < 0) { |
|
45 | + return false; |
|
46 | + } |
|
35 | 47 | } |
36 | 48 | if ($this->max) { |
37 | 49 | $c = $length->compareTo($this->max); |
38 | - if ($c === false) return false; |
|
39 | - if ($c > 0) return false; |
|
50 | + if ($c === false) { |
|
51 | + return false; |
|
52 | + } |
|
53 | + if ($c > 0) { |
|
54 | + return false; |
|
55 | + } |
|
40 | 56 | } |
41 | 57 | |
42 | 58 | return $length->toString(); |
@@ -9,6 +9,9 @@ |
||
9 | 9 | class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4 |
10 | 10 | { |
11 | 11 | |
12 | + /** |
|
13 | + * @param string $aIP |
|
14 | + */ |
|
12 | 15 | public function validate($aIP, $config, $context) { |
13 | 16 | |
14 | 17 | if (!$this->ip4) $this->_loadRegex(); |
@@ -9,90 +9,90 @@ |
||
9 | 9 | class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4 |
10 | 10 | { |
11 | 11 | |
12 | - public function validate($aIP, $config, $context) { |
|
13 | - |
|
14 | - if (!$this->ip4) $this->_loadRegex(); |
|
15 | - |
|
16 | - $original = $aIP; |
|
17 | - |
|
18 | - $hex = '[0-9a-fA-F]'; |
|
19 | - $blk = '(?:' . $hex . '{1,4})'; |
|
20 | - $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128 |
|
21 | - |
|
22 | - // prefix check |
|
23 | - if (strpos($aIP, '/') !== false) |
|
24 | - { |
|
25 | - if (preg_match('#' . $pre . '$#s', $aIP, $find)) |
|
26 | - { |
|
27 | - $aIP = substr($aIP, 0, 0-strlen($find[0])); |
|
28 | - unset($find); |
|
29 | - } |
|
30 | - else |
|
31 | - { |
|
32 | - return false; |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - // IPv4-compatiblity check |
|
37 | - if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find)) |
|
38 | - { |
|
39 | - $aIP = substr($aIP, 0, 0-strlen($find[0])); |
|
40 | - $ip = explode('.', $find[0]); |
|
41 | - $ip = array_map('dechex', $ip); |
|
42 | - $aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3]; |
|
43 | - unset($find, $ip); |
|
44 | - } |
|
45 | - |
|
46 | - // compression check |
|
47 | - $aIP = explode('::', $aIP); |
|
48 | - $c = count($aIP); |
|
49 | - if ($c > 2) |
|
50 | - { |
|
51 | - return false; |
|
52 | - } |
|
53 | - elseif ($c == 2) |
|
54 | - { |
|
55 | - list($first, $second) = $aIP; |
|
56 | - $first = explode(':', $first); |
|
57 | - $second = explode(':', $second); |
|
58 | - |
|
59 | - if (count($first) + count($second) > 8) |
|
60 | - { |
|
61 | - return false; |
|
62 | - } |
|
63 | - |
|
64 | - while(count($first) < 8) |
|
65 | - { |
|
66 | - array_push($first, '0'); |
|
67 | - } |
|
68 | - |
|
69 | - array_splice($first, 8 - count($second), 8, $second); |
|
70 | - $aIP = $first; |
|
71 | - unset($first,$second); |
|
72 | - } |
|
73 | - else |
|
74 | - { |
|
75 | - $aIP = explode(':', $aIP[0]); |
|
76 | - } |
|
77 | - $c = count($aIP); |
|
78 | - |
|
79 | - if ($c != 8) |
|
80 | - { |
|
81 | - return false; |
|
82 | - } |
|
83 | - |
|
84 | - // All the pieces should be 16-bit hex strings. Are they? |
|
85 | - foreach ($aIP as $piece) |
|
86 | - { |
|
87 | - if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece))) |
|
88 | - { |
|
89 | - return false; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - return $original; |
|
94 | - |
|
95 | - } |
|
12 | + public function validate($aIP, $config, $context) { |
|
13 | + |
|
14 | + if (!$this->ip4) $this->_loadRegex(); |
|
15 | + |
|
16 | + $original = $aIP; |
|
17 | + |
|
18 | + $hex = '[0-9a-fA-F]'; |
|
19 | + $blk = '(?:' . $hex . '{1,4})'; |
|
20 | + $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128 |
|
21 | + |
|
22 | + // prefix check |
|
23 | + if (strpos($aIP, '/') !== false) |
|
24 | + { |
|
25 | + if (preg_match('#' . $pre . '$#s', $aIP, $find)) |
|
26 | + { |
|
27 | + $aIP = substr($aIP, 0, 0-strlen($find[0])); |
|
28 | + unset($find); |
|
29 | + } |
|
30 | + else |
|
31 | + { |
|
32 | + return false; |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + // IPv4-compatiblity check |
|
37 | + if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find)) |
|
38 | + { |
|
39 | + $aIP = substr($aIP, 0, 0-strlen($find[0])); |
|
40 | + $ip = explode('.', $find[0]); |
|
41 | + $ip = array_map('dechex', $ip); |
|
42 | + $aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3]; |
|
43 | + unset($find, $ip); |
|
44 | + } |
|
45 | + |
|
46 | + // compression check |
|
47 | + $aIP = explode('::', $aIP); |
|
48 | + $c = count($aIP); |
|
49 | + if ($c > 2) |
|
50 | + { |
|
51 | + return false; |
|
52 | + } |
|
53 | + elseif ($c == 2) |
|
54 | + { |
|
55 | + list($first, $second) = $aIP; |
|
56 | + $first = explode(':', $first); |
|
57 | + $second = explode(':', $second); |
|
58 | + |
|
59 | + if (count($first) + count($second) > 8) |
|
60 | + { |
|
61 | + return false; |
|
62 | + } |
|
63 | + |
|
64 | + while(count($first) < 8) |
|
65 | + { |
|
66 | + array_push($first, '0'); |
|
67 | + } |
|
68 | + |
|
69 | + array_splice($first, 8 - count($second), 8, $second); |
|
70 | + $aIP = $first; |
|
71 | + unset($first,$second); |
|
72 | + } |
|
73 | + else |
|
74 | + { |
|
75 | + $aIP = explode(':', $aIP[0]); |
|
76 | + } |
|
77 | + $c = count($aIP); |
|
78 | + |
|
79 | + if ($c != 8) |
|
80 | + { |
|
81 | + return false; |
|
82 | + } |
|
83 | + |
|
84 | + // All the pieces should be 16-bit hex strings. Are they? |
|
85 | + foreach ($aIP as $piece) |
|
86 | + { |
|
87 | + if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece))) |
|
88 | + { |
|
89 | + return false; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + return $original; |
|
94 | + |
|
95 | + } |
|
96 | 96 | |
97 | 97 | } |
98 | 98 |
@@ -11,7 +11,9 @@ discard block |
||
11 | 11 | |
12 | 12 | public function validate($aIP, $config, $context) { |
13 | 13 | |
14 | - if (!$this->ip4) $this->_loadRegex(); |
|
14 | + if (!$this->ip4) { |
|
15 | + $this->_loadRegex(); |
|
16 | + } |
|
15 | 17 | |
16 | 18 | $original = $aIP; |
17 | 19 | |
@@ -26,8 +28,7 @@ discard block |
||
26 | 28 | { |
27 | 29 | $aIP = substr($aIP, 0, 0-strlen($find[0])); |
28 | 30 | unset($find); |
29 | - } |
|
30 | - else |
|
31 | + } else |
|
31 | 32 | { |
32 | 33 | return false; |
33 | 34 | } |
@@ -49,8 +50,7 @@ discard block |
||
49 | 50 | if ($c > 2) |
50 | 51 | { |
51 | 52 | return false; |
52 | - } |
|
53 | - elseif ($c == 2) |
|
53 | + } elseif ($c == 2) |
|
54 | 54 | { |
55 | 55 | list($first, $second) = $aIP; |
56 | 56 | $first = explode(':', $first); |
@@ -69,8 +69,7 @@ discard block |
||
69 | 69 | array_splice($first, 8 - count($second), 8, $second); |
70 | 70 | $aIP = $first; |
71 | 71 | unset($first,$second); |
72 | - } |
|
73 | - else |
|
72 | + } else |
|
74 | 73 | { |
75 | 74 | $aIP = explode(':', $aIP[0]); |
76 | 75 | } |
@@ -16,15 +16,15 @@ discard block |
||
16 | 16 | $original = $aIP; |
17 | 17 | |
18 | 18 | $hex = '[0-9a-fA-F]'; |
19 | - $blk = '(?:' . $hex . '{1,4})'; |
|
20 | - $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128 |
|
19 | + $blk = '(?:'.$hex.'{1,4})'; |
|
20 | + $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128 |
|
21 | 21 | |
22 | 22 | // prefix check |
23 | 23 | if (strpos($aIP, '/') !== false) |
24 | 24 | { |
25 | - if (preg_match('#' . $pre . '$#s', $aIP, $find)) |
|
25 | + if (preg_match('#'.$pre.'$#s', $aIP, $find)) |
|
26 | 26 | { |
27 | - $aIP = substr($aIP, 0, 0-strlen($find[0])); |
|
27 | + $aIP = substr($aIP, 0, 0 - strlen($find[0])); |
|
28 | 28 | unset($find); |
29 | 29 | } |
30 | 30 | else |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | // IPv4-compatiblity check |
37 | - if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find)) |
|
37 | + if (preg_match('#(?<=:'.')'.$this->ip4.'$#s', $aIP, $find)) |
|
38 | 38 | { |
39 | - $aIP = substr($aIP, 0, 0-strlen($find[0])); |
|
39 | + $aIP = substr($aIP, 0, 0 - strlen($find[0])); |
|
40 | 40 | $ip = explode('.', $find[0]); |
41 | 41 | $ip = array_map('dechex', $ip); |
42 | - $aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3]; |
|
42 | + $aIP .= $ip[0].$ip[1].':'.$ip[2].$ip[3]; |
|
43 | 43 | unset($find, $ip); |
44 | 44 | } |
45 | 45 | |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | |
64 | - while(count($first) < 8) |
|
64 | + while (count($first) < 8) |
|
65 | 65 | { |
66 | 66 | array_push($first, '0'); |
67 | 67 | } |
68 | 68 | |
69 | 69 | array_splice($first, 8 - count($second), 8, $second); |
70 | 70 | $aIP = $first; |
71 | - unset($first,$second); |
|
71 | + unset($first, $second); |
|
72 | 72 | } |
73 | 73 | else |
74 | 74 | { |
@@ -89,6 +89,7 @@ discard block |
||
89 | 89 | /** |
90 | 90 | * @param $definition HTMLPurifier_ConfigSchema that defines what directives |
91 | 91 | * are allowed. |
92 | + * @param HTMLPurifier_PropertyList $parent |
|
92 | 93 | */ |
93 | 94 | public function __construct($definition, $parent = null) { |
94 | 95 | $parent = $parent ? $parent : $definition->defaultPlist; |
@@ -104,7 +105,7 @@ discard block |
||
104 | 105 | * an array of directives based on loadArray(), |
105 | 106 | * or a string filename of an ini file. |
106 | 107 | * @param HTMLPurifier_ConfigSchema Schema object |
107 | - * @return Configured HTMLPurifier_Config object |
|
108 | + * @return HTMLPurifier_Config HTMLPurifier_Config object |
|
108 | 109 | */ |
109 | 110 | public static function create($config, $schema = null) { |
110 | 111 | if ($config instanceof HTMLPurifier_Config) { |
@@ -133,7 +134,7 @@ discard block |
||
133 | 134 | |
134 | 135 | /** |
135 | 136 | * Convenience constructor that creates a default configuration object. |
136 | - * @return Default HTMLPurifier_Config object. |
|
137 | + * @return HTMLPurifier_Config HTMLPurifier_Config object. |
|
137 | 138 | */ |
138 | 139 | public static function createDefault() { |
139 | 140 | $definition = HTMLPurifier_ConfigSchema::instance(); |
@@ -143,7 +144,7 @@ discard block |
||
143 | 144 | |
144 | 145 | /** |
145 | 146 | * Retreives a value from the configuration. |
146 | - * @param $key String key |
|
147 | + * @param string $key String key |
|
147 | 148 | */ |
148 | 149 | public function get($key, $a = null) { |
149 | 150 | if ($a !== null) { |
@@ -231,7 +232,7 @@ discard block |
||
231 | 232 | |
232 | 233 | /** |
233 | 234 | * Sets a value to configuration. |
234 | - * @param $key String key |
|
235 | + * @param string $key String key |
|
235 | 236 | * @param $value Mixed value |
236 | 237 | */ |
237 | 238 | public function set($key, $value, $a = null) { |
@@ -543,7 +544,7 @@ discard block |
||
543 | 544 | * Returns a list of array(namespace, directive) for all directives |
544 | 545 | * that are allowed in a web-form context as per an allowed |
545 | 546 | * namespaces/directives list. |
546 | - * @param $allowed List of allowed namespaces/directives |
|
547 | + * @param boolean $allowed List of allowed namespaces/directives |
|
547 | 548 | */ |
548 | 549 | public static function getAllowedDirectivesForForm($allowed, $schema = null) { |
549 | 550 | if (!$schema) { |
@@ -585,7 +586,6 @@ discard block |
||
585 | 586 | /** |
586 | 587 | * Loads configuration values from $_GET/$_POST that were posted |
587 | 588 | * via ConfigForm |
588 | - * @param $array $_GET or $_POST array to import |
|
589 | 589 | * @param $index Index/name that the config variables are in |
590 | 590 | * @param $allowed List of allowed namespaces/directives |
591 | 591 | * @param $mq_fix Boolean whether or not to enable magic quotes fix |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | |
633 | 633 | /** |
634 | 634 | * Loads configuration values from an ini file |
635 | - * @param $filename Name of ini file |
|
635 | + * @param string $filename Name of ini file |
|
636 | 636 | */ |
637 | 637 | public function loadIni($filename) { |
638 | 638 | if ($this->isFinalized('Cannot load directives after finalization')) return; |
@@ -674,6 +674,7 @@ discard block |
||
674 | 674 | /** |
675 | 675 | * Produces a nicely formatted error message by supplying the |
676 | 676 | * stack frame information OUTSIDE of HTMLPurifier_Config. |
677 | + * @param integer $no |
|
677 | 678 | */ |
678 | 679 | protected function triggerError($msg, $no) { |
679 | 680 | // determine previous stack frame |
@@ -17,692 +17,692 @@ |
||
17 | 17 | class HTMLPurifier_Config |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * HTML Purifier's version |
|
22 | - */ |
|
23 | - public $version = '4.4.0'; |
|
24 | - |
|
25 | - /** |
|
26 | - * Bool indicator whether or not to automatically finalize |
|
27 | - * the object if a read operation is done |
|
28 | - */ |
|
29 | - public $autoFinalize = true; |
|
30 | - |
|
31 | - // protected member variables |
|
32 | - |
|
33 | - /** |
|
34 | - * Namespace indexed array of serials for specific namespaces (see |
|
35 | - * getSerial() for more info). |
|
36 | - */ |
|
37 | - protected $serials = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * Serial for entire configuration object |
|
41 | - */ |
|
42 | - protected $serial; |
|
43 | - |
|
44 | - /** |
|
45 | - * Parser for variables |
|
46 | - */ |
|
47 | - protected $parser = null; |
|
48 | - |
|
49 | - /** |
|
50 | - * Reference HTMLPurifier_ConfigSchema for value checking |
|
51 | - * @note This is public for introspective purposes. Please don't |
|
52 | - * abuse! |
|
53 | - */ |
|
54 | - public $def; |
|
55 | - |
|
56 | - /** |
|
57 | - * Indexed array of definitions |
|
58 | - */ |
|
59 | - protected $definitions; |
|
60 | - |
|
61 | - /** |
|
62 | - * Bool indicator whether or not config is finalized |
|
63 | - */ |
|
64 | - protected $finalized = false; |
|
65 | - |
|
66 | - /** |
|
67 | - * Property list containing configuration directives. |
|
68 | - */ |
|
69 | - protected $plist; |
|
70 | - |
|
71 | - /** |
|
72 | - * Whether or not a set is taking place due to an |
|
73 | - * alias lookup. |
|
74 | - */ |
|
75 | - private $aliasMode; |
|
76 | - |
|
77 | - /** |
|
78 | - * Set to false if you do not want line and file numbers in errors |
|
79 | - * (useful when unit testing). This will also compress some errors |
|
80 | - * and exceptions. |
|
81 | - */ |
|
82 | - public $chatty = true; |
|
83 | - |
|
84 | - /** |
|
85 | - * Current lock; only gets to this namespace are allowed. |
|
86 | - */ |
|
87 | - private $lock; |
|
88 | - |
|
89 | - /** |
|
90 | - * @param $definition HTMLPurifier_ConfigSchema that defines what directives |
|
91 | - * are allowed. |
|
92 | - */ |
|
93 | - public function __construct($definition, $parent = null) { |
|
94 | - $parent = $parent ? $parent : $definition->defaultPlist; |
|
95 | - $this->plist = new HTMLPurifier_PropertyList($parent); |
|
96 | - $this->def = $definition; // keep a copy around for checking |
|
97 | - $this->parser = new HTMLPurifier_VarParser_Flexible(); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Convenience constructor that creates a config object based on a mixed var |
|
102 | - * @param mixed $config Variable that defines the state of the config |
|
103 | - * object. Can be: a HTMLPurifier_Config() object, |
|
104 | - * an array of directives based on loadArray(), |
|
105 | - * or a string filename of an ini file. |
|
106 | - * @param HTMLPurifier_ConfigSchema Schema object |
|
107 | - * @return Configured HTMLPurifier_Config object |
|
108 | - */ |
|
109 | - public static function create($config, $schema = null) { |
|
110 | - if ($config instanceof HTMLPurifier_Config) { |
|
111 | - // pass-through |
|
112 | - return $config; |
|
113 | - } |
|
114 | - if (!$schema) { |
|
115 | - $ret = HTMLPurifier_Config::createDefault(); |
|
116 | - } else { |
|
117 | - $ret = new HTMLPurifier_Config($schema); |
|
118 | - } |
|
119 | - if (is_string($config)) $ret->loadIni($config); |
|
120 | - elseif (is_array($config)) $ret->loadArray($config); |
|
121 | - return $ret; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Creates a new config object that inherits from a previous one. |
|
126 | - * @param HTMLPurifier_Config $config Configuration object to inherit |
|
127 | - * from. |
|
128 | - * @return HTMLPurifier_Config object with $config as its parent. |
|
129 | - */ |
|
130 | - public static function inherit(HTMLPurifier_Config $config) { |
|
131 | - return new HTMLPurifier_Config($config->def, $config->plist); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Convenience constructor that creates a default configuration object. |
|
136 | - * @return Default HTMLPurifier_Config object. |
|
137 | - */ |
|
138 | - public static function createDefault() { |
|
139 | - $definition = HTMLPurifier_ConfigSchema::instance(); |
|
140 | - $config = new HTMLPurifier_Config($definition); |
|
141 | - return $config; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Retreives a value from the configuration. |
|
146 | - * @param $key String key |
|
147 | - */ |
|
148 | - public function get($key, $a = null) { |
|
149 | - if ($a !== null) { |
|
150 | - $this->triggerError("Using deprecated API: use \$config->get('$key.$a') instead", E_USER_WARNING); |
|
151 | - $key = "$key.$a"; |
|
152 | - } |
|
153 | - if (!$this->finalized) $this->autoFinalize(); |
|
154 | - if (!isset($this->def->info[$key])) { |
|
155 | - // can't add % due to SimpleTest bug |
|
156 | - $this->triggerError('Cannot retrieve value of undefined directive ' . htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
|
157 | - E_USER_WARNING); |
|
158 | - return; |
|
159 | - } |
|
160 | - if (isset($this->def->info[$key]->isAlias)) { |
|
161 | - $d = $this->def->info[$key]; |
|
162 | - $this->triggerError('Cannot get value from aliased directive, use real name ' . $d->key, |
|
163 | - E_USER_ERROR); |
|
164 | - return; |
|
165 | - } |
|
166 | - if ($this->lock) { |
|
167 | - list($ns) = explode('.', $key); |
|
168 | - if ($ns !== $this->lock) { |
|
169 | - $this->triggerError('Cannot get value of namespace ' . $ns . ' when lock for ' . $this->lock . ' is active, this probably indicates a Definition setup method is accessing directives that are not within its namespace', E_USER_ERROR); |
|
170 | - return; |
|
171 | - } |
|
172 | - } |
|
173 | - return $this->plist->get($key); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Retreives an array of directives to values from a given namespace |
|
178 | - * @param $namespace String namespace |
|
179 | - */ |
|
180 | - public function getBatch($namespace) { |
|
181 | - if (!$this->finalized) $this->autoFinalize(); |
|
182 | - $full = $this->getAll(); |
|
183 | - if (!isset($full[$namespace])) { |
|
184 | - $this->triggerError('Cannot retrieve undefined namespace ' . htmlspecialchars($namespace, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
|
185 | - E_USER_WARNING); |
|
186 | - return; |
|
187 | - } |
|
188 | - return $full[$namespace]; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Returns a md5 signature of a segment of the configuration object |
|
193 | - * that uniquely identifies that particular configuration |
|
194 | - * @note Revision is handled specially and is removed from the batch |
|
195 | - * before processing! |
|
196 | - * @param $namespace Namespace to get serial for |
|
197 | - */ |
|
198 | - public function getBatchSerial($namespace) { |
|
199 | - if (empty($this->serials[$namespace])) { |
|
200 | - $batch = $this->getBatch($namespace); |
|
201 | - unset($batch['DefinitionRev']); |
|
202 | - $this->serials[$namespace] = md5(serialize($batch)); |
|
203 | - } |
|
204 | - return $this->serials[$namespace]; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Returns a md5 signature for the entire configuration object |
|
209 | - * that uniquely identifies that particular configuration |
|
210 | - */ |
|
211 | - public function getSerial() { |
|
212 | - if (empty($this->serial)) { |
|
213 | - $this->serial = md5(serialize($this->getAll())); |
|
214 | - } |
|
215 | - return $this->serial; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Retrieves all directives, organized by namespace |
|
220 | - * @warning This is a pretty inefficient function, avoid if you can |
|
221 | - */ |
|
222 | - public function getAll() { |
|
223 | - if (!$this->finalized) $this->autoFinalize(); |
|
224 | - $ret = array(); |
|
225 | - foreach ($this->plist->squash() as $name => $value) { |
|
226 | - list($ns, $key) = explode('.', $name, 2); |
|
227 | - $ret[$ns][$key] = $value; |
|
228 | - } |
|
229 | - return $ret; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Sets a value to configuration. |
|
234 | - * @param $key String key |
|
235 | - * @param $value Mixed value |
|
236 | - */ |
|
237 | - public function set($key, $value, $a = null) { |
|
238 | - if (strpos($key, '.') === false) { |
|
239 | - $namespace = $key; |
|
240 | - $directive = $value; |
|
241 | - $value = $a; |
|
242 | - $key = "$key.$directive"; |
|
243 | - $this->triggerError("Using deprecated API: use \$config->set('$key', ...) instead", E_USER_NOTICE); |
|
244 | - } else { |
|
245 | - list($namespace) = explode('.', $key); |
|
246 | - } |
|
247 | - if ($this->isFinalized('Cannot set directive after finalization')) return; |
|
248 | - if (!isset($this->def->info[$key])) { |
|
249 | - $this->triggerError('Cannot set undefined directive ' . htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' to value', |
|
250 | - E_USER_WARNING); |
|
251 | - return; |
|
252 | - } |
|
253 | - $def = $this->def->info[$key]; |
|
254 | - |
|
255 | - if (isset($def->isAlias)) { |
|
256 | - if ($this->aliasMode) { |
|
257 | - $this->triggerError('Double-aliases not allowed, please fix '. |
|
258 | - 'ConfigSchema bug with' . $key, E_USER_ERROR); |
|
259 | - return; |
|
260 | - } |
|
261 | - $this->aliasMode = true; |
|
262 | - $this->set($def->key, $value); |
|
263 | - $this->aliasMode = false; |
|
264 | - $this->triggerError("$key is an alias, preferred directive name is {$def->key}", E_USER_NOTICE); |
|
265 | - return; |
|
266 | - } |
|
267 | - |
|
268 | - // Raw type might be negative when using the fully optimized form |
|
269 | - // of stdclass, which indicates allow_null == true |
|
270 | - $rtype = is_int($def) ? $def : $def->type; |
|
271 | - if ($rtype < 0) { |
|
272 | - $type = -$rtype; |
|
273 | - $allow_null = true; |
|
274 | - } else { |
|
275 | - $type = $rtype; |
|
276 | - $allow_null = isset($def->allow_null); |
|
277 | - } |
|
278 | - |
|
279 | - try { |
|
280 | - $value = $this->parser->parse($value, $type, $allow_null); |
|
281 | - } catch (HTMLPurifier_VarParserException $e) { |
|
282 | - $this->triggerError('Value for ' . $key . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING); |
|
283 | - return; |
|
284 | - } |
|
285 | - if (is_string($value) && is_object($def)) { |
|
286 | - // resolve value alias if defined |
|
287 | - if (isset($def->aliases[$value])) { |
|
288 | - $value = $def->aliases[$value]; |
|
289 | - } |
|
290 | - // check to see if the value is allowed |
|
291 | - if (isset($def->allowed) && !isset($def->allowed[$value])) { |
|
292 | - $this->triggerError('Value not supported, valid values are: ' . |
|
293 | - $this->_listify($def->allowed), E_USER_WARNING); |
|
294 | - return; |
|
295 | - } |
|
296 | - } |
|
297 | - $this->plist->set($key, $value); |
|
298 | - |
|
299 | - // reset definitions if the directives they depend on changed |
|
300 | - // this is a very costly process, so it's discouraged |
|
301 | - // with finalization |
|
302 | - if ($namespace == 'HTML' || $namespace == 'CSS' || $namespace == 'URI') { |
|
303 | - $this->definitions[$namespace] = null; |
|
304 | - } |
|
305 | - |
|
306 | - $this->serials[$namespace] = false; |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Convenience function for error reporting |
|
311 | - */ |
|
312 | - private function _listify($lookup) { |
|
313 | - $list = array(); |
|
314 | - foreach ($lookup as $name => $b) $list[] = $name; |
|
315 | - return implode(', ', $list); |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Retrieves object reference to the HTML definition. |
|
320 | - * @param $raw Return a copy that has not been setup yet. Must be |
|
321 | - * called before it's been setup, otherwise won't work. |
|
322 | - * @param $optimized If true, this method may return null, to |
|
323 | - * indicate that a cached version of the modified |
|
324 | - * definition object is available and no further edits |
|
325 | - * are necessary. Consider using |
|
326 | - * maybeGetRawHTMLDefinition, which is more explicitly |
|
327 | - * named, instead. |
|
328 | - */ |
|
329 | - public function getHTMLDefinition($raw = false, $optimized = false) { |
|
330 | - return $this->getDefinition('HTML', $raw, $optimized); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Retrieves object reference to the CSS definition |
|
335 | - * @param $raw Return a copy that has not been setup yet. Must be |
|
336 | - * called before it's been setup, otherwise won't work. |
|
337 | - * @param $optimized If true, this method may return null, to |
|
338 | - * indicate that a cached version of the modified |
|
339 | - * definition object is available and no further edits |
|
340 | - * are necessary. Consider using |
|
341 | - * maybeGetRawCSSDefinition, which is more explicitly |
|
342 | - * named, instead. |
|
343 | - */ |
|
344 | - public function getCSSDefinition($raw = false, $optimized = false) { |
|
345 | - return $this->getDefinition('CSS', $raw, $optimized); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Retrieves object reference to the URI definition |
|
350 | - * @param $raw Return a copy that has not been setup yet. Must be |
|
351 | - * called before it's been setup, otherwise won't work. |
|
352 | - * @param $optimized If true, this method may return null, to |
|
353 | - * indicate that a cached version of the modified |
|
354 | - * definition object is available and no further edits |
|
355 | - * are necessary. Consider using |
|
356 | - * maybeGetRawURIDefinition, which is more explicitly |
|
357 | - * named, instead. |
|
358 | - */ |
|
359 | - public function getURIDefinition($raw = false, $optimized = false) { |
|
360 | - return $this->getDefinition('URI', $raw, $optimized); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Retrieves a definition |
|
365 | - * @param $type Type of definition: HTML, CSS, etc |
|
366 | - * @param $raw Whether or not definition should be returned raw |
|
367 | - * @param $optimized Only has an effect when $raw is true. Whether |
|
368 | - * or not to return null if the result is already present in |
|
369 | - * the cache. This is off by default for backwards |
|
370 | - * compatibility reasons, but you need to do things this |
|
371 | - * way in order to ensure that caching is done properly. |
|
372 | - * Check out enduser-customize.html for more details. |
|
373 | - * We probably won't ever change this default, as much as the |
|
374 | - * maybe semantics is the "right thing to do." |
|
375 | - */ |
|
376 | - public function getDefinition($type, $raw = false, $optimized = false) { |
|
377 | - if ($optimized && !$raw) { |
|
378 | - throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false"); |
|
379 | - } |
|
380 | - if (!$this->finalized) $this->autoFinalize(); |
|
381 | - // temporarily suspend locks, so we can handle recursive definition calls |
|
382 | - $lock = $this->lock; |
|
383 | - $this->lock = null; |
|
384 | - $factory = HTMLPurifier_DefinitionCacheFactory::instance(); |
|
385 | - $cache = $factory->create($type, $this); |
|
386 | - $this->lock = $lock; |
|
387 | - if (!$raw) { |
|
388 | - // full definition |
|
389 | - // --------------- |
|
390 | - // check if definition is in memory |
|
391 | - if (!empty($this->definitions[$type])) { |
|
392 | - $def = $this->definitions[$type]; |
|
393 | - // check if the definition is setup |
|
394 | - if ($def->setup) { |
|
395 | - return $def; |
|
396 | - } else { |
|
397 | - $def->setup($this); |
|
398 | - if ($def->optimized) $cache->add($def, $this); |
|
399 | - return $def; |
|
400 | - } |
|
401 | - } |
|
402 | - // check if definition is in cache |
|
403 | - $def = $cache->get($this); |
|
404 | - if ($def) { |
|
405 | - // definition in cache, save to memory and return it |
|
406 | - $this->definitions[$type] = $def; |
|
407 | - return $def; |
|
408 | - } |
|
409 | - // initialize it |
|
410 | - $def = $this->initDefinition($type); |
|
411 | - // set it up |
|
412 | - $this->lock = $type; |
|
413 | - $def->setup($this); |
|
414 | - $this->lock = null; |
|
415 | - // save in cache |
|
416 | - $cache->add($def, $this); |
|
417 | - // return it |
|
418 | - return $def; |
|
419 | - } else { |
|
420 | - // raw definition |
|
421 | - // -------------- |
|
422 | - // check preconditions |
|
423 | - $def = null; |
|
424 | - if ($optimized) { |
|
425 | - if (is_null($this->get($type . '.DefinitionID'))) { |
|
426 | - // fatally error out if definition ID not set |
|
427 | - throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %$type.DefinitionID"); |
|
428 | - } |
|
429 | - } |
|
430 | - if (!empty($this->definitions[$type])) { |
|
431 | - $def = $this->definitions[$type]; |
|
432 | - if ($def->setup && !$optimized) { |
|
433 | - $extra = $this->chatty ? " (try moving this code block earlier in your initialization)" : ""; |
|
434 | - throw new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup" . $extra); |
|
435 | - } |
|
436 | - if ($def->optimized === null) { |
|
437 | - $extra = $this->chatty ? " (try flushing your cache)" : ""; |
|
438 | - throw new HTMLPurifier_Exception("Optimization status of definition is unknown" . $extra); |
|
439 | - } |
|
440 | - if ($def->optimized !== $optimized) { |
|
441 | - $msg = $optimized ? "optimized" : "unoptimized"; |
|
442 | - $extra = $this->chatty ? " (this backtrace is for the first inconsistent call, which was for a $msg raw definition)" : ""; |
|
443 | - throw new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra); |
|
444 | - } |
|
445 | - } |
|
446 | - // check if definition was in memory |
|
447 | - if ($def) { |
|
448 | - if ($def->setup) { |
|
449 | - // invariant: $optimized === true (checked above) |
|
450 | - return null; |
|
451 | - } else { |
|
452 | - return $def; |
|
453 | - } |
|
454 | - } |
|
455 | - // if optimized, check if definition was in cache |
|
456 | - // (because we do the memory check first, this formulation |
|
457 | - // is prone to cache slamming, but I think |
|
458 | - // guaranteeing that either /all/ of the raw |
|
459 | - // setup code or /none/ of it is run is more important.) |
|
460 | - if ($optimized) { |
|
461 | - // This code path only gets run once; once we put |
|
462 | - // something in $definitions (which is guaranteed by the |
|
463 | - // trailing code), we always short-circuit above. |
|
464 | - $def = $cache->get($this); |
|
465 | - if ($def) { |
|
466 | - // save the full definition for later, but don't |
|
467 | - // return it yet |
|
468 | - $this->definitions[$type] = $def; |
|
469 | - return null; |
|
470 | - } |
|
471 | - } |
|
472 | - // check invariants for creation |
|
473 | - if (!$optimized) { |
|
474 | - if (!is_null($this->get($type . '.DefinitionID'))) { |
|
475 | - if ($this->chatty) { |
|
476 | - $this->triggerError("Due to a documentation error in previous version of HTML Purifier, your definitions are not being cached. If this is OK, you can remove the %$type.DefinitionRev and %$type.DefinitionID declaration. Otherwise, modify your code to use maybeGetRawDefinition, and test if the returned value is null before making any edits (if it is null, that means that a cached version is available, and no raw operations are necessary). See <a href='http://htmlpurifier.org/docs/enduser-customize.html#optimized'>Customize</a> for more details", E_USER_WARNING); |
|
477 | - } else { |
|
478 | - $this->triggerError("Useless DefinitionID declaration", E_USER_WARNING); |
|
479 | - } |
|
480 | - } |
|
481 | - } |
|
482 | - // initialize it |
|
483 | - $def = $this->initDefinition($type); |
|
484 | - $def->optimized = $optimized; |
|
485 | - return $def; |
|
486 | - } |
|
487 | - throw new HTMLPurifier_Exception("The impossible happened!"); |
|
488 | - } |
|
489 | - |
|
490 | - private function initDefinition($type) { |
|
491 | - // quick checks failed, let's create the object |
|
492 | - if ($type == 'HTML') { |
|
493 | - $def = new HTMLPurifier_HTMLDefinition(); |
|
494 | - } elseif ($type == 'CSS') { |
|
495 | - $def = new HTMLPurifier_CSSDefinition(); |
|
496 | - } elseif ($type == 'URI') { |
|
497 | - $def = new HTMLPurifier_URIDefinition(); |
|
498 | - } else { |
|
499 | - throw new HTMLPurifier_Exception("Definition of $type type not supported"); |
|
500 | - } |
|
501 | - $this->definitions[$type] = $def; |
|
502 | - return $def; |
|
503 | - } |
|
504 | - |
|
505 | - public function maybeGetRawDefinition($name) { |
|
506 | - return $this->getDefinition($name, true, true); |
|
507 | - } |
|
508 | - |
|
509 | - public function maybeGetRawHTMLDefinition() { |
|
510 | - return $this->getDefinition('HTML', true, true); |
|
511 | - } |
|
512 | - |
|
513 | - public function maybeGetRawCSSDefinition() { |
|
514 | - return $this->getDefinition('CSS', true, true); |
|
515 | - } |
|
516 | - |
|
517 | - public function maybeGetRawURIDefinition() { |
|
518 | - return $this->getDefinition('URI', true, true); |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * Loads configuration values from an array with the following structure: |
|
523 | - * Namespace.Directive => Value |
|
524 | - * @param $config_array Configuration associative array |
|
525 | - */ |
|
526 | - public function loadArray($config_array) { |
|
527 | - if ($this->isFinalized('Cannot load directives after finalization')) return; |
|
528 | - foreach ($config_array as $key => $value) { |
|
529 | - $key = str_replace('_', '.', $key); |
|
530 | - if (strpos($key, '.') !== false) { |
|
531 | - $this->set($key, $value); |
|
532 | - } else { |
|
533 | - $namespace = $key; |
|
534 | - $namespace_values = $value; |
|
535 | - foreach ($namespace_values as $directive => $value) { |
|
536 | - $this->set($namespace .'.'. $directive, $value); |
|
537 | - } |
|
538 | - } |
|
539 | - } |
|
540 | - } |
|
541 | - |
|
542 | - /** |
|
543 | - * Returns a list of array(namespace, directive) for all directives |
|
544 | - * that are allowed in a web-form context as per an allowed |
|
545 | - * namespaces/directives list. |
|
546 | - * @param $allowed List of allowed namespaces/directives |
|
547 | - */ |
|
548 | - public static function getAllowedDirectivesForForm($allowed, $schema = null) { |
|
549 | - if (!$schema) { |
|
550 | - $schema = HTMLPurifier_ConfigSchema::instance(); |
|
551 | - } |
|
552 | - if ($allowed !== true) { |
|
553 | - if (is_string($allowed)) $allowed = array($allowed); |
|
554 | - $allowed_ns = array(); |
|
555 | - $allowed_directives = array(); |
|
556 | - $blacklisted_directives = array(); |
|
557 | - foreach ($allowed as $ns_or_directive) { |
|
558 | - if (strpos($ns_or_directive, '.') !== false) { |
|
559 | - // directive |
|
560 | - if ($ns_or_directive[0] == '-') { |
|
561 | - $blacklisted_directives[substr($ns_or_directive, 1)] = true; |
|
562 | - } else { |
|
563 | - $allowed_directives[$ns_or_directive] = true; |
|
564 | - } |
|
565 | - } else { |
|
566 | - // namespace |
|
567 | - $allowed_ns[$ns_or_directive] = true; |
|
568 | - } |
|
569 | - } |
|
570 | - } |
|
571 | - $ret = array(); |
|
572 | - foreach ($schema->info as $key => $def) { |
|
573 | - list($ns, $directive) = explode('.', $key, 2); |
|
574 | - if ($allowed !== true) { |
|
575 | - if (isset($blacklisted_directives["$ns.$directive"])) continue; |
|
576 | - if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) continue; |
|
577 | - } |
|
578 | - if (isset($def->isAlias)) continue; |
|
579 | - if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') continue; |
|
580 | - $ret[] = array($ns, $directive); |
|
581 | - } |
|
582 | - return $ret; |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Loads configuration values from $_GET/$_POST that were posted |
|
587 | - * via ConfigForm |
|
588 | - * @param $array $_GET or $_POST array to import |
|
589 | - * @param $index Index/name that the config variables are in |
|
590 | - * @param $allowed List of allowed namespaces/directives |
|
591 | - * @param $mq_fix Boolean whether or not to enable magic quotes fix |
|
592 | - * @param $schema Instance of HTMLPurifier_ConfigSchema to use, if not global copy |
|
593 | - */ |
|
594 | - public static function loadArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) { |
|
595 | - $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $schema); |
|
596 | - $config = HTMLPurifier_Config::create($ret, $schema); |
|
597 | - return $config; |
|
598 | - } |
|
599 | - |
|
600 | - /** |
|
601 | - * Merges in configuration values from $_GET/$_POST to object. NOT STATIC. |
|
602 | - * @note Same parameters as loadArrayFromForm |
|
603 | - */ |
|
604 | - public function mergeArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true) { |
|
605 | - $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $this->def); |
|
606 | - $this->loadArray($ret); |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Prepares an array from a form into something usable for the more |
|
611 | - * strict parts of HTMLPurifier_Config |
|
612 | - */ |
|
613 | - public static function prepareArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) { |
|
614 | - if ($index !== false) $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array(); |
|
615 | - $mq = $mq_fix && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc(); |
|
616 | - |
|
617 | - $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $schema); |
|
618 | - $ret = array(); |
|
619 | - foreach ($allowed as $key) { |
|
620 | - list($ns, $directive) = $key; |
|
621 | - $skey = "$ns.$directive"; |
|
622 | - if (!empty($array["Null_$skey"])) { |
|
623 | - $ret[$ns][$directive] = null; |
|
624 | - continue; |
|
625 | - } |
|
626 | - if (!isset($array[$skey])) continue; |
|
627 | - $value = $mq ? stripslashes($array[$skey]) : $array[$skey]; |
|
628 | - $ret[$ns][$directive] = $value; |
|
629 | - } |
|
630 | - return $ret; |
|
631 | - } |
|
632 | - |
|
633 | - /** |
|
634 | - * Loads configuration values from an ini file |
|
635 | - * @param $filename Name of ini file |
|
636 | - */ |
|
637 | - public function loadIni($filename) { |
|
638 | - if ($this->isFinalized('Cannot load directives after finalization')) return; |
|
639 | - $array = parse_ini_file($filename, true); |
|
640 | - $this->loadArray($array); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Checks whether or not the configuration object is finalized. |
|
645 | - * @param $error String error message, or false for no error |
|
646 | - */ |
|
647 | - public function isFinalized($error = false) { |
|
648 | - if ($this->finalized && $error) { |
|
649 | - $this->triggerError($error, E_USER_ERROR); |
|
650 | - } |
|
651 | - return $this->finalized; |
|
652 | - } |
|
653 | - |
|
654 | - /** |
|
655 | - * Finalizes configuration only if auto finalize is on and not |
|
656 | - * already finalized |
|
657 | - */ |
|
658 | - public function autoFinalize() { |
|
659 | - if ($this->autoFinalize) { |
|
660 | - $this->finalize(); |
|
661 | - } else { |
|
662 | - $this->plist->squash(true); |
|
663 | - } |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * Finalizes a configuration object, prohibiting further change |
|
668 | - */ |
|
669 | - public function finalize() { |
|
670 | - $this->finalized = true; |
|
671 | - $this->parser = null; |
|
672 | - } |
|
673 | - |
|
674 | - /** |
|
675 | - * Produces a nicely formatted error message by supplying the |
|
676 | - * stack frame information OUTSIDE of HTMLPurifier_Config. |
|
677 | - */ |
|
678 | - protected function triggerError($msg, $no) { |
|
679 | - // determine previous stack frame |
|
680 | - $extra = ''; |
|
681 | - if ($this->chatty) { |
|
682 | - $trace = debug_backtrace(); |
|
683 | - // zip(tail(trace), trace) -- but PHP is not Haskell har har |
|
684 | - for ($i = 0, $c = count($trace); $i < $c - 1; $i++) { |
|
685 | - if ($trace[$i + 1]['class'] === 'HTMLPurifier_Config') { |
|
686 | - continue; |
|
687 | - } |
|
688 | - $frame = $trace[$i]; |
|
689 | - $extra = " invoked on line {$frame['line']} in file {$frame['file']}"; |
|
690 | - break; |
|
691 | - } |
|
692 | - } |
|
693 | - trigger_error($msg . $extra, $no); |
|
694 | - } |
|
695 | - |
|
696 | - /** |
|
697 | - * Returns a serialized form of the configuration object that can |
|
698 | - * be reconstituted. |
|
699 | - */ |
|
700 | - public function serialize() { |
|
701 | - $this->getDefinition('HTML'); |
|
702 | - $this->getDefinition('CSS'); |
|
703 | - $this->getDefinition('URI'); |
|
704 | - return serialize($this); |
|
705 | - } |
|
20 | + /** |
|
21 | + * HTML Purifier's version |
|
22 | + */ |
|
23 | + public $version = '4.4.0'; |
|
24 | + |
|
25 | + /** |
|
26 | + * Bool indicator whether or not to automatically finalize |
|
27 | + * the object if a read operation is done |
|
28 | + */ |
|
29 | + public $autoFinalize = true; |
|
30 | + |
|
31 | + // protected member variables |
|
32 | + |
|
33 | + /** |
|
34 | + * Namespace indexed array of serials for specific namespaces (see |
|
35 | + * getSerial() for more info). |
|
36 | + */ |
|
37 | + protected $serials = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * Serial for entire configuration object |
|
41 | + */ |
|
42 | + protected $serial; |
|
43 | + |
|
44 | + /** |
|
45 | + * Parser for variables |
|
46 | + */ |
|
47 | + protected $parser = null; |
|
48 | + |
|
49 | + /** |
|
50 | + * Reference HTMLPurifier_ConfigSchema for value checking |
|
51 | + * @note This is public for introspective purposes. Please don't |
|
52 | + * abuse! |
|
53 | + */ |
|
54 | + public $def; |
|
55 | + |
|
56 | + /** |
|
57 | + * Indexed array of definitions |
|
58 | + */ |
|
59 | + protected $definitions; |
|
60 | + |
|
61 | + /** |
|
62 | + * Bool indicator whether or not config is finalized |
|
63 | + */ |
|
64 | + protected $finalized = false; |
|
65 | + |
|
66 | + /** |
|
67 | + * Property list containing configuration directives. |
|
68 | + */ |
|
69 | + protected $plist; |
|
70 | + |
|
71 | + /** |
|
72 | + * Whether or not a set is taking place due to an |
|
73 | + * alias lookup. |
|
74 | + */ |
|
75 | + private $aliasMode; |
|
76 | + |
|
77 | + /** |
|
78 | + * Set to false if you do not want line and file numbers in errors |
|
79 | + * (useful when unit testing). This will also compress some errors |
|
80 | + * and exceptions. |
|
81 | + */ |
|
82 | + public $chatty = true; |
|
83 | + |
|
84 | + /** |
|
85 | + * Current lock; only gets to this namespace are allowed. |
|
86 | + */ |
|
87 | + private $lock; |
|
88 | + |
|
89 | + /** |
|
90 | + * @param $definition HTMLPurifier_ConfigSchema that defines what directives |
|
91 | + * are allowed. |
|
92 | + */ |
|
93 | + public function __construct($definition, $parent = null) { |
|
94 | + $parent = $parent ? $parent : $definition->defaultPlist; |
|
95 | + $this->plist = new HTMLPurifier_PropertyList($parent); |
|
96 | + $this->def = $definition; // keep a copy around for checking |
|
97 | + $this->parser = new HTMLPurifier_VarParser_Flexible(); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Convenience constructor that creates a config object based on a mixed var |
|
102 | + * @param mixed $config Variable that defines the state of the config |
|
103 | + * object. Can be: a HTMLPurifier_Config() object, |
|
104 | + * an array of directives based on loadArray(), |
|
105 | + * or a string filename of an ini file. |
|
106 | + * @param HTMLPurifier_ConfigSchema Schema object |
|
107 | + * @return Configured HTMLPurifier_Config object |
|
108 | + */ |
|
109 | + public static function create($config, $schema = null) { |
|
110 | + if ($config instanceof HTMLPurifier_Config) { |
|
111 | + // pass-through |
|
112 | + return $config; |
|
113 | + } |
|
114 | + if (!$schema) { |
|
115 | + $ret = HTMLPurifier_Config::createDefault(); |
|
116 | + } else { |
|
117 | + $ret = new HTMLPurifier_Config($schema); |
|
118 | + } |
|
119 | + if (is_string($config)) $ret->loadIni($config); |
|
120 | + elseif (is_array($config)) $ret->loadArray($config); |
|
121 | + return $ret; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Creates a new config object that inherits from a previous one. |
|
126 | + * @param HTMLPurifier_Config $config Configuration object to inherit |
|
127 | + * from. |
|
128 | + * @return HTMLPurifier_Config object with $config as its parent. |
|
129 | + */ |
|
130 | + public static function inherit(HTMLPurifier_Config $config) { |
|
131 | + return new HTMLPurifier_Config($config->def, $config->plist); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Convenience constructor that creates a default configuration object. |
|
136 | + * @return Default HTMLPurifier_Config object. |
|
137 | + */ |
|
138 | + public static function createDefault() { |
|
139 | + $definition = HTMLPurifier_ConfigSchema::instance(); |
|
140 | + $config = new HTMLPurifier_Config($definition); |
|
141 | + return $config; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Retreives a value from the configuration. |
|
146 | + * @param $key String key |
|
147 | + */ |
|
148 | + public function get($key, $a = null) { |
|
149 | + if ($a !== null) { |
|
150 | + $this->triggerError("Using deprecated API: use \$config->get('$key.$a') instead", E_USER_WARNING); |
|
151 | + $key = "$key.$a"; |
|
152 | + } |
|
153 | + if (!$this->finalized) $this->autoFinalize(); |
|
154 | + if (!isset($this->def->info[$key])) { |
|
155 | + // can't add % due to SimpleTest bug |
|
156 | + $this->triggerError('Cannot retrieve value of undefined directive ' . htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
|
157 | + E_USER_WARNING); |
|
158 | + return; |
|
159 | + } |
|
160 | + if (isset($this->def->info[$key]->isAlias)) { |
|
161 | + $d = $this->def->info[$key]; |
|
162 | + $this->triggerError('Cannot get value from aliased directive, use real name ' . $d->key, |
|
163 | + E_USER_ERROR); |
|
164 | + return; |
|
165 | + } |
|
166 | + if ($this->lock) { |
|
167 | + list($ns) = explode('.', $key); |
|
168 | + if ($ns !== $this->lock) { |
|
169 | + $this->triggerError('Cannot get value of namespace ' . $ns . ' when lock for ' . $this->lock . ' is active, this probably indicates a Definition setup method is accessing directives that are not within its namespace', E_USER_ERROR); |
|
170 | + return; |
|
171 | + } |
|
172 | + } |
|
173 | + return $this->plist->get($key); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Retreives an array of directives to values from a given namespace |
|
178 | + * @param $namespace String namespace |
|
179 | + */ |
|
180 | + public function getBatch($namespace) { |
|
181 | + if (!$this->finalized) $this->autoFinalize(); |
|
182 | + $full = $this->getAll(); |
|
183 | + if (!isset($full[$namespace])) { |
|
184 | + $this->triggerError('Cannot retrieve undefined namespace ' . htmlspecialchars($namespace, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
|
185 | + E_USER_WARNING); |
|
186 | + return; |
|
187 | + } |
|
188 | + return $full[$namespace]; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Returns a md5 signature of a segment of the configuration object |
|
193 | + * that uniquely identifies that particular configuration |
|
194 | + * @note Revision is handled specially and is removed from the batch |
|
195 | + * before processing! |
|
196 | + * @param $namespace Namespace to get serial for |
|
197 | + */ |
|
198 | + public function getBatchSerial($namespace) { |
|
199 | + if (empty($this->serials[$namespace])) { |
|
200 | + $batch = $this->getBatch($namespace); |
|
201 | + unset($batch['DefinitionRev']); |
|
202 | + $this->serials[$namespace] = md5(serialize($batch)); |
|
203 | + } |
|
204 | + return $this->serials[$namespace]; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Returns a md5 signature for the entire configuration object |
|
209 | + * that uniquely identifies that particular configuration |
|
210 | + */ |
|
211 | + public function getSerial() { |
|
212 | + if (empty($this->serial)) { |
|
213 | + $this->serial = md5(serialize($this->getAll())); |
|
214 | + } |
|
215 | + return $this->serial; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Retrieves all directives, organized by namespace |
|
220 | + * @warning This is a pretty inefficient function, avoid if you can |
|
221 | + */ |
|
222 | + public function getAll() { |
|
223 | + if (!$this->finalized) $this->autoFinalize(); |
|
224 | + $ret = array(); |
|
225 | + foreach ($this->plist->squash() as $name => $value) { |
|
226 | + list($ns, $key) = explode('.', $name, 2); |
|
227 | + $ret[$ns][$key] = $value; |
|
228 | + } |
|
229 | + return $ret; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Sets a value to configuration. |
|
234 | + * @param $key String key |
|
235 | + * @param $value Mixed value |
|
236 | + */ |
|
237 | + public function set($key, $value, $a = null) { |
|
238 | + if (strpos($key, '.') === false) { |
|
239 | + $namespace = $key; |
|
240 | + $directive = $value; |
|
241 | + $value = $a; |
|
242 | + $key = "$key.$directive"; |
|
243 | + $this->triggerError("Using deprecated API: use \$config->set('$key', ...) instead", E_USER_NOTICE); |
|
244 | + } else { |
|
245 | + list($namespace) = explode('.', $key); |
|
246 | + } |
|
247 | + if ($this->isFinalized('Cannot set directive after finalization')) return; |
|
248 | + if (!isset($this->def->info[$key])) { |
|
249 | + $this->triggerError('Cannot set undefined directive ' . htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' to value', |
|
250 | + E_USER_WARNING); |
|
251 | + return; |
|
252 | + } |
|
253 | + $def = $this->def->info[$key]; |
|
254 | + |
|
255 | + if (isset($def->isAlias)) { |
|
256 | + if ($this->aliasMode) { |
|
257 | + $this->triggerError('Double-aliases not allowed, please fix '. |
|
258 | + 'ConfigSchema bug with' . $key, E_USER_ERROR); |
|
259 | + return; |
|
260 | + } |
|
261 | + $this->aliasMode = true; |
|
262 | + $this->set($def->key, $value); |
|
263 | + $this->aliasMode = false; |
|
264 | + $this->triggerError("$key is an alias, preferred directive name is {$def->key}", E_USER_NOTICE); |
|
265 | + return; |
|
266 | + } |
|
267 | + |
|
268 | + // Raw type might be negative when using the fully optimized form |
|
269 | + // of stdclass, which indicates allow_null == true |
|
270 | + $rtype = is_int($def) ? $def : $def->type; |
|
271 | + if ($rtype < 0) { |
|
272 | + $type = -$rtype; |
|
273 | + $allow_null = true; |
|
274 | + } else { |
|
275 | + $type = $rtype; |
|
276 | + $allow_null = isset($def->allow_null); |
|
277 | + } |
|
278 | + |
|
279 | + try { |
|
280 | + $value = $this->parser->parse($value, $type, $allow_null); |
|
281 | + } catch (HTMLPurifier_VarParserException $e) { |
|
282 | + $this->triggerError('Value for ' . $key . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING); |
|
283 | + return; |
|
284 | + } |
|
285 | + if (is_string($value) && is_object($def)) { |
|
286 | + // resolve value alias if defined |
|
287 | + if (isset($def->aliases[$value])) { |
|
288 | + $value = $def->aliases[$value]; |
|
289 | + } |
|
290 | + // check to see if the value is allowed |
|
291 | + if (isset($def->allowed) && !isset($def->allowed[$value])) { |
|
292 | + $this->triggerError('Value not supported, valid values are: ' . |
|
293 | + $this->_listify($def->allowed), E_USER_WARNING); |
|
294 | + return; |
|
295 | + } |
|
296 | + } |
|
297 | + $this->plist->set($key, $value); |
|
298 | + |
|
299 | + // reset definitions if the directives they depend on changed |
|
300 | + // this is a very costly process, so it's discouraged |
|
301 | + // with finalization |
|
302 | + if ($namespace == 'HTML' || $namespace == 'CSS' || $namespace == 'URI') { |
|
303 | + $this->definitions[$namespace] = null; |
|
304 | + } |
|
305 | + |
|
306 | + $this->serials[$namespace] = false; |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Convenience function for error reporting |
|
311 | + */ |
|
312 | + private function _listify($lookup) { |
|
313 | + $list = array(); |
|
314 | + foreach ($lookup as $name => $b) $list[] = $name; |
|
315 | + return implode(', ', $list); |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Retrieves object reference to the HTML definition. |
|
320 | + * @param $raw Return a copy that has not been setup yet. Must be |
|
321 | + * called before it's been setup, otherwise won't work. |
|
322 | + * @param $optimized If true, this method may return null, to |
|
323 | + * indicate that a cached version of the modified |
|
324 | + * definition object is available and no further edits |
|
325 | + * are necessary. Consider using |
|
326 | + * maybeGetRawHTMLDefinition, which is more explicitly |
|
327 | + * named, instead. |
|
328 | + */ |
|
329 | + public function getHTMLDefinition($raw = false, $optimized = false) { |
|
330 | + return $this->getDefinition('HTML', $raw, $optimized); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Retrieves object reference to the CSS definition |
|
335 | + * @param $raw Return a copy that has not been setup yet. Must be |
|
336 | + * called before it's been setup, otherwise won't work. |
|
337 | + * @param $optimized If true, this method may return null, to |
|
338 | + * indicate that a cached version of the modified |
|
339 | + * definition object is available and no further edits |
|
340 | + * are necessary. Consider using |
|
341 | + * maybeGetRawCSSDefinition, which is more explicitly |
|
342 | + * named, instead. |
|
343 | + */ |
|
344 | + public function getCSSDefinition($raw = false, $optimized = false) { |
|
345 | + return $this->getDefinition('CSS', $raw, $optimized); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Retrieves object reference to the URI definition |
|
350 | + * @param $raw Return a copy that has not been setup yet. Must be |
|
351 | + * called before it's been setup, otherwise won't work. |
|
352 | + * @param $optimized If true, this method may return null, to |
|
353 | + * indicate that a cached version of the modified |
|
354 | + * definition object is available and no further edits |
|
355 | + * are necessary. Consider using |
|
356 | + * maybeGetRawURIDefinition, which is more explicitly |
|
357 | + * named, instead. |
|
358 | + */ |
|
359 | + public function getURIDefinition($raw = false, $optimized = false) { |
|
360 | + return $this->getDefinition('URI', $raw, $optimized); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Retrieves a definition |
|
365 | + * @param $type Type of definition: HTML, CSS, etc |
|
366 | + * @param $raw Whether or not definition should be returned raw |
|
367 | + * @param $optimized Only has an effect when $raw is true. Whether |
|
368 | + * or not to return null if the result is already present in |
|
369 | + * the cache. This is off by default for backwards |
|
370 | + * compatibility reasons, but you need to do things this |
|
371 | + * way in order to ensure that caching is done properly. |
|
372 | + * Check out enduser-customize.html for more details. |
|
373 | + * We probably won't ever change this default, as much as the |
|
374 | + * maybe semantics is the "right thing to do." |
|
375 | + */ |
|
376 | + public function getDefinition($type, $raw = false, $optimized = false) { |
|
377 | + if ($optimized && !$raw) { |
|
378 | + throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false"); |
|
379 | + } |
|
380 | + if (!$this->finalized) $this->autoFinalize(); |
|
381 | + // temporarily suspend locks, so we can handle recursive definition calls |
|
382 | + $lock = $this->lock; |
|
383 | + $this->lock = null; |
|
384 | + $factory = HTMLPurifier_DefinitionCacheFactory::instance(); |
|
385 | + $cache = $factory->create($type, $this); |
|
386 | + $this->lock = $lock; |
|
387 | + if (!$raw) { |
|
388 | + // full definition |
|
389 | + // --------------- |
|
390 | + // check if definition is in memory |
|
391 | + if (!empty($this->definitions[$type])) { |
|
392 | + $def = $this->definitions[$type]; |
|
393 | + // check if the definition is setup |
|
394 | + if ($def->setup) { |
|
395 | + return $def; |
|
396 | + } else { |
|
397 | + $def->setup($this); |
|
398 | + if ($def->optimized) $cache->add($def, $this); |
|
399 | + return $def; |
|
400 | + } |
|
401 | + } |
|
402 | + // check if definition is in cache |
|
403 | + $def = $cache->get($this); |
|
404 | + if ($def) { |
|
405 | + // definition in cache, save to memory and return it |
|
406 | + $this->definitions[$type] = $def; |
|
407 | + return $def; |
|
408 | + } |
|
409 | + // initialize it |
|
410 | + $def = $this->initDefinition($type); |
|
411 | + // set it up |
|
412 | + $this->lock = $type; |
|
413 | + $def->setup($this); |
|
414 | + $this->lock = null; |
|
415 | + // save in cache |
|
416 | + $cache->add($def, $this); |
|
417 | + // return it |
|
418 | + return $def; |
|
419 | + } else { |
|
420 | + // raw definition |
|
421 | + // -------------- |
|
422 | + // check preconditions |
|
423 | + $def = null; |
|
424 | + if ($optimized) { |
|
425 | + if (is_null($this->get($type . '.DefinitionID'))) { |
|
426 | + // fatally error out if definition ID not set |
|
427 | + throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %$type.DefinitionID"); |
|
428 | + } |
|
429 | + } |
|
430 | + if (!empty($this->definitions[$type])) { |
|
431 | + $def = $this->definitions[$type]; |
|
432 | + if ($def->setup && !$optimized) { |
|
433 | + $extra = $this->chatty ? " (try moving this code block earlier in your initialization)" : ""; |
|
434 | + throw new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup" . $extra); |
|
435 | + } |
|
436 | + if ($def->optimized === null) { |
|
437 | + $extra = $this->chatty ? " (try flushing your cache)" : ""; |
|
438 | + throw new HTMLPurifier_Exception("Optimization status of definition is unknown" . $extra); |
|
439 | + } |
|
440 | + if ($def->optimized !== $optimized) { |
|
441 | + $msg = $optimized ? "optimized" : "unoptimized"; |
|
442 | + $extra = $this->chatty ? " (this backtrace is for the first inconsistent call, which was for a $msg raw definition)" : ""; |
|
443 | + throw new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra); |
|
444 | + } |
|
445 | + } |
|
446 | + // check if definition was in memory |
|
447 | + if ($def) { |
|
448 | + if ($def->setup) { |
|
449 | + // invariant: $optimized === true (checked above) |
|
450 | + return null; |
|
451 | + } else { |
|
452 | + return $def; |
|
453 | + } |
|
454 | + } |
|
455 | + // if optimized, check if definition was in cache |
|
456 | + // (because we do the memory check first, this formulation |
|
457 | + // is prone to cache slamming, but I think |
|
458 | + // guaranteeing that either /all/ of the raw |
|
459 | + // setup code or /none/ of it is run is more important.) |
|
460 | + if ($optimized) { |
|
461 | + // This code path only gets run once; once we put |
|
462 | + // something in $definitions (which is guaranteed by the |
|
463 | + // trailing code), we always short-circuit above. |
|
464 | + $def = $cache->get($this); |
|
465 | + if ($def) { |
|
466 | + // save the full definition for later, but don't |
|
467 | + // return it yet |
|
468 | + $this->definitions[$type] = $def; |
|
469 | + return null; |
|
470 | + } |
|
471 | + } |
|
472 | + // check invariants for creation |
|
473 | + if (!$optimized) { |
|
474 | + if (!is_null($this->get($type . '.DefinitionID'))) { |
|
475 | + if ($this->chatty) { |
|
476 | + $this->triggerError("Due to a documentation error in previous version of HTML Purifier, your definitions are not being cached. If this is OK, you can remove the %$type.DefinitionRev and %$type.DefinitionID declaration. Otherwise, modify your code to use maybeGetRawDefinition, and test if the returned value is null before making any edits (if it is null, that means that a cached version is available, and no raw operations are necessary). See <a href='http://htmlpurifier.org/docs/enduser-customize.html#optimized'>Customize</a> for more details", E_USER_WARNING); |
|
477 | + } else { |
|
478 | + $this->triggerError("Useless DefinitionID declaration", E_USER_WARNING); |
|
479 | + } |
|
480 | + } |
|
481 | + } |
|
482 | + // initialize it |
|
483 | + $def = $this->initDefinition($type); |
|
484 | + $def->optimized = $optimized; |
|
485 | + return $def; |
|
486 | + } |
|
487 | + throw new HTMLPurifier_Exception("The impossible happened!"); |
|
488 | + } |
|
489 | + |
|
490 | + private function initDefinition($type) { |
|
491 | + // quick checks failed, let's create the object |
|
492 | + if ($type == 'HTML') { |
|
493 | + $def = new HTMLPurifier_HTMLDefinition(); |
|
494 | + } elseif ($type == 'CSS') { |
|
495 | + $def = new HTMLPurifier_CSSDefinition(); |
|
496 | + } elseif ($type == 'URI') { |
|
497 | + $def = new HTMLPurifier_URIDefinition(); |
|
498 | + } else { |
|
499 | + throw new HTMLPurifier_Exception("Definition of $type type not supported"); |
|
500 | + } |
|
501 | + $this->definitions[$type] = $def; |
|
502 | + return $def; |
|
503 | + } |
|
504 | + |
|
505 | + public function maybeGetRawDefinition($name) { |
|
506 | + return $this->getDefinition($name, true, true); |
|
507 | + } |
|
508 | + |
|
509 | + public function maybeGetRawHTMLDefinition() { |
|
510 | + return $this->getDefinition('HTML', true, true); |
|
511 | + } |
|
512 | + |
|
513 | + public function maybeGetRawCSSDefinition() { |
|
514 | + return $this->getDefinition('CSS', true, true); |
|
515 | + } |
|
516 | + |
|
517 | + public function maybeGetRawURIDefinition() { |
|
518 | + return $this->getDefinition('URI', true, true); |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * Loads configuration values from an array with the following structure: |
|
523 | + * Namespace.Directive => Value |
|
524 | + * @param $config_array Configuration associative array |
|
525 | + */ |
|
526 | + public function loadArray($config_array) { |
|
527 | + if ($this->isFinalized('Cannot load directives after finalization')) return; |
|
528 | + foreach ($config_array as $key => $value) { |
|
529 | + $key = str_replace('_', '.', $key); |
|
530 | + if (strpos($key, '.') !== false) { |
|
531 | + $this->set($key, $value); |
|
532 | + } else { |
|
533 | + $namespace = $key; |
|
534 | + $namespace_values = $value; |
|
535 | + foreach ($namespace_values as $directive => $value) { |
|
536 | + $this->set($namespace .'.'. $directive, $value); |
|
537 | + } |
|
538 | + } |
|
539 | + } |
|
540 | + } |
|
541 | + |
|
542 | + /** |
|
543 | + * Returns a list of array(namespace, directive) for all directives |
|
544 | + * that are allowed in a web-form context as per an allowed |
|
545 | + * namespaces/directives list. |
|
546 | + * @param $allowed List of allowed namespaces/directives |
|
547 | + */ |
|
548 | + public static function getAllowedDirectivesForForm($allowed, $schema = null) { |
|
549 | + if (!$schema) { |
|
550 | + $schema = HTMLPurifier_ConfigSchema::instance(); |
|
551 | + } |
|
552 | + if ($allowed !== true) { |
|
553 | + if (is_string($allowed)) $allowed = array($allowed); |
|
554 | + $allowed_ns = array(); |
|
555 | + $allowed_directives = array(); |
|
556 | + $blacklisted_directives = array(); |
|
557 | + foreach ($allowed as $ns_or_directive) { |
|
558 | + if (strpos($ns_or_directive, '.') !== false) { |
|
559 | + // directive |
|
560 | + if ($ns_or_directive[0] == '-') { |
|
561 | + $blacklisted_directives[substr($ns_or_directive, 1)] = true; |
|
562 | + } else { |
|
563 | + $allowed_directives[$ns_or_directive] = true; |
|
564 | + } |
|
565 | + } else { |
|
566 | + // namespace |
|
567 | + $allowed_ns[$ns_or_directive] = true; |
|
568 | + } |
|
569 | + } |
|
570 | + } |
|
571 | + $ret = array(); |
|
572 | + foreach ($schema->info as $key => $def) { |
|
573 | + list($ns, $directive) = explode('.', $key, 2); |
|
574 | + if ($allowed !== true) { |
|
575 | + if (isset($blacklisted_directives["$ns.$directive"])) continue; |
|
576 | + if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) continue; |
|
577 | + } |
|
578 | + if (isset($def->isAlias)) continue; |
|
579 | + if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') continue; |
|
580 | + $ret[] = array($ns, $directive); |
|
581 | + } |
|
582 | + return $ret; |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Loads configuration values from $_GET/$_POST that were posted |
|
587 | + * via ConfigForm |
|
588 | + * @param $array $_GET or $_POST array to import |
|
589 | + * @param $index Index/name that the config variables are in |
|
590 | + * @param $allowed List of allowed namespaces/directives |
|
591 | + * @param $mq_fix Boolean whether or not to enable magic quotes fix |
|
592 | + * @param $schema Instance of HTMLPurifier_ConfigSchema to use, if not global copy |
|
593 | + */ |
|
594 | + public static function loadArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) { |
|
595 | + $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $schema); |
|
596 | + $config = HTMLPurifier_Config::create($ret, $schema); |
|
597 | + return $config; |
|
598 | + } |
|
599 | + |
|
600 | + /** |
|
601 | + * Merges in configuration values from $_GET/$_POST to object. NOT STATIC. |
|
602 | + * @note Same parameters as loadArrayFromForm |
|
603 | + */ |
|
604 | + public function mergeArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true) { |
|
605 | + $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $this->def); |
|
606 | + $this->loadArray($ret); |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Prepares an array from a form into something usable for the more |
|
611 | + * strict parts of HTMLPurifier_Config |
|
612 | + */ |
|
613 | + public static function prepareArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) { |
|
614 | + if ($index !== false) $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array(); |
|
615 | + $mq = $mq_fix && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc(); |
|
616 | + |
|
617 | + $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $schema); |
|
618 | + $ret = array(); |
|
619 | + foreach ($allowed as $key) { |
|
620 | + list($ns, $directive) = $key; |
|
621 | + $skey = "$ns.$directive"; |
|
622 | + if (!empty($array["Null_$skey"])) { |
|
623 | + $ret[$ns][$directive] = null; |
|
624 | + continue; |
|
625 | + } |
|
626 | + if (!isset($array[$skey])) continue; |
|
627 | + $value = $mq ? stripslashes($array[$skey]) : $array[$skey]; |
|
628 | + $ret[$ns][$directive] = $value; |
|
629 | + } |
|
630 | + return $ret; |
|
631 | + } |
|
632 | + |
|
633 | + /** |
|
634 | + * Loads configuration values from an ini file |
|
635 | + * @param $filename Name of ini file |
|
636 | + */ |
|
637 | + public function loadIni($filename) { |
|
638 | + if ($this->isFinalized('Cannot load directives after finalization')) return; |
|
639 | + $array = parse_ini_file($filename, true); |
|
640 | + $this->loadArray($array); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Checks whether or not the configuration object is finalized. |
|
645 | + * @param $error String error message, or false for no error |
|
646 | + */ |
|
647 | + public function isFinalized($error = false) { |
|
648 | + if ($this->finalized && $error) { |
|
649 | + $this->triggerError($error, E_USER_ERROR); |
|
650 | + } |
|
651 | + return $this->finalized; |
|
652 | + } |
|
653 | + |
|
654 | + /** |
|
655 | + * Finalizes configuration only if auto finalize is on and not |
|
656 | + * already finalized |
|
657 | + */ |
|
658 | + public function autoFinalize() { |
|
659 | + if ($this->autoFinalize) { |
|
660 | + $this->finalize(); |
|
661 | + } else { |
|
662 | + $this->plist->squash(true); |
|
663 | + } |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * Finalizes a configuration object, prohibiting further change |
|
668 | + */ |
|
669 | + public function finalize() { |
|
670 | + $this->finalized = true; |
|
671 | + $this->parser = null; |
|
672 | + } |
|
673 | + |
|
674 | + /** |
|
675 | + * Produces a nicely formatted error message by supplying the |
|
676 | + * stack frame information OUTSIDE of HTMLPurifier_Config. |
|
677 | + */ |
|
678 | + protected function triggerError($msg, $no) { |
|
679 | + // determine previous stack frame |
|
680 | + $extra = ''; |
|
681 | + if ($this->chatty) { |
|
682 | + $trace = debug_backtrace(); |
|
683 | + // zip(tail(trace), trace) -- but PHP is not Haskell har har |
|
684 | + for ($i = 0, $c = count($trace); $i < $c - 1; $i++) { |
|
685 | + if ($trace[$i + 1]['class'] === 'HTMLPurifier_Config') { |
|
686 | + continue; |
|
687 | + } |
|
688 | + $frame = $trace[$i]; |
|
689 | + $extra = " invoked on line {$frame['line']} in file {$frame['file']}"; |
|
690 | + break; |
|
691 | + } |
|
692 | + } |
|
693 | + trigger_error($msg . $extra, $no); |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | + * Returns a serialized form of the configuration object that can |
|
698 | + * be reconstituted. |
|
699 | + */ |
|
700 | + public function serialize() { |
|
701 | + $this->getDefinition('HTML'); |
|
702 | + $this->getDefinition('CSS'); |
|
703 | + $this->getDefinition('URI'); |
|
704 | + return serialize($this); |
|
705 | + } |
|
706 | 706 | |
707 | 707 | } |
708 | 708 |
@@ -116,8 +116,11 @@ discard block |
||
116 | 116 | } else { |
117 | 117 | $ret = new HTMLPurifier_Config($schema); |
118 | 118 | } |
119 | - if (is_string($config)) $ret->loadIni($config); |
|
120 | - elseif (is_array($config)) $ret->loadArray($config); |
|
119 | + if (is_string($config)) { |
|
120 | + $ret->loadIni($config); |
|
121 | + } elseif (is_array($config)) { |
|
122 | + $ret->loadArray($config); |
|
123 | + } |
|
121 | 124 | return $ret; |
122 | 125 | } |
123 | 126 | |
@@ -150,7 +153,9 @@ discard block |
||
150 | 153 | $this->triggerError("Using deprecated API: use \$config->get('$key.$a') instead", E_USER_WARNING); |
151 | 154 | $key = "$key.$a"; |
152 | 155 | } |
153 | - if (!$this->finalized) $this->autoFinalize(); |
|
156 | + if (!$this->finalized) { |
|
157 | + $this->autoFinalize(); |
|
158 | + } |
|
154 | 159 | if (!isset($this->def->info[$key])) { |
155 | 160 | // can't add % due to SimpleTest bug |
156 | 161 | $this->triggerError('Cannot retrieve value of undefined directive ' . htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
@@ -178,7 +183,9 @@ discard block |
||
178 | 183 | * @param $namespace String namespace |
179 | 184 | */ |
180 | 185 | public function getBatch($namespace) { |
181 | - if (!$this->finalized) $this->autoFinalize(); |
|
186 | + if (!$this->finalized) { |
|
187 | + $this->autoFinalize(); |
|
188 | + } |
|
182 | 189 | $full = $this->getAll(); |
183 | 190 | if (!isset($full[$namespace])) { |
184 | 191 | $this->triggerError('Cannot retrieve undefined namespace ' . htmlspecialchars($namespace, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
@@ -220,7 +227,9 @@ discard block |
||
220 | 227 | * @warning This is a pretty inefficient function, avoid if you can |
221 | 228 | */ |
222 | 229 | public function getAll() { |
223 | - if (!$this->finalized) $this->autoFinalize(); |
|
230 | + if (!$this->finalized) { |
|
231 | + $this->autoFinalize(); |
|
232 | + } |
|
224 | 233 | $ret = array(); |
225 | 234 | foreach ($this->plist->squash() as $name => $value) { |
226 | 235 | list($ns, $key) = explode('.', $name, 2); |
@@ -244,7 +253,9 @@ discard block |
||
244 | 253 | } else { |
245 | 254 | list($namespace) = explode('.', $key); |
246 | 255 | } |
247 | - if ($this->isFinalized('Cannot set directive after finalization')) return; |
|
256 | + if ($this->isFinalized('Cannot set directive after finalization')) { |
|
257 | + return; |
|
258 | + } |
|
248 | 259 | if (!isset($this->def->info[$key])) { |
249 | 260 | $this->triggerError('Cannot set undefined directive ' . htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' to value', |
250 | 261 | E_USER_WARNING); |
@@ -311,7 +322,9 @@ discard block |
||
311 | 322 | */ |
312 | 323 | private function _listify($lookup) { |
313 | 324 | $list = array(); |
314 | - foreach ($lookup as $name => $b) $list[] = $name; |
|
325 | + foreach ($lookup as $name => $b) { |
|
326 | + $list[] = $name; |
|
327 | + } |
|
315 | 328 | return implode(', ', $list); |
316 | 329 | } |
317 | 330 | |
@@ -377,7 +390,9 @@ discard block |
||
377 | 390 | if ($optimized && !$raw) { |
378 | 391 | throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false"); |
379 | 392 | } |
380 | - if (!$this->finalized) $this->autoFinalize(); |
|
393 | + if (!$this->finalized) { |
|
394 | + $this->autoFinalize(); |
|
395 | + } |
|
381 | 396 | // temporarily suspend locks, so we can handle recursive definition calls |
382 | 397 | $lock = $this->lock; |
383 | 398 | $this->lock = null; |
@@ -395,7 +410,9 @@ discard block |
||
395 | 410 | return $def; |
396 | 411 | } else { |
397 | 412 | $def->setup($this); |
398 | - if ($def->optimized) $cache->add($def, $this); |
|
413 | + if ($def->optimized) { |
|
414 | + $cache->add($def, $this); |
|
415 | + } |
|
399 | 416 | return $def; |
400 | 417 | } |
401 | 418 | } |
@@ -524,7 +541,9 @@ discard block |
||
524 | 541 | * @param $config_array Configuration associative array |
525 | 542 | */ |
526 | 543 | public function loadArray($config_array) { |
527 | - if ($this->isFinalized('Cannot load directives after finalization')) return; |
|
544 | + if ($this->isFinalized('Cannot load directives after finalization')) { |
|
545 | + return; |
|
546 | + } |
|
528 | 547 | foreach ($config_array as $key => $value) { |
529 | 548 | $key = str_replace('_', '.', $key); |
530 | 549 | if (strpos($key, '.') !== false) { |
@@ -550,7 +569,9 @@ discard block |
||
550 | 569 | $schema = HTMLPurifier_ConfigSchema::instance(); |
551 | 570 | } |
552 | 571 | if ($allowed !== true) { |
553 | - if (is_string($allowed)) $allowed = array($allowed); |
|
572 | + if (is_string($allowed)) { |
|
573 | + $allowed = array($allowed); |
|
574 | + } |
|
554 | 575 | $allowed_ns = array(); |
555 | 576 | $allowed_directives = array(); |
556 | 577 | $blacklisted_directives = array(); |
@@ -572,11 +593,19 @@ discard block |
||
572 | 593 | foreach ($schema->info as $key => $def) { |
573 | 594 | list($ns, $directive) = explode('.', $key, 2); |
574 | 595 | if ($allowed !== true) { |
575 | - if (isset($blacklisted_directives["$ns.$directive"])) continue; |
|
576 | - if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) continue; |
|
596 | + if (isset($blacklisted_directives["$ns.$directive"])) { |
|
597 | + continue; |
|
598 | + } |
|
599 | + if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) { |
|
600 | + continue; |
|
601 | + } |
|
602 | + } |
|
603 | + if (isset($def->isAlias)) { |
|
604 | + continue; |
|
605 | + } |
|
606 | + if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') { |
|
607 | + continue; |
|
577 | 608 | } |
578 | - if (isset($def->isAlias)) continue; |
|
579 | - if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') continue; |
|
580 | 609 | $ret[] = array($ns, $directive); |
581 | 610 | } |
582 | 611 | return $ret; |
@@ -611,7 +640,9 @@ discard block |
||
611 | 640 | * strict parts of HTMLPurifier_Config |
612 | 641 | */ |
613 | 642 | public static function prepareArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) { |
614 | - if ($index !== false) $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array(); |
|
643 | + if ($index !== false) { |
|
644 | + $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array(); |
|
645 | + } |
|
615 | 646 | $mq = $mq_fix && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc(); |
616 | 647 | |
617 | 648 | $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $schema); |
@@ -623,7 +654,9 @@ discard block |
||
623 | 654 | $ret[$ns][$directive] = null; |
624 | 655 | continue; |
625 | 656 | } |
626 | - if (!isset($array[$skey])) continue; |
|
657 | + if (!isset($array[$skey])) { |
|
658 | + continue; |
|
659 | + } |
|
627 | 660 | $value = $mq ? stripslashes($array[$skey]) : $array[$skey]; |
628 | 661 | $ret[$ns][$directive] = $value; |
629 | 662 | } |
@@ -635,7 +668,9 @@ discard block |
||
635 | 668 | * @param $filename Name of ini file |
636 | 669 | */ |
637 | 670 | public function loadIni($filename) { |
638 | - if ($this->isFinalized('Cannot load directives after finalization')) return; |
|
671 | + if ($this->isFinalized('Cannot load directives after finalization')) { |
|
672 | + return; |
|
673 | + } |
|
639 | 674 | $array = parse_ini_file($filename, true); |
640 | 675 | $this->loadArray($array); |
641 | 676 | } |
@@ -153,20 +153,20 @@ discard block |
||
153 | 153 | if (!$this->finalized) $this->autoFinalize(); |
154 | 154 | if (!isset($this->def->info[$key])) { |
155 | 155 | // can't add % due to SimpleTest bug |
156 | - $this->triggerError('Cannot retrieve value of undefined directive ' . htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
|
156 | + $this->triggerError('Cannot retrieve value of undefined directive '.htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
|
157 | 157 | E_USER_WARNING); |
158 | 158 | return; |
159 | 159 | } |
160 | 160 | if (isset($this->def->info[$key]->isAlias)) { |
161 | 161 | $d = $this->def->info[$key]; |
162 | - $this->triggerError('Cannot get value from aliased directive, use real name ' . $d->key, |
|
162 | + $this->triggerError('Cannot get value from aliased directive, use real name '.$d->key, |
|
163 | 163 | E_USER_ERROR); |
164 | 164 | return; |
165 | 165 | } |
166 | 166 | if ($this->lock) { |
167 | 167 | list($ns) = explode('.', $key); |
168 | 168 | if ($ns !== $this->lock) { |
169 | - $this->triggerError('Cannot get value of namespace ' . $ns . ' when lock for ' . $this->lock . ' is active, this probably indicates a Definition setup method is accessing directives that are not within its namespace', E_USER_ERROR); |
|
169 | + $this->triggerError('Cannot get value of namespace '.$ns.' when lock for '.$this->lock.' is active, this probably indicates a Definition setup method is accessing directives that are not within its namespace', E_USER_ERROR); |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | if (!$this->finalized) $this->autoFinalize(); |
182 | 182 | $full = $this->getAll(); |
183 | 183 | if (!isset($full[$namespace])) { |
184 | - $this->triggerError('Cannot retrieve undefined namespace ' . htmlspecialchars($namespace, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
|
184 | + $this->triggerError('Cannot retrieve undefined namespace '.htmlspecialchars($namespace, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), |
|
185 | 185 | E_USER_WARNING); |
186 | 186 | return; |
187 | 187 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | } |
247 | 247 | if ($this->isFinalized('Cannot set directive after finalization')) return; |
248 | 248 | if (!isset($this->def->info[$key])) { |
249 | - $this->triggerError('Cannot set undefined directive ' . htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' to value', |
|
249 | + $this->triggerError('Cannot set undefined directive '.htmlspecialchars($key, ENT_COMPAT | ENT_HTML401, 'UTF-8', false).' to value', |
|
250 | 250 | E_USER_WARNING); |
251 | 251 | return; |
252 | 252 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | if (isset($def->isAlias)) { |
256 | 256 | if ($this->aliasMode) { |
257 | 257 | $this->triggerError('Double-aliases not allowed, please fix '. |
258 | - 'ConfigSchema bug with' . $key, E_USER_ERROR); |
|
258 | + 'ConfigSchema bug with'.$key, E_USER_ERROR); |
|
259 | 259 | return; |
260 | 260 | } |
261 | 261 | $this->aliasMode = true; |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | try { |
280 | 280 | $value = $this->parser->parse($value, $type, $allow_null); |
281 | 281 | } catch (HTMLPurifier_VarParserException $e) { |
282 | - $this->triggerError('Value for ' . $key . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING); |
|
282 | + $this->triggerError('Value for '.$key.' is of invalid type, should be '.HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING); |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | if (is_string($value) && is_object($def)) { |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | } |
290 | 290 | // check to see if the value is allowed |
291 | 291 | if (isset($def->allowed) && !isset($def->allowed[$value])) { |
292 | - $this->triggerError('Value not supported, valid values are: ' . |
|
292 | + $this->triggerError('Value not supported, valid values are: '. |
|
293 | 293 | $this->_listify($def->allowed), E_USER_WARNING); |
294 | 294 | return; |
295 | 295 | } |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | // check preconditions |
423 | 423 | $def = null; |
424 | 424 | if ($optimized) { |
425 | - if (is_null($this->get($type . '.DefinitionID'))) { |
|
425 | + if (is_null($this->get($type.'.DefinitionID'))) { |
|
426 | 426 | // fatally error out if definition ID not set |
427 | 427 | throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %$type.DefinitionID"); |
428 | 428 | } |
@@ -431,16 +431,16 @@ discard block |
||
431 | 431 | $def = $this->definitions[$type]; |
432 | 432 | if ($def->setup && !$optimized) { |
433 | 433 | $extra = $this->chatty ? " (try moving this code block earlier in your initialization)" : ""; |
434 | - throw new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup" . $extra); |
|
434 | + throw new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup".$extra); |
|
435 | 435 | } |
436 | 436 | if ($def->optimized === null) { |
437 | 437 | $extra = $this->chatty ? " (try flushing your cache)" : ""; |
438 | - throw new HTMLPurifier_Exception("Optimization status of definition is unknown" . $extra); |
|
438 | + throw new HTMLPurifier_Exception("Optimization status of definition is unknown".$extra); |
|
439 | 439 | } |
440 | 440 | if ($def->optimized !== $optimized) { |
441 | 441 | $msg = $optimized ? "optimized" : "unoptimized"; |
442 | 442 | $extra = $this->chatty ? " (this backtrace is for the first inconsistent call, which was for a $msg raw definition)" : ""; |
443 | - throw new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra); |
|
443 | + throw new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals".$extra); |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | // check if definition was in memory |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | } |
472 | 472 | // check invariants for creation |
473 | 473 | if (!$optimized) { |
474 | - if (!is_null($this->get($type . '.DefinitionID'))) { |
|
474 | + if (!is_null($this->get($type.'.DefinitionID'))) { |
|
475 | 475 | if ($this->chatty) { |
476 | 476 | $this->triggerError("Due to a documentation error in previous version of HTML Purifier, your definitions are not being cached. If this is OK, you can remove the %$type.DefinitionRev and %$type.DefinitionID declaration. Otherwise, modify your code to use maybeGetRawDefinition, and test if the returned value is null before making any edits (if it is null, that means that a cached version is available, and no raw operations are necessary). See <a href='http://htmlpurifier.org/docs/enduser-customize.html#optimized'>Customize</a> for more details", E_USER_WARNING); |
477 | 477 | } else { |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $namespace = $key; |
534 | 534 | $namespace_values = $value; |
535 | 535 | foreach ($namespace_values as $directive => $value) { |
536 | - $this->set($namespace .'.'. $directive, $value); |
|
536 | + $this->set($namespace.'.'.$directive, $value); |
|
537 | 537 | } |
538 | 538 | } |
539 | 539 | } |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | break; |
691 | 691 | } |
692 | 692 | } |
693 | - trigger_error($msg . $extra, $no); |
|
693 | + trigger_error($msg.$extra, $no); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |