Mereged updates from DokuWiki 38
[sudaraka-org:dokuwiki-mods.git] / inc / farm.php
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 http://cvs.drupal.org/viewvc/drupal/drupal/includes/bootstrap.inc?view=markup)
22  * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
23 */
24
25 // DOKU_FARMDIR needs to be set in preload.php, here the fallback is the same as DOKU_INC would be (if it was set already)
26 if(!defined('DOKU_FARMDIR')) define('DOKU_FARMDIR', fullpath(dirname(__FILE__).'/../').'/');
27 if(!defined('DOKU_CONF')) define('DOKU_CONF', farm_confpath(DOKU_FARMDIR));
28 if(!defined('DOKU_FARM')) define('DOKU_FARM', false);
29
30
31 /**
32  * Find the appropriate configuration directory.
33  *
34  * If the .htaccess based setup is used, the configuration directory can be
35  * any subdirectory of the farm directory.
36  *
37  * Otherwise try finding a matching configuration directory by stripping the
38  * website's hostname from left to right and pathname from right to left. The
39  * first configuration file found will be used; the remaining will ignored.
40  * If no configuration file is found, return the default confdir './conf'.
41  */
42 function farm_confpath($farm) {
43
44     // htaccess based or cli
45     // cli usage example: animal=your_animal bin/indexer.php
46     if(isset($_REQUEST['animal']) || ('cli' == php_sapi_name() && isset($_SERVER['animal']))) {
47         $mode = isset($_REQUEST['animal']) ? 'htaccess' : 'cli';
48         $animal = $mode == 'htaccess' ? $_REQUEST['animal'] : $_SERVER['animal'];
49         // check that $animal is a string and just a directory name and not a path
50         if (!is_string($animal) || strpbrk($animal, '\\/') !== false)
51             nice_die('Sorry! Invalid animal name!');
52         if(!is_dir($farm.'/'.$animal))
53             nice_die("Sorry! This Wiki doesn't exist!");
54         if(!defined('DOKU_FARM')) define('DOKU_FARM', $mode);
55         return $farm.'/'.$animal.'/conf/';
56     }
57
58     // virtual host based
59     $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']);
60     $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
61     for ($i = count($uri) - 1; $i > 0; $i--) {
62         for ($j = count($server); $j > 0; $j--) {
63             $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
64             if(is_dir("$farm/$dir/conf/")) {
65                 if(!defined('DOKU_FARM')) define('DOKU_FARM', 'virtual');
66                 return "$farm/$dir/conf/";
67             }
68         }
69     }
70
71     // default conf directory in farm
72     if(is_dir("$farm/default/conf/")) {
73         if(!defined('DOKU_FARM')) define('DOKU_FARM', 'default');
74         return "$farm/default/conf/";
75     }
76     // farmer
77     return DOKU_INC.'conf/';
78 }
79
80 /* Use default config files and local animal config files */
81 $config_cascade = array(
82     'main' => array(
83         'default'   => array(DOKU_INC.'conf/dokuwiki.php'),
84         'local'     => array(DOKU_CONF.'local.php'),
85         'protected' => array(DOKU_CONF.'local.protected.php'),
86     ),
87     'acronyms'  => array(
88         'default'   => array(DOKU_INC.'conf/acronyms.conf'),
89         'local'     => array(DOKU_CONF.'acronyms.local.conf'),
90     ),
91     'entities'  => array(
92         'default'   => array(DOKU_INC.'conf/entities.conf'),
93         'local'     => array(DOKU_CONF.'entities.local.conf'),
94     ),
95     'interwiki' => array(
96         'default'   => array(DOKU_INC.'conf/interwiki.conf'),
97         'local'     => array(DOKU_CONF.'interwiki.local.conf'),
98     ),
99     'license' => array(
100         'default'   => array(DOKU_INC.'conf/license.php'),
101         'local'     => array(DOKU_CONF.'license.local.php'),
102     ),
103     'mediameta' => array(
104         'default'   => array(DOKU_INC.'conf/mediameta.php'),
105         'local'     => array(DOKU_CONF.'mediameta.local.php'),
106     ),
107     'mime'      => array(
108         'default'   => array(DOKU_INC.'conf/mime.conf'),
109         'local'     => array(DOKU_CONF.'mime.local.conf'),
110     ),
111     'scheme'    => array(
112         'default'   => array(DOKU_INC.'conf/scheme.conf'),
113         'local'     => array(DOKU_CONF.'scheme.local.conf'),
114     ),
115     'smileys'   => array(
116         'default'   => array(DOKU_INC.'conf/smileys.conf'),
117         'local'     => array(DOKU_CONF.'smileys.local.conf'),
118     ),
119     'wordblock' => array(
120         'default'   => array(DOKU_INC.'conf/wordblock.conf'),
121         'local'     => array(DOKU_CONF.'wordblock.local.conf'),
122     ),
123     'acl'       => array(
124         'default'   => DOKU_CONF.'acl.auth.php',
125     ),
126     'plainauth.users' => array(
127         'default'   => DOKU_CONF.'users.auth.php',
128     ),
129     'plugins' => array( // needed since Angua
130         'default'   => array(DOKU_INC.'conf/plugins.php'),
131         'local'     => array(DOKU_CONF.'plugins.local.php'),
132         'protected' => array(
133             DOKU_INC.'conf/plugins.required.php',
134             DOKU_CONF.'plugins.protected.php',
135         ),
136     ),
137     'userstyle' => array(
138         'default' => DOKU_CONF.'userstyle.css', // 'default' was renamed to 'screen' on 2011-02-26, so will be deprecated in the next version
139         'screen'  => DOKU_CONF.'userstyle.css',
140         'rtl'     => DOKU_CONF.'userrtl.css', // deprecated since version after 2012-04-09
141         'print'   => DOKU_CONF.'userprint.css',
142         'feed'    => DOKU_CONF.'userfeed.css',
143         'all'     => DOKU_CONF.'userall.css',
144     ),
145     'userscript' => array(
146         'default' => DOKU_CONF.'userscript.js'
147     ),
148 );