summaryrefslogtreecommitdiff
path: root/platform/www/inc/load.php
blob: 46cd91f4c35ccdbc43d062a0eadf2ddb1e61a471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
 * Load all internal libraries and setup class autoloader
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */

use dokuwiki\Extension\PluginController;

// setup class autoloader
spl_autoload_register('load_autoload');

// require all the common libraries
// for a few of these order does matter
require_once(DOKU_INC.'inc/defines.php');
require_once(DOKU_INC.'inc/actions.php');
require_once(DOKU_INC.'inc/changelog.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/confutils.php');
require_once(DOKU_INC.'inc/pluginutils.php');
require_once(DOKU_INC.'inc/form.php');
require_once(DOKU_INC.'inc/fulltext.php');
require_once(DOKU_INC.'inc/html.php');
require_once(DOKU_INC.'inc/httputils.php');
require_once(DOKU_INC.'inc/indexer.php');
require_once(DOKU_INC.'inc/infoutils.php');
require_once(DOKU_INC.'inc/io.php');
require_once(DOKU_INC.'inc/mail.php');
require_once(DOKU_INC.'inc/media.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/parserutils.php');
require_once(DOKU_INC.'inc/search.php');
require_once(DOKU_INC.'inc/template.php');
require_once(DOKU_INC.'inc/toolbar.php');
require_once(DOKU_INC.'inc/utf8.php');
require_once(DOKU_INC.'inc/auth.php');
require_once(DOKU_INC.'inc/compatibility.php');
require_once(DOKU_INC.'inc/deprecated.php');
require_once(DOKU_INC.'inc/legacy.php');

/**
 * spl_autoload_register callback
 *
 * Contains a static list of DokuWiki's core classes and automatically
 * require()s their associated php files when an object is instantiated.
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @todo   add generic loading of renderers and auth backends
 *
 * @param string $name
 *
 * @return bool
 */
function load_autoload($name){
    static $classes = null;
    if($classes === null) $classes = array(
        'Diff'                  => DOKU_INC.'inc/DifferenceEngine.php',
        'UnifiedDiffFormatter'  => DOKU_INC.'inc/DifferenceEngine.php',
        'TableDiffFormatter'    => DOKU_INC.'inc/DifferenceEngine.php',
        'cache'                 => DOKU_INC.'inc/cache.php',
        'cache_parser'          => DOKU_INC.'inc/cache.php',
        'cache_instructions'    => DOKU_INC.'inc/cache.php',
        'cache_renderer'        => DOKU_INC.'inc/cache.php',
        'Input'                 => DOKU_INC.'inc/Input.class.php',
        'JpegMeta'              => DOKU_INC.'inc/JpegMeta.php',
        'SimplePie'             => DOKU_INC.'inc/SimplePie.php',
        'FeedParser'            => DOKU_INC.'inc/FeedParser.php',
        'IXR_Server'            => DOKU_INC.'inc/IXR_Library.php',
        'IXR_Client'            => DOKU_INC.'inc/IXR_Library.php',
        'IXR_Error'             => DOKU_INC.'inc/IXR_Library.php',
        'IXR_IntrospectionServer' => DOKU_INC.'inc/IXR_Library.php',
        'SafeFN'                => DOKU_INC.'inc/SafeFN.class.php',
        'Sitemapper'            => DOKU_INC.'inc/Sitemapper.php',
        'Mailer'                => DOKU_INC.'inc/Mailer.class.php',

        'Doku_Handler'          => DOKU_INC.'inc/parser/handler.php',
        'Doku_Renderer'          => DOKU_INC.'inc/parser/renderer.php',
        'Doku_Renderer_xhtml'    => DOKU_INC.'inc/parser/xhtml.php',
        'Doku_Renderer_code'     => DOKU_INC.'inc/parser/code.php',
        'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php',
        'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php',

        'DokuCLI'                => DOKU_INC.'inc/cli.php',
        'DokuCLI_Options'        => DOKU_INC.'inc/cli.php',
        'DokuCLI_Colors'         => DOKU_INC.'inc/cli.php',

    );

    if(isset($classes[$name])){
        require ($classes[$name]);
        return true;
    }

    // namespace to directory conversion
    $name = str_replace('\\', '/', $name);

    // test namespace
    if(substr($name, 0, 14) === 'dokuwiki/test/') {
        $file = DOKU_INC . '_test/' . substr($name, 14) . '.php';
        if(file_exists($file)) {
            require $file;
            return true;
        }
    }

    // plugin namespace
    if(substr($name, 0, 16) === 'dokuwiki/plugin/') {
        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
        $file = DOKU_PLUGIN . substr($name, 16) . '.php';
        if(file_exists($file)) {
            require $file;
            return true;
        }
    }

    // template namespace
    if(substr($name, 0, 18) === 'dokuwiki/template/') {
        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
        $file = DOKU_INC.'lib/tpl/' . substr($name, 18) . '.php';
        if(file_exists($file)) {
            require $file;
            return true;
        }
    }

    // our own namespace
    if(substr($name, 0, 9) === 'dokuwiki/') {
        $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php';
        if(file_exists($file)) {
            require $file;
            return true;
        }
    }

    // Plugin loading
    if(preg_match(
        '/^(' . implode('|', PluginController::PLUGIN_TYPES) . ')_plugin_(' .
        DOKU_PLUGIN_NAME_REGEX .
        ')(?:_([^_]+))?$/',
        $name,
        $m
    )) {
        // try to load the wanted plugin file
        $c = ((count($m) === 4) ? "/{$m[3]}" : '');
        $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
        if(file_exists($plg)){
            require $plg;
        }
        return true;
    }
    return false;
}