xref: /dokuwiki/inc/load.php (revision d443762bafe99b9292cee141f99fbe818e8d2f16)
1<?php
2/**
3 * Load all internal libraries and setup class autoloader
4 *
5 * @author Andreas Gohr <andi@splitbrain.org>
6 */
7
8// setup class autoloader
9spl_autoload_register('load_autoload');
10
11// require all the common libraries
12// for a few of these order does matter
13require_once(DOKU_INC.'inc/actions.php');
14require_once(DOKU_INC.'inc/changelog.php');
15require_once(DOKU_INC.'inc/common.php');
16require_once(DOKU_INC.'inc/confutils.php');
17require_once(DOKU_INC.'inc/pluginutils.php');
18require_once(DOKU_INC.'inc/events.php');
19require_once(DOKU_INC.'inc/form.php');
20require_once(DOKU_INC.'inc/fulltext.php');
21require_once(DOKU_INC.'inc/html.php');
22require_once(DOKU_INC.'inc/httputils.php');
23require_once(DOKU_INC.'inc/indexer.php');
24require_once(DOKU_INC.'inc/infoutils.php');
25require_once(DOKU_INC.'inc/io.php');
26require_once(DOKU_INC.'inc/mail.php');
27require_once(DOKU_INC.'inc/media.php');
28require_once(DOKU_INC.'inc/pageutils.php');
29require_once(DOKU_INC.'inc/parserutils.php');
30require_once(DOKU_INC.'inc/search.php');
31require_once(DOKU_INC.'inc/subscription.php');
32require_once(DOKU_INC.'inc/template.php');
33require_once(DOKU_INC.'inc/toolbar.php');
34require_once(DOKU_INC.'inc/utf8.php');
35require_once(DOKU_INC.'inc/auth.php');
36require_once(DOKU_INC.'inc/compatibility.php');
37require_once(DOKU_INC.'inc/deprecated.php');
38
39/**
40 * spl_autoload_register callback
41 *
42 * Contains a static list of DokuWiki's core classes and automatically
43 * require()s their associated php files when an object is instantiated.
44 *
45 * @author Andreas Gohr <andi@splitbrain.org>
46 * @todo   add generic loading of renderers and auth backends
47 *
48 * @param string $name
49 *
50 * @return bool
51 */
52function load_autoload($name){
53    static $classes = null;
54    if(is_null($classes)) $classes = array(
55        'DokuHTTPClient'        => DOKU_INC.'inc/HTTPClient.php',
56        'HTTPClient'            => DOKU_INC.'inc/HTTPClient.php',
57        'Diff'                  => DOKU_INC.'inc/DifferenceEngine.php',
58        'UnifiedDiffFormatter'  => DOKU_INC.'inc/DifferenceEngine.php',
59        'TableDiffFormatter'    => DOKU_INC.'inc/DifferenceEngine.php',
60        'cache'                 => DOKU_INC.'inc/cache.php',
61        'cache_parser'          => DOKU_INC.'inc/cache.php',
62        'cache_instructions'    => DOKU_INC.'inc/cache.php',
63        'cache_renderer'        => DOKU_INC.'inc/cache.php',
64        'Doku_Event'            => DOKU_INC.'inc/events.php',
65        'Doku_Event_Handler'    => DOKU_INC.'inc/events.php',
66        'Input'                 => DOKU_INC.'inc/Input.class.php',
67        'JpegMeta'              => DOKU_INC.'inc/JpegMeta.php',
68        'SimplePie'             => DOKU_INC.'inc/SimplePie.php',
69        'FeedParser'            => DOKU_INC.'inc/FeedParser.php',
70        'IXR_Server'            => DOKU_INC.'inc/IXR_Library.php',
71        'IXR_Client'            => DOKU_INC.'inc/IXR_Library.php',
72        'IXR_Error'             => DOKU_INC.'inc/IXR_Library.php',
73        'IXR_IntrospectionServer' => DOKU_INC.'inc/IXR_Library.php',
74        'Doku_Plugin_Controller'=> DOKU_INC.'inc/plugincontroller.class.php',
75        'SafeFN'                => DOKU_INC.'inc/SafeFN.class.php',
76        'Sitemapper'            => DOKU_INC.'inc/Sitemapper.php',
77        'PassHash'              => DOKU_INC.'inc/PassHash.class.php',
78        'Mailer'                => DOKU_INC.'inc/Mailer.class.php',
79        'Subscription'          => DOKU_INC.'inc/subscription.php',
80
81        'DokuWiki_PluginInterface' => DOKU_INC.'inc/PluginInterface.php',
82        'DokuWiki_PluginTrait'     => DOKU_INC.'inc/PluginTrait.php',
83        'DokuWiki_Plugin'          => DOKU_INC.'inc/Plugin.php',
84
85
86        'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php',
87        'DokuWiki_Admin_Plugin'  => DOKU_PLUGIN.'admin.php',
88        'DokuWiki_Syntax_Plugin' => DOKU_PLUGIN.'syntax.php',
89        'DokuWiki_Remote_Plugin' => DOKU_PLUGIN.'remote.php',
90        'DokuWiki_Auth_Plugin'   => DOKU_PLUGIN.'auth.php',
91        'DokuWiki_CLI_Plugin'    => DOKU_PLUGIN.'cli.php',
92
93        'Doku_Handler'          => DOKU_INC.'inc/parser/handler.php',
94        'Doku_Renderer'          => DOKU_INC.'inc/parser/renderer.php',
95        'Doku_Renderer_xhtml'    => DOKU_INC.'inc/parser/xhtml.php',
96        'Doku_Renderer_code'     => DOKU_INC.'inc/parser/code.php',
97        'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php',
98        'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php',
99
100        'DokuCLI'                => DOKU_INC.'inc/cli.php',
101        'DokuCLI_Options'        => DOKU_INC.'inc/cli.php',
102        'DokuCLI_Colors'         => DOKU_INC.'inc/cli.php',
103
104    );
105
106    if(isset($classes[$name])){
107        require ($classes[$name]);
108        return true;
109    }
110
111    // namespace to directory conversion
112    $name = str_replace('\\', '/', $name);
113
114    // test namespace
115    if(substr($name, 0, 14) == 'dokuwiki/test/') {
116        $file = DOKU_INC . '_test/' . substr($name, 14) . '.php';
117        if(file_exists($file)) {
118            require $file;
119            return true;
120        }
121    }
122
123    // plugin namespace
124    if(substr($name, 0, 16) == 'dokuwiki/plugin/') {
125        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
126        $file = DOKU_PLUGIN . substr($name, 16) . '.php';
127        if(file_exists($file)) {
128            require $file;
129            return true;
130        }
131    }
132
133    // template namespace
134    if(substr($name, 0, 18) == 'dokuwiki/template/') {
135        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
136        $file = DOKU_INC.'lib/tpl/' . substr($name, 18) . '.php';
137        if(file_exists($file)) {
138            require $file;
139            return true;
140        }
141    }
142
143    // our own namespace
144    if(substr($name, 0, 9) == 'dokuwiki/') {
145        $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php';
146        if(file_exists($file)) {
147            require $file;
148            return true;
149        }
150    }
151
152    // Plugin loading
153    if(preg_match(
154        '/^(auth|helper|syntax|action|admin|renderer|remote|cli)_plugin_(' .
155        DOKU_PLUGIN_NAME_REGEX .
156        ')(?:_([^_]+))?$/',
157        $name,
158        $m
159    )) {
160        // try to load the wanted plugin file
161        $c = ((count($m) === 4) ? "/{$m[3]}" : '');
162        $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
163        if(file_exists($plg)){
164            require $plg;
165        }
166        return true;
167    }
168    return false;
169}
170
171