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