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.8.2dev');
23 define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility
25 define('STATUSNET_CODENAME', 'Life and How to Live It');
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,
118 'openidonly' => false,
122 'shorturllength' => 30,
123 'dupelimit' => 60), # default for same person saying the same thing
125 array('appname' => 'statusnet', # for syslog
126 'priority' => 'debug', # XXX: currently ignored
127 'facility' => LOG_USER),
129 array('enabled' => false,
130 'subsystem' => 'db', # default to database, or 'stomp'
131 'stomp_server' => null,
132 'queue_basename' => 'statusnet',
133 'stomp_username' => null,
134 'stomp_password' => null,
137 array('url' => 'http://creativecommons.org/licenses/by/3.0/',
138 'title' => 'Creative Commons Attribution 3.0',
139 'image' => 'http://i.creativecommons.org/l/by/3.0/80x15.png'),
141 array('backend' => 'mail',
144 array('blacklist' => array(),
145 'featured' => array()),
147 array('banned' => array()),
149 array('server' => null,
150 'dir' => INSTALLDIR . '/avatar/',
151 'path' => $_path . '/avatar/'),
153 array('server' => null,
154 'dir' => INSTALLDIR . '/background/',
155 'path' => $_path . '/background/'),
157 array('localonly' => true,
158 'blacklist' => array(),
159 'autosource' => array()),
161 array('server' => null,
165 array('enabled' => false, // whether to throttle edits; false by default
166 'count' => 20, // number of allowed messages in timespan
167 'timespan' => 600), // timespan for throttling
169 array('enabled' => false,
170 'server' => 'INVALID SERVER',
173 'encryption' => true,
174 'resource' => 'uniquename',
175 'password' => 'blahblahblah',
176 'host' => null, # only set if != server
177 'debug' => false, # print extra debug info
178 'public' => array()), # JIDs of users who want to receive the public stream
180 array('enabled' => true),
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' => false),
202 array('source' => 'StatusNet', # source attribute for Twitter
203 'taguri' => $_server.',2009'), # base for tag URIs
205 array('enabled' => true,
206 'consumer_key' => null,
207 'consumer_secret' => null),
209 array('enabled' => false,
210 'server' => 'localhost',
214 array('notify' => array()),
216 array('enabled' => true), # on by default for new sites
218 array('default' => null,
221 array('run' => 'web',
222 'frequency' => 10000,
223 'reporturl' => 'http://status.net/stats/report'),
225 array('server' => null,
226 'dir' => INSTALLDIR . '/file/',
227 'path' => $_path . '/file/',
228 'supported' => array('image/png',
236 'application/vnd.oasis.opendocument.text',
237 'application/vnd.oasis.opendocument.text-template',
238 'application/vnd.oasis.opendocument.graphics',
239 'application/vnd.oasis.opendocument.graphics-template',
240 'application/vnd.oasis.opendocument.presentation',
241 'application/vnd.oasis.opendocument.presentation-template',
242 'application/vnd.oasis.opendocument.spreadsheet',
243 'application/vnd.oasis.opendocument.spreadsheet-template',
244 'application/vnd.oasis.opendocument.chart',
245 'application/vnd.oasis.opendocument.chart-template',
246 'application/vnd.oasis.opendocument.image',
247 'application/vnd.oasis.opendocument.image-template',
248 'application/vnd.oasis.opendocument.formula',
249 'application/vnd.oasis.opendocument.formula-template',
250 'application/vnd.oasis.opendocument.text-master',
251 'application/vnd.oasis.opendocument.text-web',
259 'file_quota' => 5000000,
260 'user_quota' => 50000000,
261 'monthly_quota' => 15000000,
263 'filecommand' => '/usr/bin/file',
266 array('maxaliases' => 3),
267 'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/'),
269 array('type' => 'fulltext'),
271 array('handle' => false, // whether to handle sessions ourselves
272 'debug' => false), // debugging output for sessions
274 array('backgroundcolor' => null, // null -> 'use theme default'
275 'contentcolor' => null,
276 'sidebarcolor' => null,
279 'backgroundimage' => null,
280 'disposition' => null),
283 $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
286 array('database' => 'YOU HAVE TO SET THIS IN config.php',
287 'schema_location' => INSTALLDIR . '/classes',
288 'class_location' => INSTALLDIR . '/classes',
289 'require_prefix' => 'classes/',
290 'class_prefix' => '',
293 'db_driver' => 'DB', # XXX: JanRain libs only work with DB
294 'quote_identifiers' => false,
297 // Backward compatibility
299 $config['site']['design'] =& $config['design'];
301 if (function_exists('date_default_timezone_set')) {
302 /* Work internally in UTC */
303 date_default_timezone_set('UTC');
306 function addPlugin($name, $attrs = null)
308 $name = ucfirst($name);
309 $pluginclass = "{$name}Plugin";
311 if (!class_exists($pluginclass)) {
313 $files = array("local/plugins/{$pluginclass}.php",
314 "local/plugins/{$name}/{$pluginclass}.php",
315 "local/{$pluginclass}.php",
316 "local/{$name}/{$pluginclass}.php",
317 "plugins/{$pluginclass}.php",
318 "plugins/{$name}/{$pluginclass}.php");
320 foreach ($files as $file) {
321 $fullpath = INSTALLDIR.'/'.$file;
322 if (@file_exists($fullpath)) {
323 include_once($fullpath);
329 $inst = new $pluginclass();
331 if (!empty($attrs)) {
332 foreach ($attrs as $aname => $avalue) {
333 $inst->$aname = $avalue;
339 // From most general to most specific:
340 // server-wide, then vhost-wide, then for a path,
341 // finally for a dir (usually only need one of the last two).
343 if (isset($conffile)) {
344 $_config_files = array($conffile);
346 $_config_files = array('/etc/statusnet/statusnet.php',
347 '/etc/statusnet/laconica.php',
348 '/etc/laconica/laconica.php',
349 '/etc/statusnet/'.$_server.'.php',
350 '/etc/laconica/'.$_server.'.php');
352 if (strlen($_path) > 0) {
353 $_config_files[] = '/etc/statusnet/'.$_server.'_'.$_path.'.php';
354 $_config_files[] = '/etc/laconica/'.$_server.'_'.$_path.'.php';
357 $_config_files[] = INSTALLDIR.'/config.php';
360 $_have_a_config = false;
362 foreach ($_config_files as $_config_file) {
363 if (@file_exists($_config_file)) {
364 include_once($_config_file);
365 $_have_a_config = true;
369 function _have_config()
371 global $_have_a_config;
372 return $_have_a_config;
375 // XXX: Throw a conniption if database not installed
377 // Fixup for statusnet.ini
379 $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1);
381 if ($_db_name != 'statusnet' && !array_key_exists('ini_'.$_db_name, $config['db'])) {
382 $config['db']['ini_'.$_db_name] = INSTALLDIR.'/classes/statusnet.ini';
385 // Ignore openidonly if OpenID is disabled
387 if (!$config['openid']['enabled']) {
388 $config['site']['openidonly'] = false;
391 // XXX: how many of these could be auto-loaded on use?
393 require_once 'Validate.php';
394 require_once 'markdown.php';
396 require_once INSTALLDIR.'/lib/util.php';
397 require_once INSTALLDIR.'/lib/action.php';
398 require_once INSTALLDIR.'/lib/theme.php';
399 require_once INSTALLDIR.'/lib/mail.php';
400 require_once INSTALLDIR.'/lib/subs.php';
401 require_once INSTALLDIR.'/lib/Shorturl_api.php';
402 require_once INSTALLDIR.'/lib/twitter.php';
404 require_once INSTALLDIR.'/lib/clientexception.php';
405 require_once INSTALLDIR.'/lib/serverexception.php';
407 // XXX: other formats here
409 define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);
411 function __autoload($class)
413 if ($class == 'OAuthRequest') {
414 require_once('OAuth.php');
415 } else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) {
416 require_once(INSTALLDIR.'/classes/' . $class . '.php');
417 } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($class) . '.php')) {
418 require_once(INSTALLDIR.'/lib/' . strtolower($class) . '.php');
419 } else if (mb_substr($class, -6) == 'Action' &&
420 file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($class, 0, -6)) . '.php')) {
421 require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($class, 0, -6)) . '.php');
425 // Give plugins a chance to initialize in a fully-prepared environment
427 Event::handle('InitializePlugin');