]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/common.php
update version number
[quix0rs-gnu-social.git] / lib / common.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
21
22 define('STATUSNET_VERSION', '0.8.2');
23 define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility
24
25 define('STATUSNET_CODENAME', 'Life and How to Live It');
26
27 define('AVATAR_PROFILE_SIZE', 96);
28 define('AVATAR_STREAM_SIZE', 48);
29 define('AVATAR_MINI_SIZE', 24);
30
31 define('NOTICES_PER_PAGE', 20);
32 define('PROFILES_PER_PAGE', 20);
33
34 define('FOREIGN_NOTICE_SEND', 1);
35 define('FOREIGN_NOTICE_RECV', 2);
36 define('FOREIGN_NOTICE_SEND_REPLY', 4);
37
38 define('FOREIGN_FRIEND_SEND', 1);
39 define('FOREIGN_FRIEND_RECV', 2);
40
41 define_syslog_variables();
42
43 # append our extlib dir as the last-resort place to find libs
44
45 set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/');
46
47 # global configuration object
48
49 require_once('PEAR.php');
50 require_once('DB/DataObject.php');
51 require_once('DB/DataObject/Cast.php'); # for dates
52
53 if (!function_exists('gettext')) {
54     require_once("php-gettext/gettext.inc");
55 }
56 require_once(INSTALLDIR.'/lib/language.php');
57
58 // This gets included before the config file, so that admin code and plugins
59 // can use it
60
61 require_once(INSTALLDIR.'/lib/event.php');
62 require_once(INSTALLDIR.'/lib/plugin.php');
63
64 function _sn_to_path($sn)
65 {
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);
70     } else {
71         $p = '';
72     }
73     return $p;
74 }
75
76 // try to figure out where we are. $server and $path
77 // can be set by including module, else we guess based
78 // on HTTP info.
79
80 if (isset($server)) {
81     $_server = $server;
82 } else {
83     $_server = array_key_exists('SERVER_NAME', $_SERVER) ?
84       strtolower($_SERVER['SERVER_NAME']) :
85     null;
86 }
87
88 if (isset($path)) {
89     $_path = $path;
90 } else {
91     $_path = (array_key_exists('SERVER_NAME', $_SERVER) && array_key_exists('SCRIPT_NAME', $_SERVER)) ?
92       _sn_to_path($_SERVER['SCRIPT_NAME']) :
93     null;
94 }
95
96 // default configuration, overwritten in config.php
97
98 $config =
99   array('site' =>
100         array('name' => 'Just another StatusNet microblog',
101               'server' => $_server,
102               'theme' => 'default',
103               'path' => $_path,
104               'logfile' => null,
105               'logo' => null,
106               'logdebug' => false,
107               'fancy' => false,
108               'locale_path' => INSTALLDIR.'/locale',
109               'language' => 'en_US',
110               'languages' => get_all_languages(),
111               'email' =>
112               array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : null,
113               'broughtby' => null,
114               'timezone' => 'UTC',
115               'broughtbyurl' => null,
116               'closed' => false,
117               'inviteonly' => false,
118               'openidonly' => false,
119               'private' => false,
120               'ssl' => 'never',
121               'sslserver' => null,
122               'shorturllength' => 30,
123               'dupelimit' => 60), # default for same person saying the same thing
124         'syslog' =>
125         array('appname' => 'statusnet', # for syslog
126               'priority' => 'debug', # XXX: currently ignored
127               'facility' => LOG_USER),
128         'queue' =>
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,
135               ),
136         'license' =>
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'),
140         'mail' =>
141         array('backend' => 'mail',
142               'params' => null),
143         'nickname' =>
144         array('blacklist' => array(),
145               'featured' => array()),
146         'profile' =>
147         array('banned' => array()),
148         'avatar' =>
149         array('server' => null,
150               'dir' => INSTALLDIR . '/avatar/',
151               'path' => $_path . '/avatar/'),
152         'background' =>
153         array('server' => null,
154               'dir' => INSTALLDIR . '/background/',
155               'path' => $_path . '/background/'),
156         'public' =>
157         array('localonly' => true,
158               'blacklist' => array(),
159               'autosource' => array()),
160         'theme' =>
161         array('server' => null,
162               'dir' => null,
163               'path'=> null),
164         'throttle' =>
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
168         'xmpp' =>
169         array('enabled' => false,
170               'server' => 'INVALID SERVER',
171               'port' => 5222,
172               'user' => 'update',
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
179         'openid' =>
180         array('enabled' => true),
181         'invite' =>
182         array('enabled' => true),
183         'sphinx' =>
184         array('enabled' => false,
185               'server' => 'localhost',
186               'port' => 3312),
187         'tag' =>
188         array('dropoff' => 864000.0),
189         'popular' =>
190         array('dropoff' => 864000.0),
191         'daemon' =>
192         array('piddir' => '/var/run',
193               'user' => false,
194               'group' => false),
195         'emailpost' =>
196         array('enabled' => true),
197         'sms' =>
198         array('enabled' => true),
199         'twitterbridge' =>
200         array('enabled' => false),
201         'integration' =>
202         array('source' => 'StatusNet', # source attribute for Twitter
203               'taguri' => $_server.',2009'), # base for tag URIs
204         'twitter' =>
205         array('enabled'         => true,
206               'consumer_key'    => null,
207               'consumer_secret' => null),
208         'memcached' =>
209         array('enabled' => false,
210               'server' => 'localhost',
211               'base' => null,
212               'port' => 11211),
213                 'ping' =>
214         array('notify' => array()),
215         'inboxes' =>
216         array('enabled' => true), # on by default for new sites
217         'newuser' =>
218         array('default' => null,
219               'welcome' => null),
220         'snapshot' =>
221         array('run' => 'web',
222               'frequency' => 10000,
223               'reporturl' => 'http://status.net/stats/report'),
224         'attachments' =>
225         array('server' => null,
226               'dir' => INSTALLDIR . '/file/',
227               'path' => $_path . '/file/',
228               'supported' => array('image/png',
229                                    'image/jpeg',
230                                    'image/gif',
231                                    'image/svg+xml',
232                                    'audio/mpeg',
233                                    'audio/x-speex',
234                                    'application/ogg',
235                                    'application/pdf',
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',
252                                    'application/x-zip',
253                                    'application/zip',
254                                    'text/plain',
255                                    'video/mpeg',
256                                    'video/mp4',
257                                    'video/quicktime',
258                                    'video/mpeg'),
259         'file_quota' => 5000000,
260         'user_quota' => 50000000,
261         'monthly_quota' => 15000000,
262         'uploads' => true,
263         'filecommand' => '/usr/bin/file',
264         ),
265         'group' =>
266         array('maxaliases' => 3),
267         'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/'),
268         'search' =>
269         array('type' => 'fulltext'),
270         'sessions' =>
271         array('handle' => false, // whether to handle sessions ourselves
272               'debug' => false), // debugging output for sessions
273         'design' =>
274         array('backgroundcolor' => null, // null -> 'use theme default'
275               'contentcolor' => null,
276               'sidebarcolor' => null,
277               'textcolor' => null,
278               'linkcolor' => null,
279               'backgroundimage' => null,
280               'disposition' => null),
281         );
282
283 $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
284
285 $config['db'] =
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' => '',
291         'mirror' => null,
292         'utf8' => true,
293         'db_driver' => 'DB', # XXX: JanRain libs only work with DB
294         'quote_identifiers' => false,
295         'type' => 'mysql' );
296
297 // Backward compatibility
298
299 $config['site']['design'] =& $config['design'];
300
301 if (function_exists('date_default_timezone_set')) {
302     /* Work internally in UTC */
303     date_default_timezone_set('UTC');
304 }
305
306 function addPlugin($name, $attrs = null)
307 {
308     $name = ucfirst($name);
309     $pluginclass = "{$name}Plugin";
310
311     if (!class_exists($pluginclass)) {
312
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");
319
320         foreach ($files as $file) {
321             $fullpath = INSTALLDIR.'/'.$file;
322             if (@file_exists($fullpath)) {
323                 include_once($fullpath);
324                 break;
325             }
326         }
327     }
328
329     $inst = new $pluginclass();
330
331     if (!empty($attrs)) {
332         foreach ($attrs as $aname => $avalue) {
333             $inst->$aname = $avalue;
334         }
335     }
336     return $inst;
337 }
338
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).
342
343 if (isset($conffile)) {
344     $_config_files = array($conffile);
345 } else {
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');
351
352     if (strlen($_path) > 0) {
353         $_config_files[] = '/etc/statusnet/'.$_server.'_'.$_path.'.php';
354         $_config_files[] = '/etc/laconica/'.$_server.'_'.$_path.'.php';
355     }
356
357     $_config_files[] = INSTALLDIR.'/config.php';
358 }
359
360 $_have_a_config = false;
361
362 foreach ($_config_files as $_config_file) {
363     if (@file_exists($_config_file)) {
364         include_once($_config_file);
365         $_have_a_config = true;
366     }
367 }
368
369 function _have_config()
370 {
371     global $_have_a_config;
372     return $_have_a_config;
373 }
374
375 // XXX: Throw a conniption if database not installed
376
377 // Fixup for statusnet.ini
378
379 $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1);
380
381 if ($_db_name != 'statusnet' && !array_key_exists('ini_'.$_db_name, $config['db'])) {
382     $config['db']['ini_'.$_db_name] = INSTALLDIR.'/classes/statusnet.ini';
383 }
384
385 // Ignore openidonly if OpenID is disabled
386
387 if (!$config['openid']['enabled']) {
388     $config['site']['openidonly'] = false;
389 }
390
391 // XXX: how many of these could be auto-loaded on use?
392
393 require_once 'Validate.php';
394 require_once 'markdown.php';
395
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';
403
404 require_once INSTALLDIR.'/lib/clientexception.php';
405 require_once INSTALLDIR.'/lib/serverexception.php';
406
407 // XXX: other formats here
408
409 define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);
410
411 function __autoload($class)
412 {
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');
422     }
423 }
424
425 // Give plugins a chance to initialize in a fully-prepared environment
426
427 Event::handle('InitializePlugin');