xref: /dokuwiki/inc/farm.php (revision bb853ec32133da0147618382c031cd09e4512c50)
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 *
6 * The farm ($farm) can be any directory and needs to be set.
7 * Animals are direct subdirectories of the farm directory.
8 * There are two different approaches:
9 *  * An .htaccess based setup can use any animal directory name:
10 *    http://example.org/<path_to_farm>/subdir/ will need the subdirectory '$farm/subdir/'.
11 *  * A virtual host based setup needs animal directory names which have to reflect
12 *    the domain name: If an animal resides in http://www.example.org:8080/mysite/test/,
13 *    directories that will match range from '$farm/8080.www.example.org.mysite.test/'
14 *    to a simple '$farm/domain/'.
15 *
16 * @author Anika Henke <anika@selfthinker.org>
17 * @author Michael Klier <chi@chimeric.de>
18 * @author Christopher Smith <chris@jalakai.co.uk>
19 * @author virtual host part of conf_path() based on conf_path() from Drupal.org's /includes/bootstrap.inc
20 *   (see http://cvs.drupal.org/viewvc/drupal/drupal/includes/bootstrap.inc?view=markup)
21 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
22*/
23
24// DOKU_FARMDIR needs to be set in preload.php, here the fallback is the same as DOKU_INC (which isn't set yet)
25if(!defined('DOKU_FARMDIR')) define('DOKU_FARMDIR', fullpath(dirname(__FILE__).'/../').'/');
26if(!defined('DOKU_CONF')) define('DOKU_CONF', conf_path(DOKU_FARMDIR));
27if(!defined('DOKU_FARM')) define('DOKU_FARM', false);
28
29
30/**
31 * Find the appropriate configuration directory.
32 *
33 * If the .htaccess based setup is used, the configuration directory can be
34 * any subdirectory of the farm directory.
35 *
36 * Otherwise try finding a matching configuration directory by stripping the
37 * website's hostname from left to right and pathname from right to left. The
38 * first configuration file found will be used; the remaining will ignored.
39 * If no configuration file is found, return the default confdir './conf'.
40 */
41function conf_path($farm) {
42
43    // htaccess based
44    if(isset($_REQUEST['animal'])) {
45        if(!is_dir($farm.'/'.$_REQUEST['animal']))
46            nice_die("Sorry! This Wiki doesn't exist!");
47        if(!defined('DOKU_FARM')) define('DOKU_FARM', 'htaccess');
48        return $farm.'/'.$_REQUEST['animal'].'/conf/';
49    }
50
51    // virtual host based
52    $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']);
53    $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
54    for ($i = count($uri) - 1; $i > 0; $i--) {
55        for ($j = count($server); $j > 0; $j--) {
56            $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
57            if(is_dir("$farm/$dir/conf/")) {
58                if(!defined('DOKU_FARM')) define('DOKU_FARM', 'virtual');
59                return "$farm/$dir/conf/";
60            }
61        }
62    }
63
64    // default conf directory in farm
65    if(is_dir("$farm/default/conf/")) {
66        if(!defined('DOKU_FARM')) define('DOKU_FARM', 'default');
67        return "$farm/default/conf/";
68    }
69    // farmer
70    return DOKU_INC.'conf/';
71}
72
73/* Use default config files and local animal config files */
74$config_cascade = array(
75    'main' => array(
76        'default'   => array(DOKU_INC.'conf/dokuwiki.php'),
77        'local'     => array(DOKU_CONF.'local.php'),
78        'protected' => array(DOKU_CONF.'local.protected.php'),
79    ),
80    'acronyms'  => array(
81        'default'   => array(DOKU_INC.'conf/acronyms.conf'),
82        'local'     => array(DOKU_CONF.'acronyms.local.conf'),
83    ),
84    'entities'  => array(
85        'default'   => array(DOKU_INC.'conf/entities.conf'),
86        'local'     => array(DOKU_CONF.'entities.local.conf'),
87    ),
88    'interwiki' => array(
89        'default'   => array(DOKU_INC.'conf/interwiki.conf'),
90        'local'     => array(DOKU_CONF.'interwiki.local.conf'),
91    ),
92    'license' => array(
93        'default'   => array(DOKU_INC.'conf/license.php'),
94        'local'     => array(DOKU_CONF.'license.local.php'),
95    ),
96    'mediameta' => array(
97        'default'   => array(DOKU_INC.'conf/mediameta.php'),
98        'local'     => array(DOKU_CONF.'mediameta.local.php'),
99    ),
100    'mime'      => array(
101        'default'   => array(DOKU_INC.'conf/mime.conf'),
102        'local'     => array(DOKU_CONF.'mime.local.conf'),
103    ),
104    'scheme'    => array(
105        'default'   => array(DOKU_INC.'conf/scheme.conf'),
106        'local'     => array(DOKU_CONF.'scheme.local.conf'),
107    ),
108    'smileys'   => array(
109        'default'   => array(DOKU_INC.'conf/smileys.conf'),
110        'local'     => array(DOKU_CONF.'smileys.local.conf'),
111    ),
112    'wordblock' => array(
113        'default'   => array(DOKU_INC.'conf/wordblock.conf'),
114        'local'     => array(DOKU_CONF.'wordblock.local.conf'),
115    ),
116    'acl'       => array(
117        'default'   => DOKU_CONF.'acl.auth.php',
118    ),
119    'plainauth.users' => array(
120        'default'   => DOKU_CONF.'users.auth.php',
121    ),
122    'plugins' => array( // needed since Angua
123        'default'   => array(DOKU_CONF.'plugins.php'),
124        'local'     => array(DOKU_CONF.'plugins.local.php'),
125        'protected' => array(
126            DOKU_INC.'conf/plugins.required.php',
127            DOKU_CONF.'plugins.protected.php',
128        ),
129    ),
130    'userstyle' => array(
131        'default' => DOKU_CONF.'userstyle.css', // 'default' was renamed to 'screen' on 2011-02-26, so will be deprecated in the next version
132        'screen'  => DOKU_CONF.'userstyle.css',
133        'rtl'     => DOKU_CONF.'userrtl.css', // deprecated since version after 2012-04-09
134        'print'   => DOKU_CONF.'userprint.css',
135        'feed'    => DOKU_CONF.'userfeed.css',
136        'all'     => DOKU_CONF.'userall.css',
137    ),
138    'userscript' => array(
139        'default' => DOKU_CONF.'userscript.js'
140    ),
141);
142