116905344SAndreas Gohr<?php 2*d4f83172SAndreas Gohr 316905344SAndreas Gohr/** 416905344SAndreas Gohr * Load all internal libraries and setup class autoloader 516905344SAndreas Gohr * 616905344SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 716905344SAndreas Gohr */ 8*d4f83172SAndreas Gohr 924870174SAndreas Gohruse dokuwiki\ErrorHandler; 101935a891SAndreas Gohruse dokuwiki\Extension\PluginController; 111935a891SAndreas Gohr 1216905344SAndreas Gohr// setup class autoloader 1316905344SAndreas Gohrspl_autoload_register('load_autoload'); 1416905344SAndreas Gohr 1516905344SAndreas Gohr// require all the common libraries 1605ed2c25SAndreas Gohr// for a few of these order does matter 1746028c4cSAndreas Gohrrequire_once(DOKU_INC . 'inc/defines.php'); 1816905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/actions.php'); 1916905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/changelog.php'); 2016905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/common.php'); 2116905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/confutils.php'); 2216905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/pluginutils.php'); 2316905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/form.php'); 2416905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/fulltext.php'); 2516905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/html.php'); 2616905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/httputils.php'); 2716905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/indexer.php'); 2816905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/infoutils.php'); 2916905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/io.php'); 3016905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/mail.php'); 3116905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/media.php'); 3216905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/pageutils.php'); 3316905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/parserutils.php'); 3416905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/search.php'); 3516905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/template.php'); 3616905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/toolbar.php'); 3716905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/utf8.php'); 3816905344SAndreas Gohrrequire_once(DOKU_INC . 'inc/auth.php'); 396589c60cSAndreas Gohrrequire_once(DOKU_INC . 'inc/compatibility.php'); 404cdb6842SAndreas Gohrrequire_once(DOKU_INC . 'inc/deprecated.php'); 41e1d9dcc8SAndreas Gohrrequire_once(DOKU_INC . 'inc/legacy.php'); 4216905344SAndreas Gohr 4316905344SAndreas Gohr/** 4416905344SAndreas Gohr * spl_autoload_register callback 4516905344SAndreas Gohr * 4616905344SAndreas Gohr * Contains a static list of DokuWiki's core classes and automatically 472dcde304SAndreas Gohr * require()s their associated php files when an object is instantiated. 4816905344SAndreas Gohr * 4916905344SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 50d54ac877SAdrian Lang * @todo add generic loading of renderers and auth backends 51f50a239bSTakamura * 52f50a239bSTakamura * @param string $name 53f50a239bSTakamura * 54f50a239bSTakamura * @return bool 5516905344SAndreas Gohr */ 56d868eb89SAndreas Gohrfunction load_autoload($name) 57d868eb89SAndreas Gohr{ 5816905344SAndreas Gohr static $classes = null; 5924870174SAndreas Gohr if ($classes === null) $classes = [ 6016905344SAndreas Gohr 'Diff' => DOKU_INC . 'inc/DifferenceEngine.php', 6116905344SAndreas Gohr 'UnifiedDiffFormatter' => DOKU_INC . 'inc/DifferenceEngine.php', 6216905344SAndreas Gohr 'TableDiffFormatter' => DOKU_INC . 'inc/DifferenceEngine.php', 6316905344SAndreas Gohr 'cache' => DOKU_INC . 'inc/cache.php', 6416905344SAndreas Gohr 'cache_parser' => DOKU_INC . 'inc/cache.php', 6516905344SAndreas Gohr 'cache_instructions' => DOKU_INC . 'inc/cache.php', 6616905344SAndreas Gohr 'cache_renderer' => DOKU_INC . 'inc/cache.php', 67e1d9dcc8SAndreas Gohr 'Input' => DOKU_INC . 'inc/Input.class.php', 6816905344SAndreas Gohr 'JpegMeta' => DOKU_INC . 'inc/JpegMeta.php', 692dcde304SAndreas Gohr 'SimplePie' => DOKU_INC . 'inc/SimplePie.php', 7016905344SAndreas Gohr 'FeedParser' => DOKU_INC . 'inc/FeedParser.php', 71f03fd957SAndreas Gohr 'SafeFN' => DOKU_INC . 'inc/SafeFN.class.php', 72c9a53c46SAndreas Gohr 'Mailer' => DOKU_INC . 'inc/Mailer.class.php', 73d2778ca9SAndreas Gohr 'Doku_Handler' => DOKU_INC . 'inc/parser/handler.php', 742ada8709SChristopher Smith 'Doku_Renderer' => DOKU_INC . 'inc/parser/renderer.php', 752ada8709SChristopher Smith 'Doku_Renderer_xhtml' => DOKU_INC . 'inc/parser/xhtml.php', 762ada8709SChristopher Smith 'Doku_Renderer_code' => DOKU_INC . 'inc/parser/code.php', 772ada8709SChristopher Smith 'Doku_Renderer_xhtmlsummary' => DOKU_INC . 'inc/parser/xhtmlsummary.php', 7824870174SAndreas Gohr 'Doku_Renderer_metadata' => DOKU_INC . 'inc/parser/metadata.php' 7924870174SAndreas Gohr ]; 8016905344SAndreas Gohr 8116905344SAndreas Gohr if (isset($classes[$name])) { 828a58013eSDavid Stone require($classes[$name]); 838a58013eSDavid Stone return true; 8416905344SAndreas Gohr } 85d54ac877SAdrian Lang 86b89dfc20SAndreas Gohr // namespace to directory conversion 87e7a32b17SAndreas Gohr $name = str_replace('\\', '/', $name); 88e7a32b17SAndreas Gohr 89ec85aeb2SAndreas Gohr // test mock namespace 90ec85aeb2SAndreas Gohr if (substr($name, 0, 19) === 'dokuwiki/test/mock/') { 91ec85aeb2SAndreas Gohr $file = DOKU_INC . '_test/mock/' . substr($name, 19) . '.php'; 92ec85aeb2SAndreas Gohr if (file_exists($file)) { 93ec85aeb2SAndreas Gohr require $file; 94ec85aeb2SAndreas Gohr return true; 95ec85aeb2SAndreas Gohr } 96ec85aeb2SAndreas Gohr } 97ec85aeb2SAndreas Gohr 98ec85aeb2SAndreas Gohr // tests namespace 9968f88d34SAndreas Gohr if (substr($name, 0, 14) === 'dokuwiki/test/') { 100ec85aeb2SAndreas Gohr $file = DOKU_INC . '_test/tests/' . substr($name, 14) . '.php'; 101a087da71SAndreas Gohr if (file_exists($file)) { 102a087da71SAndreas Gohr require $file; 103a087da71SAndreas Gohr return true; 104a087da71SAndreas Gohr } 105a087da71SAndreas Gohr } 106a087da71SAndreas Gohr 107600fb65eSAndreas Gohr // plugin namespace 10868f88d34SAndreas Gohr if (substr($name, 0, 16) === 'dokuwiki/plugin/') { 109600fb65eSAndreas Gohr $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace 110b00eb817SAndreas Gohr $file = DOKU_PLUGIN . substr($name, 16) . '.php'; 111600fb65eSAndreas Gohr if (file_exists($file)) { 112ffa84f81SAndreas Gohr try { 113600fb65eSAndreas Gohr require $file; 114ffa84f81SAndreas Gohr } catch (\Throwable $e) { 11524870174SAndreas Gohr ErrorHandler::showExceptionMsg($e, "Error loading plugin $name"); 116ffa84f81SAndreas Gohr } 117600fb65eSAndreas Gohr return true; 118600fb65eSAndreas Gohr } 119600fb65eSAndreas Gohr } 120600fb65eSAndreas Gohr 121f83f0fd0SAndreas Gohr // template namespace 12268f88d34SAndreas Gohr if (substr($name, 0, 18) === 'dokuwiki/template/') { 123f83f0fd0SAndreas Gohr $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace 124f83f0fd0SAndreas Gohr $file = DOKU_INC . 'lib/tpl/' . substr($name, 18) . '.php'; 125f83f0fd0SAndreas Gohr if (file_exists($file)) { 126ffa84f81SAndreas Gohr try { 127f83f0fd0SAndreas Gohr require $file; 128ffa84f81SAndreas Gohr } catch (\Throwable $e) { 12924870174SAndreas Gohr ErrorHandler::showExceptionMsg($e, "Error loading template $name"); 130ffa84f81SAndreas Gohr } 131f83f0fd0SAndreas Gohr return true; 132f83f0fd0SAndreas Gohr } 133f83f0fd0SAndreas Gohr } 134f83f0fd0SAndreas Gohr 135b89dfc20SAndreas Gohr // our own namespace 13668f88d34SAndreas Gohr if (substr($name, 0, 9) === 'dokuwiki/') { 137b16ddc6eSAndreas Gohr $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php'; 138b16ddc6eSAndreas Gohr if (file_exists($file)) { 139b16ddc6eSAndreas Gohr require $file; 140b89dfc20SAndreas Gohr return true; 141b89dfc20SAndreas Gohr } 142b16ddc6eSAndreas Gohr } 143b89dfc20SAndreas Gohr 144d54ac877SAdrian Lang // Plugin loading 1457d34963bSAndreas Gohr if ( 1467d34963bSAndreas Gohr preg_match( 1471935a891SAndreas Gohr '/^(' . implode('|', PluginController::PLUGIN_TYPES) . ')_plugin_(' . 14864159a61SAndreas Gohr DOKU_PLUGIN_NAME_REGEX . 14964159a61SAndreas Gohr ')(?:_([^_]+))?$/', 15064159a61SAndreas Gohr $name, 15164159a61SAndreas Gohr $m 1527d34963bSAndreas Gohr ) 1537d34963bSAndreas Gohr ) { 154d54ac877SAdrian Lang // try to load the wanted plugin file 155d54ac877SAdrian Lang $c = ((count($m) === 4) ? "/{$m[3]}" : ''); 1565a9866e9SAndreas Gohr $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php"; 15779e79377SAndreas Gohr if (file_exists($plg)) { 158ffa84f81SAndreas Gohr try { 159ce949263SAndreas Gohr require $plg; 160ffa84f81SAndreas Gohr } catch (\Throwable $e) { 16124870174SAndreas Gohr ErrorHandler::showExceptionMsg($e, "Error loading plugin {$m[2]}"); 162ffa84f81SAndreas Gohr } 1635a9866e9SAndreas Gohr } 1648a58013eSDavid Stone return true; 165d54ac877SAdrian Lang } 166ce949263SAndreas Gohr return false; 16716905344SAndreas Gohr} 168