123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- $_startTime = microtime(true);
- $_perfCounters = array();
- set_include_path('.');
- define('INSTALLDIR', dirname(__FILE__));
- define('GNUSOCIAL', true);
- define('STATUSNET', true);
- $user = null;
- $action = null;
- function getPath($req)
- {
- $p = null;
- if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER))
- && array_key_exists('p', $req)
- ) {
- $p = $req['p'];
- } else if (array_key_exists('PATH_INFO', $_SERVER)) {
- $path = $_SERVER['PATH_INFO'];
- $script = $_SERVER['SCRIPT_NAME'];
- if (substr($path, 0, mb_strlen($script)) == $script) {
- $p = substr($path, mb_strlen($script) + 1);
- } else {
- $p = $path;
- }
- } else {
- $p = null;
- }
-
- $p = ltrim($p, '/');
- return $p;
- }
- function handleError($error)
- {
- try {
- if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
- return;
- }
- $logmsg = "Exception thrown: " . _ve($error->getMessage());
- if ($error instanceof PEAR_Exception && common_config('log', 'debugtrace')) {
- $logmsg .= " PEAR: ". $error->toText();
- }
-
-
- $logmsg = str_replace("\n", " ", $logmsg);
- common_log(LOG_ERR, $logmsg);
-
- if (common_config('log', 'debugtrace')) {
- $bt = $error->getTrace();
- foreach ($bt as $n => $line) {
- common_log(LOG_ERR, formatBacktraceLine($n, $line));
- }
- }
- if ($error instanceof DB_DataObject_Error
- || $error instanceof DB_Error
- || ($error instanceof PEAR_Exception && $error->getCode() == -24)
- ) {
-
-
-
- global $_cur;
- $_cur = null;
- $msg = sprintf(
-
- _('The database for %1$s is not responding correctly, '.
- 'so the site will not work properly. '.
- 'The site admins probably know about the problem, '.
- 'but you can contact them at %2$s to make sure. '.
- 'Otherwise, wait a few minutes and try again.'
- ),
- common_config('site', 'name'),
- common_config('site', 'email')
- );
- $erraction = new DBErrorAction($msg, 500);
- } elseif ($error instanceof ClientException) {
- $erraction = new ClientErrorAction($error->getMessage(), $error->getCode());
- } elseif ($error instanceof ServerException) {
- $erraction = new ServerErrorAction($error->getMessage(), $error->getCode(), $error);
- } else {
-
- $erraction = new ServerErrorAction($error->getMessage(), 500, $error);
- }
- $erraction->showPage();
- } catch (Exception $e) {
-
- echo _('An error occurred.');
- exit(-1);
- }
- exit(-1);
- }
- set_exception_handler('handleError');
- if (preg_replace("/\?.+$/", "", $_SERVER['REQUEST_URI']) === preg_replace("/^\/$/", "", (dirname($_SERVER['REQUEST_URI']))) . '/check-fancy') {
- die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs.");
- }
- require_once INSTALLDIR . '/lib/common.php';
- function formatBacktraceLine($n, $line)
- {
- $out = "#$n ";
- if (isset($line['class'])) $out .= $line['class'];
- if (isset($line['type'])) $out .= $line['type'];
- if (isset($line['function'])) $out .= $line['function'];
- $out .= '(';
- if (isset($line['args'])) {
- $args = array();
- foreach ($line['args'] as $arg) {
-
-
- $args[] = gettype($arg);
- }
- $out .= implode(',', $args);
- }
- $out .= ')';
- $out .= ' called at [';
- if (isset($line['file'])) $out .= $line['file'];
- if (isset($line['line'])) $out .= ':' . $line['line'];
- $out .= ']';
- return $out;
- }
- function setupRW()
- {
- global $config;
- static $alwaysRW = array('session', 'remember_me');
- $rwdb = $config['db']['database'];
- if (Event::handle('StartReadWriteTables', array(&$alwaysRW, &$rwdb))) {
-
-
- $config['db']['database_rw'] = $rwdb;
- $config['db']['ini_rw'] = INSTALLDIR.'/classes/statusnet.ini';
- foreach ($alwaysRW as $table) {
- $config['db']['table_'.$table] = 'rw';
- }
- Event::handle('EndReadWriteTables', array($alwaysRW, $rwdb));
- }
- return;
- }
- function isLoginAction($action)
- {
- static $loginActions = array('login', 'recoverpassword', 'api', 'doc', 'register', 'publicxrds', 'otp', 'opensearch', 'rsd');
- $login = null;
- if (Event::handle('LoginAction', array($action, &$login))) {
- $login = in_array($action, $loginActions);
- }
- return $login;
- }
- function main()
- {
- global $user, $action;
- if (!_have_config()) {
- $msg = sprintf(
-
- _("No configuration file found. Try running ".
- "the installation program first."
- )
- );
- $sac = new ServerErrorAction($msg);
- $sac->showPage();
- return;
- }
-
- setupRW();
-
-
- $user = common_current_user();
-
- common_init_language();
- $path = getPath($_REQUEST);
- $r = Router::get();
- $args = $r->map($path);
-
- if (GNUsocial::useHTTPS() && !GNUsocial::isHTTPS()) {
- common_redirect(common_local_url($args['action'], $args));
- }
- $args = array_merge($args, $_REQUEST ?: []);
- Event::handle('ArgsInitialize', array(&$args));
- $action = basename($args['action']);
- if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) {
- common_redirect(common_local_url('public'));
- }
-
-
- if (!$user && common_config('site', 'private')
- && !isLoginAction($action)
- && !preg_match('/rss$/', $action)
- && $action != 'robotstxt'
- && !preg_match('/^Api/', $action)) {
-
- $rargs =& common_copy_args($args);
- unset($rargs['action']);
- if (common_config('site', 'fancy')) {
- unset($rargs['p']);
- }
- if (array_key_exists('submit', $rargs)) {
- unset($rargs['submit']);
- }
- foreach (array_keys($_COOKIE) as $cookie) {
- unset($rargs[$cookie]);
- }
- common_set_returnto(common_local_url($action, $rargs));
- common_redirect(common_local_url('login'));
- }
- $action_class = ucfirst($action).'Action';
- if (!class_exists($action_class)) {
-
- throw new ClientException(_('Unknown action'), 404);
- }
- call_user_func("$action_class::run", $args);
- }
- main();
- Event::handle('CleanupPlugin');
|