You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

159 lines
6.4 KiB

  1. <?php
  2. /**
  3. * This overwrites DOKU_CONF. Each animal gets its own configuration and data directory.
  4. * This can be used together with preload.php. See preload.php.dist for an example setup.
  5. * For more information see http://www.dokuwiki.org/farms.
  6. *
  7. * The farm directory (constant DOKU_FARMDIR) can be any directory and needs to be set.
  8. * Animals are direct subdirectories of the farm directory.
  9. * There are two different approaches:
  10. * * An .htaccess based setup can use any animal directory name:
  11. * http://example.org/<path_to_farm>/subdir/ will need the subdirectory '$farm/subdir/'.
  12. * * A virtual host based setup needs animal directory names which have to reflect
  13. * the domain name: If an animal resides in http://www.example.org:8080/mysite/test/,
  14. * directories that will match range from '$farm/8080.www.example.org.mysite.test/'
  15. * to a simple '$farm/domain/'.
  16. *
  17. * @author Anika Henke <anika@selfthinker.org>
  18. * @author Michael Klier <chi@chimeric.de>
  19. * @author Christopher Smith <chris@jalakai.co.uk>
  20. * @author virtual host part of farm_confpath() based on conf_path() from Drupal.org's /includes/bootstrap.inc
  21. * (see https://github.com/drupal/drupal/blob/7.x/includes/bootstrap.inc#L537)
  22. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  23. */
  24. // DOKU_FARMDIR needs to be set in preload.php, the fallback is the same as DOKU_INC would be (if it was set already)
  25. if (!defined('DOKU_FARMDIR')) define('DOKU_FARMDIR', fullpath(__DIR__ . '/../') . '/');
  26. if (!defined('DOKU_CONF')) define('DOKU_CONF', farm_confpath(DOKU_FARMDIR));
  27. if (!defined('DOKU_FARM')) define('DOKU_FARM', false);
  28. /**
  29. * Find the appropriate configuration directory.
  30. *
  31. * If the .htaccess based setup is used, the configuration directory can be
  32. * any subdirectory of the farm directory.
  33. *
  34. * Otherwise try finding a matching configuration directory by stripping the
  35. * website's hostname from left to right and pathname from right to left. The
  36. * first configuration file found will be used; the remaining will ignored.
  37. * If no configuration file is found, return the default confdir './conf'.
  38. *
  39. * @param string $farm
  40. *
  41. * @return string
  42. */
  43. function farm_confpath($farm)
  44. {
  45. // htaccess based or cli
  46. // cli usage example: animal=your_animal bin/indexer.php
  47. if (isset($_GET['animal']) || ('cli' == PHP_SAPI && isset($_SERVER['animal']))) {
  48. $mode = isset($_GET['animal']) ? 'htaccess' : 'cli';
  49. $animal = $mode == 'htaccess' ? $_GET['animal'] : $_SERVER['animal'];
  50. if (isset($_GET['animal'])) {
  51. // now unset the parameter to not leak into new queries
  52. // code by @splitbrain from farmer plugin
  53. unset($_GET['animal']);
  54. $params = [];
  55. parse_str($_SERVER['QUERY_STRING'], $params);
  56. if (isset($params['animal'])) unset($params['animal']);
  57. $_SERVER['QUERY_STRING'] = http_build_query($params);
  58. }
  59. // check that $animal is a string and just a directory name and not a path
  60. if (!is_string($animal) || strpbrk($animal, '\\/') !== false)
  61. nice_die('Sorry! Invalid animal name!');
  62. if (!is_dir($farm . '/' . $animal))
  63. nice_die("Sorry! This Wiki doesn't exist!");
  64. if (!defined('DOKU_FARM')) define('DOKU_FARM', $mode);
  65. return $farm . '/' . $animal . '/conf/';
  66. }
  67. // virtual host based
  68. $uri = explode('/', $_SERVER['SCRIPT_NAME'] ?: $_SERVER['SCRIPT_FILENAME']);
  69. $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
  70. for ($i = count($uri) - 1; $i > 0; $i--) {
  71. for ($j = count($server); $j > 0; $j--) {
  72. $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
  73. if (is_dir("$farm/$dir/conf/")) {
  74. if (!defined('DOKU_FARM')) define('DOKU_FARM', 'virtual');
  75. return "$farm/$dir/conf/";
  76. }
  77. }
  78. }
  79. // default conf directory in farm
  80. if (is_dir("$farm/default/conf/")) {
  81. if (!defined('DOKU_FARM')) define('DOKU_FARM', 'default');
  82. return "$farm/default/conf/";
  83. }
  84. // farmer
  85. return DOKU_INC . 'conf/';
  86. }
  87. /* Use default config files and local animal config files */
  88. $config_cascade = [
  89. 'main' => [
  90. 'default' => [DOKU_INC . 'conf/dokuwiki.php'],
  91. 'local' => [DOKU_CONF . 'local.php'],
  92. 'protected' => [DOKU_CONF . 'local.protected.php']
  93. ],
  94. 'acronyms' => [
  95. 'default' => [DOKU_INC . 'conf/acronyms.conf'],
  96. 'local' => [DOKU_CONF . 'acronyms.local.conf']
  97. ],
  98. 'entities' => [
  99. 'default' => [DOKU_INC . 'conf/entities.conf'],
  100. 'local' => [DOKU_CONF . 'entities.local.conf']
  101. ],
  102. 'interwiki' => [
  103. 'default' => [DOKU_INC . 'conf/interwiki.conf'],
  104. 'local' => [DOKU_CONF . 'interwiki.local.conf']
  105. ],
  106. 'license' => [
  107. 'default' => [DOKU_INC . 'conf/license.php'],
  108. 'local' => [DOKU_CONF . 'license.local.php']
  109. ],
  110. 'mediameta' => [
  111. 'default' => [DOKU_INC . 'conf/mediameta.php'],
  112. 'local' => [DOKU_CONF . 'mediameta.local.php']
  113. ],
  114. 'mime' => [
  115. 'default' => [DOKU_INC . 'conf/mime.conf'],
  116. 'local' => [DOKU_CONF . 'mime.local.conf']
  117. ],
  118. 'scheme' => [
  119. 'default' => [DOKU_INC . 'conf/scheme.conf'],
  120. 'local' => [DOKU_CONF . 'scheme.local.conf']
  121. ],
  122. 'smileys' => [
  123. 'default' => [DOKU_INC . 'conf/smileys.conf'],
  124. 'local' => [DOKU_CONF . 'smileys.local.conf']
  125. ],
  126. 'wordblock' => [
  127. 'default' => [DOKU_INC . 'conf/wordblock.conf'],
  128. 'local' => [DOKU_CONF . 'wordblock.local.conf']
  129. ],
  130. 'acl' => [
  131. 'default' => DOKU_CONF . 'acl.auth.php'
  132. ],
  133. 'plainauth.users' => [
  134. 'default' => DOKU_CONF . 'users.auth.php'
  135. ],
  136. 'plugins' => [
  137. // needed since Angua
  138. 'default' => [DOKU_INC . 'conf/plugins.php'],
  139. 'local' => [DOKU_CONF . 'plugins.local.php'],
  140. 'protected' => [DOKU_INC . 'conf/plugins.required.php', DOKU_CONF . 'plugins.protected.php'],
  141. ],
  142. 'userstyle' => [
  143. 'screen' => [DOKU_CONF . 'userstyle.css', DOKU_CONF . 'userstyle.less'],
  144. 'print' => [DOKU_CONF . 'userprint.css', DOKU_CONF . 'userprint.less'],
  145. 'feed' => [DOKU_CONF . 'userfeed.css', DOKU_CONF . 'userfeed.less'],
  146. 'all' => [DOKU_CONF . 'userall.css', DOKU_CONF . 'userall.less']
  147. ],
  148. 'userscript' => [
  149. 'default' => [DOKU_CONF . 'userscript.js']
  150. ]
  151. ];