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 define('STATUSNET_VERSION', '0.9.0dev');
23 define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility
25 define('STATUSNET_CODENAME', 'Stand');
27 define('AVATAR_PROFILE_SIZE', 96);
28 define('AVATAR_STREAM_SIZE', 48);
29 define('AVATAR_MINI_SIZE', 24);
31 define('NOTICES_PER_PAGE', 20);
32 define('PROFILES_PER_PAGE', 20);
34 define('FOREIGN_NOTICE_SEND', 1);
35 define('FOREIGN_NOTICE_RECV', 2);
36 define('FOREIGN_NOTICE_SEND_REPLY', 4);
38 define('FOREIGN_FRIEND_SEND', 1);
39 define('FOREIGN_FRIEND_RECV', 2);
41 define_syslog_variables();
43 # append our extlib dir as the last-resort place to find libs
45 set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/');
47 # global configuration object
49 require_once('PEAR.php');
50 require_once('DB/DataObject.php');
51 require_once('DB/DataObject/Cast.php'); # for dates
53 if (!function_exists('gettext')) {
54 require_once("php-gettext/gettext.inc");
56 require_once(INSTALLDIR.'/lib/language.php');
58 // This gets included before the config file, so that admin code and plugins
61 require_once(INSTALLDIR.'/lib/event.php');
62 require_once(INSTALLDIR.'/lib/plugin.php');
64 function _sn_to_path($sn)
66 $past_root = substr($sn, 1);
67 $last_slash = strrpos($past_root, '/');
68 if ($last_slash > 0) {
69 $p = substr($past_root, 0, $last_slash);
76 // try to figure out where we are. $server and $path
77 // can be set by including module, else we guess based
83 $_server = array_key_exists('SERVER_NAME', $_SERVER) ?
84 strtolower($_SERVER['SERVER_NAME']) :
91 $_path = (array_key_exists('SERVER_NAME', $_SERVER) && array_key_exists('SCRIPT_NAME', $_SERVER)) ?
92 _sn_to_path($_SERVER['SCRIPT_NAME']) :
96 // default configuration, overwritten in config.php
100 array('name' => 'Just another StatusNet microblog',
101 'server' => $_server,
102 'theme' => 'default',
108 'locale_path' => INSTALLDIR.'/locale',
109 'language' => 'en_US',
110 'languages' => get_all_languages(),
112 array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : null,
115 'broughtbyurl' => null,
117 'inviteonly' => false,
121 'shorturllength' => 30,
122 'dupelimit' => 60, # default for same person saying the same thing
126 array('appname' => 'statusnet', # for syslog
127 'priority' => 'debug', # XXX: currently ignored
128 'facility' => LOG_USER),
130 array('enabled' => false,
131 'subsystem' => 'db', # default to database, or 'stomp'
132 'stomp_server' => null,
133 'queue_basename' => 'statusnet',
134 'stomp_username' => null,
135 'stomp_password' => null,
138 array('url' => 'http://creativecommons.org/licenses/by/3.0/',
139 'title' => 'Creative Commons Attribution 3.0',
140 'image' => 'http://i.creativecommons.org/l/by/3.0/80x15.png'),
142 array('backend' => 'mail',
145 array('blacklist' => array(),
146 'featured' => array()),
148 array('banned' => array(),
151 array('server' => null,
152 'dir' => INSTALLDIR . '/avatar/',
153 'path' => $_path . '/avatar/'),
155 array('server' => null,
156 'dir' => INSTALLDIR . '/background/',
157 'path' => $_path . '/background/'),
159 array('localonly' => true,
160 'blacklist' => array(),
161 'autosource' => array()),
163 array('server' => null,
167 array('enabled' => false, // whether to throttle edits; false by default
168 'count' => 20, // number of allowed messages in timespan
169 'timespan' => 600), // timespan for throttling
171 array('enabled' => false,
172 'server' => 'INVALID SERVER',
175 'encryption' => true,
176 'resource' => 'uniquename',
177 'password' => 'blahblahblah',
178 'host' => null, # only set if != server
179 'debug' => false, # print extra debug info
180 'public' => array()), # JIDs of users who want to receive the public stream
182 array('enabled' => true),
184 array('enabled' => false,
185 'server' => 'localhost',
188 array('dropoff' => 864000.0),
190 array('dropoff' => 864000.0),
192 array('piddir' => '/var/run',
196 array('enabled' => true),
198 array('enabled' => true),
200 array('enabled' => true),
202 array('enabled' => false),
204 array('source' => 'StatusNet', # source attribute for Twitter
205 'taguri' => $_server.',2009'), # base for tag URIs
207 array('consumer_key' => null,
208 'consumer_secret' => null),
210 array('enabled' => false,
211 'server' => 'localhost',
215 array('notify' => array()),
217 array('enabled' => true), # on by default for new sites
219 array('default' => null,
222 array('run' => 'web',
223 'frequency' => 10000,
224 'reporturl' => 'http://status.net/stats/report'),
226 array('server' => null,
227 'dir' => INSTALLDIR . '/file/',
228 'path' => $_path . '/file/',
229 'supported' => array('image/png',
237 'application/vnd.oasis.opendocument.text',
238 'application/vnd.oasis.opendocument.text-template',
239 'application/vnd.oasis.opendocument.graphics',
240 'application/vnd.oasis.opendocument.graphics-template',
241 'application/vnd.oasis.opendocument.presentation',
242 'application/vnd.oasis.opendocument.presentation-template',
243 'application/vnd.oasis.opendocument.spreadsheet',
244 'application/vnd.oasis.opendocument.spreadsheet-template',
245 'application/vnd.oasis.opendocument.chart',
246 'application/vnd.oasis.opendocument.chart-template',
247 'application/vnd.oasis.opendocument.image',
248 'application/vnd.oasis.opendocument.image-template',
249 'application/vnd.oasis.opendocument.formula',
250 'application/vnd.oasis.opendocument.formula-template',
251 'application/vnd.oasis.opendocument.text-master',
252 'application/vnd.oasis.opendocument.text-web',
260 'file_quota' => 5000000,
261 'user_quota' => 50000000,
262 'monthly_quota' => 15000000,
264 'filecommand' => '/usr/bin/file',
267 array('maxaliases' => 3,
268 'desclimit' => null),
269 'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/'),
271 array('type' => 'fulltext'),
273 array('handle' => false, // whether to handle sessions ourselves
274 'debug' => false), // debugging output for sessions
276 array('backgroundcolor' => null, // null -> 'use theme default'
277 'contentcolor' => null,
278 'sidebarcolor' => null,
281 'backgroundimage' => null,
282 'disposition' => null),
284 array('contentlimit' => null),
286 array('contentlimit' => null),
289 $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
292 array('database' => 'YOU HAVE TO SET THIS IN config.php',
293 'schema_location' => INSTALLDIR . '/classes',
294 'class_location' => INSTALLDIR . '/classes',
295 'require_prefix' => 'classes/',
296 'class_prefix' => '',
299 'db_driver' => 'DB', # XXX: JanRain libs only work with DB
300 'quote_identifiers' => false,
303 // Backward compatibility
305 $config['site']['design'] =& $config['design'];
307 if (function_exists('date_default_timezone_set')) {
308 /* Work internally in UTC */
309 date_default_timezone_set('UTC');
312 function addPlugin($name, $attrs = null)
314 $name = ucfirst($name);
315 $pluginclass = "{$name}Plugin";
317 if (!class_exists($pluginclass)) {
319 $files = array("local/plugins/{$pluginclass}.php",
320 "local/plugins/{$name}/{$pluginclass}.php",
321 "local/{$pluginclass}.php",
322 "local/{$name}/{$pluginclass}.php",
323 "plugins/{$pluginclass}.php",
324 "plugins/{$name}/{$pluginclass}.php");
326 foreach ($files as $file) {
327 $fullpath = INSTALLDIR.'/'.$file;
328 if (@file_exists($fullpath)) {
329 include_once($fullpath);
335 $inst = new $pluginclass();
337 if (!empty($attrs)) {
338 foreach ($attrs as $aname => $avalue) {
339 $inst->$aname = $avalue;
345 // From most general to most specific:
346 // server-wide, then vhost-wide, then for a path,
347 // finally for a dir (usually only need one of the last two).
349 if (isset($conffile)) {
350 $_config_files = array($conffile);
352 $_config_files = array('/etc/statusnet/statusnet.php',
353 '/etc/statusnet/laconica.php',
354 '/etc/laconica/laconica.php',
355 '/etc/statusnet/'.$_server.'.php',
356 '/etc/laconica/'.$_server.'.php');
358 if (strlen($_path) > 0) {
359 $_config_files[] = '/etc/statusnet/'.$_server.'_'.$_path.'.php';
360 $_config_files[] = '/etc/laconica/'.$_server.'_'.$_path.'.php';
363 $_config_files[] = INSTALLDIR.'/config.php';
366 $_have_a_config = false;
368 foreach ($_config_files as $_config_file) {
369 if (@file_exists($_config_file)) {
370 include_once($_config_file);
371 $_have_a_config = true;
375 function _have_config()
377 global $_have_a_config;
378 return $_have_a_config;
381 // XXX: Throw a conniption if database not installed
383 // Fixup for statusnet.ini
385 $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1);
387 if ($_db_name != 'statusnet' && !array_key_exists('ini_'.$_db_name, $config['db'])) {
388 $config['db']['ini_'.$_db_name] = INSTALLDIR.'/classes/statusnet.ini';
391 function __autoload($cls)
393 if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) {
394 require_once(INSTALLDIR.'/classes/' . $cls . '.php');
395 } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($cls) . '.php')) {
396 require_once(INSTALLDIR.'/lib/' . strtolower($cls) . '.php');
397 } else if (mb_substr($cls, -6) == 'Action' &&
398 file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php')) {
399 require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
400 } else if ($cls == 'OAuthRequest') {
401 require_once('OAuth.php');
403 Event::handle('Autoload', array(&$cls));
407 // XXX: how many of these could be auto-loaded on use?
408 // XXX: note that these files should not use config options
409 // at compile time since DB config options are not yet loaded.
411 require_once 'Validate.php';
412 require_once 'markdown.php';
414 require_once INSTALLDIR.'/lib/util.php';
415 require_once INSTALLDIR.'/lib/action.php';
416 require_once INSTALLDIR.'/lib/theme.php';
417 require_once INSTALLDIR.'/lib/mail.php';
418 require_once INSTALLDIR.'/lib/subs.php';
419 require_once INSTALLDIR.'/lib/Shorturl_api.php';
420 require_once INSTALLDIR.'/lib/twitter.php';
422 require_once INSTALLDIR.'/lib/clientexception.php';
423 require_once INSTALLDIR.'/lib/serverexception.php';
425 // Load settings from database; note we need autoload for this
427 Config::loadSettings();
429 // XXX: other formats here
431 define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);
433 // Give plugins a chance to initialize in a fully-prepared environment
435 Event::handle('InitializePlugin');