]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/common.php
change version to 0.8.2dev
[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.2dev');
23 define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility
24
25 define('STATUSNET_CODENAME', 'Second Guessing');
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         'twitter' =>
200         array('enabled' => true),
201         'twitterbridge' =>
202         array('enabled' => false),
203         'integration' =>
204         array('source' => 'StatusNet', # source attribute for Twitter
205               'taguri' => $_server.',2009'), # base for tag URIs
206         'twitter' =>
207         array('consumer_key'    => null,
208               'consumer_secret' => null),
209         'memcached' =>
210         array('enabled' => false,
211               'server' => 'localhost',
212               'base' => null,
213               'port' => 11211),
214                 'ping' =>
215         array('notify' => array()),
216         'inboxes' =>
217         array('enabled' => true), # on by default for new sites
218         'newuser' =>
219         array('default' => null,
220               'welcome' => null),
221         'snapshot' =>
222         array('run' => 'web',
223               'frequency' => 10000,
224               'reporturl' => 'http://status.net/stats/report'),
225         'attachments' =>
226         array('server' => null,
227               'dir' => INSTALLDIR . '/file/',
228               'path' => $_path . '/file/',
229               'supported' => array('image/png',
230                                    'image/jpeg',
231                                    'image/gif',
232                                    'image/svg+xml',
233                                    'audio/mpeg',
234                                    'audio/x-speex',
235                                    'application/ogg',
236                                    'application/pdf',
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',
253                                    'application/x-zip',
254                                    'application/zip',
255                                    'text/plain',
256                                    'video/mpeg',
257                                    'video/mp4',
258                                    'video/quicktime',
259                                    'video/mpeg'),
260         'file_quota' => 5000000,
261         'user_quota' => 50000000,
262         'monthly_quota' => 15000000,
263         'uploads' => true,
264         'filecommand' => '/usr/bin/file',
265         ),
266         'group' =>
267         array('maxaliases' => 3),
268         'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/'),
269         'search' =>
270         array('type' => 'fulltext'),
271         'sessions' =>
272         array('handle' => false, // whether to handle sessions ourselves
273               'debug' => false), // debugging output for sessions
274         'design' =>
275         array('backgroundcolor' => null, // null -> 'use theme default'
276               'contentcolor' => null,
277               'sidebarcolor' => null,
278               'textcolor' => null,
279               'linkcolor' => null,
280               'backgroundimage' => null,
281               'disposition' => null),
282         );
283
284 $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
285
286 $config['db'] =
287   array('database' => 'YOU HAVE TO SET THIS IN config.php',
288         'schema_location' => INSTALLDIR . '/classes',
289         'class_location' => INSTALLDIR . '/classes',
290         'require_prefix' => 'classes/',
291         'class_prefix' => '',
292         'mirror' => null,
293         'utf8' => true,
294         'db_driver' => 'DB', # XXX: JanRain libs only work with DB
295         'quote_identifiers' => false,
296         'type' => 'mysql' );
297
298 // Backward compatibility
299
300 $config['site']['design'] =& $config['design'];
301
302 if (function_exists('date_default_timezone_set')) {
303     /* Work internally in UTC */
304     date_default_timezone_set('UTC');
305 }
306
307 function addPlugin($name, $attrs = null)
308 {
309     $name = ucfirst($name);
310     $pluginclass = "{$name}Plugin";
311
312     if (!class_exists($pluginclass)) {
313
314         $files = array("local/plugins/{$pluginclass}.php",
315                        "local/plugins/{$name}/{$pluginclass}.php",
316                        "local/{$pluginclass}.php",
317                        "local/{$name}/{$pluginclass}.php",
318                        "plugins/{$pluginclass}.php",
319                        "plugins/{$name}/{$pluginclass}.php");
320
321         foreach ($files as $file) {
322             $fullpath = INSTALLDIR.'/'.$file;
323             if (@file_exists($fullpath)) {
324                 include_once($fullpath);
325                 break;
326             }
327         }
328     }
329
330     $inst = new $pluginclass();
331
332     if (!empty($attrs)) {
333         foreach ($attrs as $aname => $avalue) {
334             $inst->$aname = $avalue;
335         }
336     }
337     return $inst;
338 }
339
340 // From most general to most specific:
341 // server-wide, then vhost-wide, then for a path,
342 // finally for a dir (usually only need one of the last two).
343
344 if (isset($conffile)) {
345     $_config_files = array($conffile);
346 } else {
347     $_config_files = array('/etc/statusnet/statusnet.php',
348                            '/etc/statusnet/laconica.php',
349                            '/etc/laconica/laconica.php',
350                            '/etc/statusnet/'.$_server.'.php',
351                            '/etc/laconica/'.$_server.'.php');
352
353     if (strlen($_path) > 0) {
354         $_config_files[] = '/etc/statusnet/'.$_server.'_'.$_path.'.php';
355         $_config_files[] = '/etc/laconica/'.$_server.'_'.$_path.'.php';
356     }
357
358     $_config_files[] = INSTALLDIR.'/config.php';
359 }
360
361 $_have_a_config = false;
362
363 foreach ($_config_files as $_config_file) {
364     if (@file_exists($_config_file)) {
365         include_once($_config_file);
366         $_have_a_config = true;
367     }
368 }
369
370 function _have_config()
371 {
372     global $_have_a_config;
373     return $_have_a_config;
374 }
375
376 // XXX: Throw a conniption if database not installed
377
378 // Fixup for statusnet.ini
379
380 $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1);
381
382 if ($_db_name != 'statusnet' && !array_key_exists('ini_'.$_db_name, $config['db'])) {
383     $config['db']['ini_'.$_db_name] = INSTALLDIR.'/classes/statusnet.ini';
384 }
385
386 // Ignore openidonly if OpenID is disabled
387
388 if (!$config['openid']['enabled']) {
389     $config['site']['openidonly'] = false;
390 }
391
392 // XXX: how many of these could be auto-loaded on use?
393
394 require_once 'Validate.php';
395 require_once 'markdown.php';
396
397 require_once INSTALLDIR.'/lib/util.php';
398 require_once INSTALLDIR.'/lib/action.php';
399 require_once INSTALLDIR.'/lib/theme.php';
400 require_once INSTALLDIR.'/lib/mail.php';
401 require_once INSTALLDIR.'/lib/subs.php';
402 require_once INSTALLDIR.'/lib/Shorturl_api.php';
403 require_once INSTALLDIR.'/lib/twitter.php';
404
405 require_once INSTALLDIR.'/lib/clientexception.php';
406 require_once INSTALLDIR.'/lib/serverexception.php';
407
408 // XXX: other formats here
409
410 define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);
411
412 function __autoload($class)
413 {
414     if ($class == 'OAuthRequest') {
415         require_once('OAuth.php');
416     } else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) {
417         require_once(INSTALLDIR.'/classes/' . $class . '.php');
418     } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($class) . '.php')) {
419         require_once(INSTALLDIR.'/lib/' . strtolower($class) . '.php');
420     } else if (mb_substr($class, -6) == 'Action' &&
421                file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($class, 0, -6)) . '.php')) {
422         require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($class, 0, -6)) . '.php');
423     }
424 }
425
426 // Give plugins a chance to initialize in a fully-prepared environment
427
428 Event::handle('InitializePlugin');