1 : <?php
2 :
3 : // constants are slow, so we use as few as possible
4 1 : if (!defined('HTMLPURIFIER_PREFIX')) {
5 1 : define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));
6 1 : }
7 :
8 : // accomodations for versions earlier than 5.0.2
9 : // borrowed from PHP_Compat, LGPL licensed, by Aidan Lister <aidan@php.net>
10 1 : if (!defined('PHP_EOL')) {
11 0 : switch (strtoupper(substr(PHP_OS, 0, 3))) {
12 0 : case 'WIN':
13 0 : define('PHP_EOL', "\r\n");
14 0 : break;
15 0 : case 'DAR':
16 0 : define('PHP_EOL', "\r");
17 0 : break;
18 0 : default:
19 0 : define('PHP_EOL', "\n");
20 0 : }
21 0 : }
22 :
23 : /**
24 : * Bootstrap class that contains meta-functionality for HTML Purifier such as
25 : * the autoload function.
26 : *
27 : * @note
28 : * This class may be used without any other files from HTML Purifier.
29 : */
30 : class HTMLPurifier_Bootstrap
31 1 : {
32 :
33 : /**
34 : * Autoload function for HTML Purifier
35 : * @param $class Class to load
36 : */
37 : public static function autoload($class) {
38 1 : $file = HTMLPurifier_Bootstrap::getPath($class);
39 1 : if (!$file) return false;
40 1 : require HTMLPURIFIER_PREFIX . '/' . $file;
41 1 : return true;
42 : }
43 :
44 : /**
45 : * Returns the path for a specific class.
46 : */
47 : public static function getPath($class) {
48 1 : if (strncmp('HTMLPurifier', $class, 12) !== 0) return false;
49 : // Custom implementations
50 1 : if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {
51 0 : $code = str_replace('_', '-', substr($class, 22));
52 0 : $file = 'HTMLPurifier/Language/classes/' . $code . '.php';
53 0 : } else {
54 1 : $file = str_replace('_', '/', $class) . '.php';
55 : }
56 1 : if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) return false;
57 1 : return $file;
58 : }
59 :
60 : /**
61 : * "Pre-registers" our autoloader on the SPL stack.
62 : */
63 : public static function registerAutoload() {
64 1 : $autoload = array('HTMLPurifier_Bootstrap', 'autoload');
65 1 : if ( ($funcs = spl_autoload_functions()) === false ) {
66 1 : spl_autoload_register($autoload);
67 1 : } elseif (function_exists('spl_autoload_unregister')) {
68 0 : $compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
69 0 : version_compare(PHP_VERSION, '5.1.0', '>=');
70 0 : foreach ($funcs as $func) {
71 0 : if (is_array($func)) {
72 : // :TRICKY: There are some compatibility issues and some
73 : // places where we need to error out
74 0 : $reflector = new ReflectionMethod($func[0], $func[1]);
75 0 : if (!$reflector->isStatic()) {
76 0 : throw new Exception('
77 : HTML Purifier autoloader registrar is not compatible
78 : with non-static object methods due to PHP Bug #44144;
79 : Please do not use HTMLPurifier.autoload.php (or any
80 : file that includes this file); instead, place the code:
81 : spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\'))
82 : after your own autoloaders.
83 0 : ');
84 : }
85 : // Suprisingly, spl_autoload_register supports the
86 : // Class::staticMethod callback format, although call_user_func doesn't
87 0 : if ($compat) $func = implode('::', $func);
88 0 : }
89 0 : spl_autoload_unregister($func);
90 0 : }
91 0 : spl_autoload_register($autoload);
92 0 : foreach ($funcs as $func) spl_autoload_register($func);
93 0 : }
94 1 : }
95 :
96 : }
|