3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 //exit with 200 response, if this is checking fancy from the installer
23 if (isset($_REQUEST['p']) && $_REQUEST['p'] == 'check-fancy') { exit; }
25 define('STATUSNET_VERSION', '0.9.0rc2');
26 define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility
28 define('STATUSNET_CODENAME', 'Stand');
30 define('AVATAR_PROFILE_SIZE', 96);
31 define('AVATAR_STREAM_SIZE', 48);
32 define('AVATAR_MINI_SIZE', 24);
34 define('NOTICES_PER_PAGE', 20);
35 define('PROFILES_PER_PAGE', 20);
37 define('FOREIGN_NOTICE_SEND', 1);
38 define('FOREIGN_NOTICE_RECV', 2);
39 define('FOREIGN_NOTICE_SEND_REPLY', 4);
41 define('FOREIGN_FRIEND_SEND', 1);
42 define('FOREIGN_FRIEND_RECV', 2);
44 # append our extlib dir as the last-resort place to find libs
46 set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/');
48 // To protect against upstream libraries which haven't updated
49 // for PHP 5.3 where dl() function may not be present...
50 if (!function_exists('dl')) {
51 // function_exists() returns false for things in disable_functions,
52 // but they still exist and we'll die if we try to redefine them.
54 // Fortunately trying to call the disabled one will only trigger
55 // a warning, not a fatal, so it's safe to leave it for our case.
56 // Callers will be suppressing warnings anyway.
57 $disabled = array_filter(array_map('trim', explode(',', ini_get('disable_functions'))));
58 if (!in_array('dl', $disabled)) {
59 function dl($library) {
65 # global configuration object
67 require_once('PEAR.php');
68 require_once('DB/DataObject.php');
69 require_once('DB/DataObject/Cast.php'); # for dates
71 require_once(INSTALLDIR.'/lib/language.php');
73 // This gets included before the config file, so that admin code and plugins
76 require_once(INSTALLDIR.'/lib/event.php');
77 require_once(INSTALLDIR.'/lib/plugin.php');
79 function _sn_to_path($sn)
81 $past_root = substr($sn, 1);
82 $last_slash = strrpos($past_root, '/');
83 if ($last_slash > 0) {
84 $p = substr($past_root, 0, $last_slash);
91 // Save our sanity when code gets loaded through subroutines such as PHPUnit tests
92 global $default, $config, $_server, $_path;
94 // try to figure out where we are. $server and $path
95 // can be set by including module, else we guess based
101 $_server = array_key_exists('SERVER_NAME', $_SERVER) ?
102 strtolower($_SERVER['SERVER_NAME']) :
109 $_path = (array_key_exists('SERVER_NAME', $_SERVER) && array_key_exists('SCRIPT_NAME', $_SERVER)) ?
110 _sn_to_path($_SERVER['SCRIPT_NAME']) :
114 require_once(INSTALLDIR.'/lib/default.php');
116 // Set config values initially to default values
120 // default configuration, overwritten in config.php
122 $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
124 $config['db'] = $default['db'];
126 // Backward compatibility
128 $config['site']['design'] =& $config['design'];
130 if (function_exists('date_default_timezone_set')) {
131 /* Work internally in UTC */
132 date_default_timezone_set('UTC');
135 function addPlugin($name, $attrs = null)
137 $name = ucfirst($name);
138 $pluginclass = "{$name}Plugin";
140 if (!class_exists($pluginclass)) {
142 $files = array("local/plugins/{$pluginclass}.php",
143 "local/plugins/{$name}/{$pluginclass}.php",
144 "local/{$pluginclass}.php",
145 "local/{$name}/{$pluginclass}.php",
146 "plugins/{$pluginclass}.php",
147 "plugins/{$name}/{$pluginclass}.php");
149 foreach ($files as $file) {
150 $fullpath = INSTALLDIR.'/'.$file;
151 if (@file_exists($fullpath)) {
152 include_once($fullpath);
158 $inst = new $pluginclass();
160 if (!empty($attrs)) {
161 foreach ($attrs as $aname => $avalue) {
162 $inst->$aname = $avalue;
168 // From most general to most specific:
169 // server-wide, then vhost-wide, then for a path,
170 // finally for a dir (usually only need one of the last two).
172 if (isset($conffile)) {
173 $_config_files = array($conffile);
175 $_config_files = array('/etc/statusnet/statusnet.php',
176 '/etc/statusnet/laconica.php',
177 '/etc/laconica/laconica.php',
178 '/etc/statusnet/'.$_server.'.php',
179 '/etc/laconica/'.$_server.'.php');
181 if (strlen($_path) > 0) {
182 $_config_files[] = '/etc/statusnet/'.$_server.'_'.$_path.'.php';
183 $_config_files[] = '/etc/laconica/'.$_server.'_'.$_path.'.php';
186 $_config_files[] = INSTALLDIR.'/config.php';
189 global $_have_a_config;
190 $_have_a_config = false;
192 foreach ($_config_files as $_config_file) {
193 if (@file_exists($_config_file)) {
194 include_once($_config_file);
195 $_have_a_config = true;
199 function _have_config()
201 global $_have_a_config;
202 return $_have_a_config;
205 // XXX: Throw a conniption if database not installed
206 // XXX: Find a way to use htmlwriter for this instead of handcoded markup
207 if (!_have_config()) {
208 echo '<p>'. _('No configuration file found. ') .'</p>';
209 echo '<p>'. _('I looked for configuration files in the following places: ') .'<br /> '. implode($_config_files, '<br />');
210 echo '<p>'. _('You may wish to run the installer to fix this.') .'</p>';
211 echo '<a href="install.php">'. _('Go to the installer.') .'</a>';
214 // Fixup for statusnet.ini
216 $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1);
218 if ($_db_name != 'statusnet' && !array_key_exists('ini_'.$_db_name, $config['db'])) {
219 $config['db']['ini_'.$_db_name] = INSTALLDIR.'/classes/statusnet.ini';
222 // Backwards compatibility
224 if (array_key_exists('memcached', $config)) {
225 if ($config['memcached']['enabled']) {
226 addPlugin('Memcache', array('servers' => $config['memcached']['server']));
229 if (!empty($config['memcached']['base'])) {
230 $config['cache']['base'] = $config['memcached']['base'];
234 function __autoload($cls)
236 if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) {
237 require_once(INSTALLDIR.'/classes/' . $cls . '.php');
238 } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($cls) . '.php')) {
239 require_once(INSTALLDIR.'/lib/' . strtolower($cls) . '.php');
240 } else if (mb_substr($cls, -6) == 'Action' &&
241 file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php')) {
242 require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
243 } else if ($cls == 'OAuthRequest') {
244 require_once('OAuth.php');
246 Event::handle('Autoload', array(&$cls));
250 // Load default plugins
252 foreach ($config['plugins']['default'] as $name => $params) {
253 if (is_null($params)) {
255 } else if (is_array($params)) {
256 if (count($params) == 0) {
259 $keys = array_keys($params);
260 if (is_string($keys[0])) {
261 addPlugin($name, $params);
263 foreach ($params as $paramset) {
264 addPlugin($name, $paramset);
271 // XXX: how many of these could be auto-loaded on use?
272 // XXX: note that these files should not use config options
273 // at compile time since DB config options are not yet loaded.
275 require_once 'Validate.php';
276 require_once 'markdown.php';
278 require_once INSTALLDIR.'/lib/util.php';
279 require_once INSTALLDIR.'/lib/action.php';
280 require_once INSTALLDIR.'/lib/mail.php';
281 require_once INSTALLDIR.'/lib/subs.php';
283 require_once INSTALLDIR.'/lib/clientexception.php';
284 require_once INSTALLDIR.'/lib/serverexception.php';
286 // Load settings from database; note we need autoload for this
288 Config::loadSettings();
290 // XXX: if plugins should check the schema at runtime, do that here.
292 if ($config['db']['schemacheck'] == 'runtime') {
293 Event::handle('CheckSchema');
296 // XXX: other formats here
298 define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);
300 // Give plugins a chance to initialize in a fully-prepared environment
302 Event::handle('InitializePlugin');