We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

common.php 5.75 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Evan Prodromou's avatar
Evan Prodromou committed
2
/*
3
 * StatusNet - the distributed open-source microblogging tool
4
 * Copyright (C) 2008, 2009, StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
5
 *
Evan Prodromou's avatar
Evan Prodromou committed
6 7 8 9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
Evan Prodromou's avatar
Evan Prodromou committed
10
 *
Evan Prodromou's avatar
Evan Prodromou committed
11 12 13 14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
Evan Prodromou's avatar
Evan Prodromou committed
15
 *
Evan Prodromou's avatar
Evan Prodromou committed
16 17 18 19
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

20
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
Evan Prodromou's avatar
Evan Prodromou committed
21

22
//exit with 200 response, if this is checking fancy from the installer
Evan Prodromou's avatar
Evan Prodromou committed
23
if (isset($_REQUEST['p']) && $_REQUEST['p'] == 'check-fancy') {  exit; }
24

25
define('STATUSNET_VERSION', '0.9.6');
26
define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility
27

28
define('STATUSNET_CODENAME', 'Man on the Moon');
29

Evan Prodromou's avatar
Evan Prodromou committed
30 31 32 33
define('AVATAR_PROFILE_SIZE', 96);
define('AVATAR_STREAM_SIZE', 48);
define('AVATAR_MINI_SIZE', 24);

34
define('NOTICES_PER_PAGE', 20);
35
define('PROFILES_PER_PAGE', 20);
36

37 38 39 40 41 42 43
define('FOREIGN_NOTICE_SEND', 1);
define('FOREIGN_NOTICE_RECV', 2);
define('FOREIGN_NOTICE_SEND_REPLY', 4);

define('FOREIGN_FRIEND_SEND', 1);
define('FOREIGN_FRIEND_RECV', 2);

44 45 46 47 48 49
define('NOTICE_INBOX_SOURCE_SUB', 1);
define('NOTICE_INBOX_SOURCE_GROUP', 2);
define('NOTICE_INBOX_SOURCE_REPLY', 3);
define('NOTICE_INBOX_SOURCE_FORWARD', 4);
define('NOTICE_INBOX_SOURCE_GATEWAY', -1);

50 51
# append our extlib dir as the last-resort place to find libs

Evan Prodromou's avatar
Evan Prodromou committed
52
set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/');
Evan Prodromou's avatar
Evan Prodromou committed
53

54 55
// To protect against upstream libraries which haven't updated
// for PHP 5.3 where dl() function may not be present...
56
if (!function_exists('dl')) {
57 58 59 60 61 62 63 64 65 66 67
    // function_exists() returns false for things in disable_functions,
    // but they still exist and we'll die if we try to redefine them.
    //
    // Fortunately trying to call the disabled one will only trigger
    // a warning, not a fatal, so it's safe to leave it for our case.
    // Callers will be suppressing warnings anyway.
    $disabled = array_filter(array_map('trim', explode(',', ini_get('disable_functions'))));
    if (!in_array('dl', $disabled)) {
        function dl($library) {
            return false;
        }
68 69 70
    }
}

Evan Prodromou's avatar
Evan Prodromou committed
71 72
# global configuration object

Evan Prodromou's avatar
Evan Prodromou committed
73
require_once('PEAR.php');
Evan Prodromou's avatar
Evan Prodromou committed
74
require_once('DB/DataObject.php');
Evan Prodromou's avatar
Evan Prodromou committed
75
require_once('DB/DataObject/Cast.php'); # for dates
Evan Prodromou's avatar
Evan Prodromou committed
76

77 78
require_once(INSTALLDIR.'/lib/language.php');

79 80 81 82
// This gets included before the config file, so that admin code and plugins
// can use it

require_once(INSTALLDIR.'/lib/event.php');
83
require_once(INSTALLDIR.'/lib/plugin.php');
84

85 86
function addPlugin($name, $attrs = null)
{
87
    return StatusNet::addPlugin($name, $attrs);
88
}
89

90 91
function _have_config()
{
92
    return StatusNet::haveConfig();
93 94
}

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
function __autoload($cls)
{
    if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) {
        require_once(INSTALLDIR.'/classes/' . $cls . '.php');
    } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($cls) . '.php')) {
        require_once(INSTALLDIR.'/lib/' . strtolower($cls) . '.php');
    } else if (mb_substr($cls, -6) == 'Action' &&
               file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php')) {
        require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
    } else if ($cls == 'OAuthRequest') {
        require_once('OAuth.php');
    } else {
        Event::handle('Autoload', array(&$cls));
    }
}

111
// XXX: how many of these could be auto-loaded on use?
112 113
// XXX: note that these files should not use config options
// at compile time since DB config options are not yet loaded.
114

115 116
require_once 'Validate.php';
require_once 'markdown.php';
117

118 119
// XXX: other formats here

120 121 122 123 124 125 126 127 128 129 130
/**
 * Avoid the NICKNAME_FMT constant; use the Nickname class instead.
 *
 * Nickname::DISPLAY_FMT is more suitable for inserting into regexes;
 * note that it includes the [] and repeating bits, so should be wrapped
 * directly in a capture paren usually.
 *
 * For validation, use Nickname::validate() etc.
 *
 * @deprecated
 */
131 132
define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);

133 134 135 136
require_once INSTALLDIR.'/lib/util.php';
require_once INSTALLDIR.'/lib/action.php';
require_once INSTALLDIR.'/lib/mail.php';
require_once INSTALLDIR.'/lib/subs.php';
Evan Prodromou's avatar
Evan Prodromou committed
137

138 139
require_once INSTALLDIR.'/lib/clientexception.php';
require_once INSTALLDIR.'/lib/serverexception.php';
140

141 142 143 144 145
try {
    StatusNet::init(@$server, @$path, @$conffile);
} catch (NoConfigException $e) {
    // XXX: Throw a conniption if database not installed
    // XXX: Find a way to use htmlwriter for this instead of handcoded markup
146
    // TRANS: Error message displayed when no configuration file was found for a StatusNet installation.
147
    echo '<p>'. _('No configuration file found.') .'</p>';
148 149
    // TRANS: Error message displayed when no configuration file was found for a StatusNet installation.
    // TRANS: Is followed by a list of directories (separated by HTML breaks).
150
    echo '<p>'. _('I looked for configuration files in the following places:') .'<br /> ';
151 152
    echo implode($e->configFiles, '<br />');
    // TRANS: Error message displayed when no configuration file was found for a StatusNet installation.
153
    echo '<p>'. _('You may wish to run the installer to fix this.') .'</p>';
154 155 156
    // @todo FIXME Link should be in a para?
    // TRANS: Error message displayed when no configuration file was found for a StatusNet installation.
    // TRANS: The text is link text that leads to the installer page.
157 158
    echo '<a href="install.php">'. _('Go to the installer.') .'</a>';
    exit;
Evan Prodromou's avatar
Evan Prodromou committed
159
}