xref: /dokuwiki/inc/load.php (revision 836f6efbf31a2a263102aea61ef0cc5d577aa9bb)
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');
37
38/**
39 * spl_autoload_register callback
40 *
41 * Contains a static list of DokuWiki's core classes and automatically
42 * require()s their associated php files when an object is instantiated.
43 *
44 * @author Andreas Gohr <andi@splitbrain.org>
45 * @todo   add generic loading of renderers and auth backends
46 *
47 * @param string $name
48 *
49 * @return bool
50 */
51function load_autoload($name){
52    static $classes = null;
53    if(is_null($classes)) $classes = array(
54        'DokuHTTPClient'        => DOKU_INC.'inc/HTTPClient.php',
55        'HTTPClient'            => DOKU_INC.'inc/HTTPClient.php',
56        'JSON'                  => DOKU_INC.'inc/JSON.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        'RemoteAPI'             => DOKU_INC.'inc/remote.php',
80        'RemoteAPICore'         => DOKU_INC.'inc/RemoteAPICore.php',
81        'Subscription'          => DOKU_INC.'inc/subscription.php',
82
83        'DokuWiki_PluginInterface' => DOKU_INC.'inc/PluginInterface.php',
84        'DokuWiki_PluginTrait'     => DOKU_INC.'inc/PluginTrait.php',
85        'DokuWiki_Plugin'          => DOKU_INC.'inc/Plugin.php',
86
87
88        'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php',
89        'DokuWiki_Admin_Plugin'  => DOKU_PLUGIN.'admin.php',
90        'DokuWiki_Syntax_Plugin' => DOKU_PLUGIN.'syntax.php',
91        'DokuWiki_Remote_Plugin' => DOKU_PLUGIN.'remote.php',
92        'DokuWiki_Auth_Plugin'   => DOKU_PLUGIN.'auth.php',
93        'DokuWiki_CLI_Plugin'    => DOKU_PLUGIN.'cli.php',
94
95        'Doku_Handler'          => DOKU_INC.'inc/parser/handler.php',
96        'Doku_Renderer'          => DOKU_INC.'inc/parser/renderer.php',
97        'Doku_Renderer_xhtml'    => DOKU_INC.'inc/parser/xhtml.php',
98        'Doku_Renderer_code'     => DOKU_INC.'inc/parser/code.php',
99        'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php',
100        'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php',
101
102        'DokuCLI'                => DOKU_INC.'inc/cli.php',
103        'DokuCLI_Options'        => DOKU_INC.'inc/cli.php',
104        'DokuCLI_Colors'         => DOKU_INC.'inc/cli.php',
105
106    );
107
108    if(isset($classes[$name])){
109        require ($classes[$name]);
110        return true;
111    }
112
113    // namespace to directory conversion
114    $name = str_replace('\\', '/', $name);
115
116    // test namespace
117    if(substr($name, 0, 14) == 'dokuwiki/test/') {
118        $file = DOKU_INC . '_test/' . substr($name, 14) . '.php';
119        if(file_exists($file)) {
120            require $file;
121            return true;
122        }
123    }
124
125    // plugin namespace
126    if(substr($name, 0, 16) == 'dokuwiki/plugin/') {
127        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
128        $file = DOKU_PLUGIN . substr($name, 16) . '.php';
129        if(file_exists($file)) {
130            require $file;
131            return true;
132        }
133    }
134
135    // template namespace
136    if(substr($name, 0, 18) == 'dokuwiki/template/') {
137        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
138        $file = DOKU_INC.'lib/tpl/' . substr($name, 18) . '.php';
139        if(file_exists($file)) {
140            require $file;
141            return true;
142        }
143    }
144
145    // our own namespace
146    if(substr($name, 0, 9) == 'dokuwiki/') {
147        $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php';
148        if(file_exists($file)) {
149            require $file;
150            return true;
151        }
152    }
153
154    // Plugin loading
155    if(preg_match(
156        '/^(auth|helper|syntax|action|admin|renderer|remote|cli)_plugin_(' .
157        DOKU_PLUGIN_NAME_REGEX .
158        ')(?:_([^_]+))?$/',
159        $name,
160        $m
161    )) {
162        // try to load the wanted plugin file
163        $c = ((count($m) === 4) ? "/{$m[3]}" : '');
164        $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
165        if(file_exists($plg)){
166            require $plg;
167        }
168        return true;
169    }
170    return false;
171}
172
173