]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - index.php
Merge ActivitySpam plugin
[quix0rs-gnu-social.git] / index.php
index 5a08aa07825c4d11b87a2e726c81c1db5be8b4ee..1566399fa2f351e8381796397d0f697b5b4e617f 100644 (file)
--- a/index.php
+++ b/index.php
@@ -37,6 +37,9 @@
  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
  */
 
+$_startTime = microtime(true);
+$_perfCounters = array();
+
 define('INSTALLDIR', dirname(__FILE__));
 define('STATUSNET', true);
 define('LACONICA', true); // compatibility
@@ -46,21 +49,29 @@ $action = null;
 
 function getPath($req)
 {
+    $p = null;
+
     if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER))
         && array_key_exists('p', $req)
     ) {
-        return $req['p'];
+        $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) {
-            return substr($path, mb_strlen($script));
+            $p = substr($path, mb_strlen($script) + 1);
         } else {
-            return $path;
+            $p = $path;
         }
     } else {
-        return null;
+        $p = null;
     }
+
+    // Trim all initial '/'
+
+    $p = ltrim($p, '/');
+
+    return $p;
 }
 
 /**
@@ -103,27 +114,26 @@ function handleError($error)
             $_cur = null;
 
             $msg = sprintf(
-                _(
-                    'The database for %s isn\'t responding correctly, '.
-                    'so the site won\'t work properly. '.
-                    'The site admins probably know about the problem, '.
-                    'but you can contact them at %s to make sure. '.
-                    'Otherwise, wait a few minutes and try again.'
+                // TRANS: Database error message.
+                _('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')
             );
+
+            $dac = new DBErrorAction($msg, 500);
+            $dac->showPage();
         } else {
-            $msg = _(
-                'An important error occured, probably related to email setup. '.
-                'Check logfiles for more info..'
-            );
+            $sac = new ServerErrorAction($error->getMessage(), 500, $error);
+            $sac->showPage();
         }
 
-        $dac = new DBErrorAction($msg, 500);
-        $dac->showPage();
-
     } catch (Exception $e) {
+        // TRANS: Error message.
         echo _('An error occurred.');
     }
     exit(-1);
@@ -171,15 +181,24 @@ function setupRW()
 
     static $alwaysRW = array('session', 'remember_me');
 
-    // We ensure that these tables always are used
-    // on the master DB
+    $rwdb = $config['db']['database'];
+
+    if (Event::handle('StartReadWriteTables', array(&$alwaysRW, &$rwdb))) {
+
+        // We ensure that these tables always are used
+        // on the master DB
 
-    $config['db']['database_rw'] = $config['db']['database'];
-    $config['db']['ini_rw'] = INSTALLDIR.'/classes/statusnet.ini';
+        $config['db']['database_rw'] = $rwdb;
+        $config['db']['ini_rw'] = INSTALLDIR.'/classes/statusnet.ini';
 
-    foreach ($alwaysRW as $table) {
-        $config['db']['table_'.$table] = 'rw';
+        foreach ($alwaysRW as $table) {
+            $config['db']['table_'.$table] = 'rw';
+        }
+
+        Event::handle('EndReadWriteTables', array($alwaysRW, $rwdb));
     }
+
+    return;
 }
 
 function checkMirror($action_obj, $args)
@@ -219,7 +238,7 @@ function main()
 {
     // fake HTTP redirects using lighttpd's 404 redirects
     if (strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false) {
-        $_lighty_url = $base_url.$_SERVER['REQUEST_URI'];
+        $_lighty_url = $_SERVER['REQUEST_URI'];
         $_lighty_url = @parse_url($_lighty_url);
 
         if ($_lighty_url['path'] != '/index.php' && $_lighty_url['path'] != '/') {
@@ -247,9 +266,9 @@ function main()
 
     if (!_have_config()) {
         $msg = sprintf(
-            _(
-                "No configuration file found. Try running ".
-                "the installation program first."
+            // TRANS: Error message displayed when there is no StatusNet configuration file.
+            _("No configuration file found. Try running ".
+              "the installation program first."
             )
         );
         $sac = new ServerErrorAction($msg);
@@ -278,6 +297,7 @@ function main()
     $args = $r->map($path);
 
     if (!$args) {
+        // TRANS: Error message displayed when trying to access a non-existing page.
         $cac = new ClientErrorAction(_('Unknown page'), 404);
         $cac->showPage();
         return;
@@ -332,6 +352,7 @@ function main()
     $action_class = ucfirst($action).'Action';
 
     if (!class_exists($action_class)) {
+        // TRANS: Error message displayed when trying to perform an undefined action.
         $cac = new ClientErrorAction(_('Unknown action'), 404);
         $cac->showPage();
     } else {