[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/ -> load.php (source)

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