| 1: | <?php
|
| 2: |
|
| 3: |
|
| 4: | if (!defined('HTMLPURIFIER_PREFIX')) {
|
| 5: | define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));
|
| 6: | }
|
| 7: |
|
| 8: |
|
| 9: |
|
| 10: | if (!defined('PHP_EOL')) {
|
| 11: | switch (strtoupper(substr(PHP_OS, 0, 3))) {
|
| 12: | case 'WIN':
|
| 13: | define('PHP_EOL', "\r\n");
|
| 14: | break;
|
| 15: | case 'DAR':
|
| 16: | define('PHP_EOL', "\r");
|
| 17: | break;
|
| 18: | default:
|
| 19: | define('PHP_EOL', "\n");
|
| 20: | }
|
| 21: | }
|
| 22: |
|
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: |
|
| 30: | class HTMLPurifier_Bootstrap
|
| 31: | {
|
| 32: |
|
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: |
|
| 38: | public static function autoload($class)
|
| 39: | {
|
| 40: | $file = HTMLPurifier_Bootstrap::getPath($class);
|
| 41: | if (!$file) {
|
| 42: | return false;
|
| 43: | }
|
| 44: |
|
| 45: |
|
| 46: |
|
| 47: |
|
| 48: |
|
| 49: | require_once HTMLPURIFIER_PREFIX . '/' . $file;
|
| 50: | return true;
|
| 51: | }
|
| 52: |
|
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: |
|
| 58: | public static function getPath($class)
|
| 59: | {
|
| 60: | if (strncmp('HTMLPurifier', $class, 12) !== 0) {
|
| 61: | return false;
|
| 62: | }
|
| 63: |
|
| 64: | if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {
|
| 65: | $code = str_replace('_', '-', substr($class, 22));
|
| 66: | $file = 'HTMLPurifier/Language/classes/' . $code . '.php';
|
| 67: | } else {
|
| 68: | $file = str_replace('_', '/', $class) . '.php';
|
| 69: | }
|
| 70: | if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) {
|
| 71: | return false;
|
| 72: | }
|
| 73: | return $file;
|
| 74: | }
|
| 75: |
|
| 76: | |
| 77: | |
| 78: |
|
| 79: | public static function registerAutoload()
|
| 80: | {
|
| 81: | $autoload = array('HTMLPurifier_Bootstrap', 'autoload');
|
| 82: | if (($funcs = spl_autoload_functions()) === false) {
|
| 83: | spl_autoload_register($autoload);
|
| 84: | } elseif (function_exists('spl_autoload_unregister')) {
|
| 85: | if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
|
| 86: |
|
| 87: | spl_autoload_register($autoload, true, true);
|
| 88: | } else {
|
| 89: | $buggy = version_compare(PHP_VERSION, '5.2.11', '<');
|
| 90: | $compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
|
| 91: | version_compare(PHP_VERSION, '5.1.0', '>=');
|
| 92: | foreach ($funcs as $func) {
|
| 93: | if ($buggy && is_array($func)) {
|
| 94: |
|
| 95: |
|
| 96: | $reflector = new ReflectionMethod($func[0], $func[1]);
|
| 97: | if (!$reflector->isStatic()) {
|
| 98: | throw new Exception(
|
| 99: | 'HTML Purifier autoloader registrar is not compatible
|
| 100: | with non-static object methods due to PHP Bug #44144;
|
| 101: | Please do not use HTMLPurifier.autoload.php (or any
|
| 102: | file that includes this file); instead, place the code:
|
| 103: | spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\'))
|
| 104: | after your own autoloaders.'
|
| 105: | );
|
| 106: | }
|
| 107: |
|
| 108: |
|
| 109: | if ($compat) {
|
| 110: | $func = implode('::', $func);
|
| 111: | }
|
| 112: | }
|
| 113: | spl_autoload_unregister($func);
|
| 114: | }
|
| 115: | spl_autoload_register($autoload);
|
| 116: | foreach ($funcs as $func) {
|
| 117: | spl_autoload_register($func);
|
| 118: | }
|
| 119: | }
|
| 120: | }
|
| 121: | }
|
| 122: | }
|
| 123: |
|
| 124: |
|
| 125: | |