farm.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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(dirname(__FILE__).'/../').'/');
  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. // htaccess based or cli
  45. // cli usage example: animal=your_animal bin/indexer.php
  46. if(isset($_GET['animal']) || ('cli' == php_sapi_name() && isset($_SERVER['animal']))) {
  47. $mode = isset($_GET['animal']) ? 'htaccess' : 'cli';
  48. $animal = $mode == 'htaccess' ? $_GET['animal'] : $_SERVER['animal'];
  49. if(isset($_GET['animal'])) {
  50. // now unset the parameter to not leak into new queries
  51. // code by @splitbrain from farmer plugin
  52. unset($_GET['animal']);
  53. $params = [];
  54. parse_str($_SERVER['QUERY_STRING'], $params);
  55. if (isset($params['animal'])) unset($params['animal']);
  56. $_SERVER['QUERY_STRING'] = http_build_query($params);
  57. }
  58. // check that $animal is a string and just a directory name and not a path
  59. if (!is_string($animal) || strpbrk($animal, '\\/') !== false)
  60. nice_die('Sorry! Invalid animal name!');
  61. if(!is_dir($farm.'/'.$animal))
  62. nice_die("Sorry! This Wiki doesn't exist!");
  63. if(!defined('DOKU_FARM')) define('DOKU_FARM', $mode);
  64. return $farm.'/'.$animal.'/conf/';
  65. }
  66. // virtual host based
  67. $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']);
  68. $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
  69. for ($i = count($uri) - 1; $i > 0; $i--) {
  70. for ($j = count($server); $j > 0; $j--) {
  71. $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
  72. if(is_dir("$farm/$dir/conf/")) {
  73. if(!defined('DOKU_FARM')) define('DOKU_FARM', 'virtual');
  74. return "$farm/$dir/conf/";
  75. }
  76. }
  77. }
  78. // default conf directory in farm
  79. if(is_dir("$farm/default/conf/")) {
  80. if(!defined('DOKU_FARM')) define('DOKU_FARM', 'default');
  81. return "$farm/default/conf/";
  82. }
  83. // farmer
  84. return DOKU_INC.'conf/';
  85. }
  86. /* Use default config files and local animal config files */
  87. $config_cascade = array(
  88. 'main' => array(
  89. 'default' => array(DOKU_INC.'conf/dokuwiki.php'),
  90. 'local' => array(DOKU_CONF.'local.php'),
  91. 'protected' => array(DOKU_CONF.'local.protected.php'),
  92. ),
  93. 'acronyms' => array(
  94. 'default' => array(DOKU_INC.'conf/acronyms.conf'),
  95. 'local' => array(DOKU_CONF.'acronyms.local.conf'),
  96. ),
  97. 'entities' => array(
  98. 'default' => array(DOKU_INC.'conf/entities.conf'),
  99. 'local' => array(DOKU_CONF.'entities.local.conf'),
  100. ),
  101. 'interwiki' => array(
  102. 'default' => array(DOKU_INC.'conf/interwiki.conf'),
  103. 'local' => array(DOKU_CONF.'interwiki.local.conf'),
  104. ),
  105. 'license' => array(
  106. 'default' => array(DOKU_INC.'conf/license.php'),
  107. 'local' => array(DOKU_CONF.'license.local.php'),
  108. ),
  109. 'mediameta' => array(
  110. 'default' => array(DOKU_INC.'conf/mediameta.php'),
  111. 'local' => array(DOKU_CONF.'mediameta.local.php'),
  112. ),
  113. 'mime' => array(
  114. 'default' => array(DOKU_INC.'conf/mime.conf'),
  115. 'local' => array(DOKU_CONF.'mime.local.conf'),
  116. ),
  117. 'scheme' => array(
  118. 'default' => array(DOKU_INC.'conf/scheme.conf'),
  119. 'local' => array(DOKU_CONF.'scheme.local.conf'),
  120. ),
  121. 'smileys' => array(
  122. 'default' => array(DOKU_INC.'conf/smileys.conf'),
  123. 'local' => array(DOKU_CONF.'smileys.local.conf'),
  124. ),
  125. 'wordblock' => array(
  126. 'default' => array(DOKU_INC.'conf/wordblock.conf'),
  127. 'local' => array(DOKU_CONF.'wordblock.local.conf'),
  128. ),
  129. 'acl' => array(
  130. 'default' => DOKU_CONF.'acl.auth.php',
  131. ),
  132. 'plainauth.users' => array(
  133. 'default' => DOKU_CONF.'users.auth.php',
  134. ),
  135. 'plugins' => array( // needed since Angua
  136. 'default' => array(DOKU_INC.'conf/plugins.php'),
  137. 'local' => array(DOKU_CONF.'plugins.local.php'),
  138. 'protected' => array(
  139. DOKU_INC.'conf/plugins.required.php',
  140. DOKU_CONF.'plugins.protected.php',
  141. ),
  142. ),
  143. 'userstyle' => array(
  144. 'screen' => array(DOKU_CONF . 'userstyle.css', DOKU_CONF . 'userstyle.less'),
  145. 'print' => array(DOKU_CONF . 'userprint.css', DOKU_CONF . 'userprint.less'),
  146. 'feed' => array(DOKU_CONF . 'userfeed.css', DOKU_CONF . 'userfeed.less'),
  147. 'all' => array(DOKU_CONF . 'userall.css', DOKU_CONF . 'userall.less')
  148. ),
  149. 'userscript' => array(
  150. 'default' => array(DOKU_CONF . 'userscript.js')
  151. ),
  152. );