]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - index.php
Make sure we have a DB connection before setting its charset
[quix0rs-gnu-social.git] / index.php
index b180e2b653b285f2c54585d83d7558e170f7e74d..f5b32ea09086cc2e3a205404603b30553d7798a3 100644 (file)
--- a/index.php
+++ b/index.php
@@ -27,12 +27,13 @@ $action = null;
 
 function getPath($req)
 {
-    if (common_config('site', 'fancy')) {
+    if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER))
+        && array_key_exists('p', $req)) {
         return $req['p'];
-    } else if ($_SERVER['PATH_INFO']) {
+    } else if (array_key_exists('PATH_INFO', $_SERVER)) {
         return $_SERVER['PATH_INFO'];
     } else {
-        return $req['p'];
+        return null;
     }
 }
 
@@ -42,14 +43,23 @@ function handleError($error)
         return;
     }
 
-    common_log(LOG_ERR, "PEAR error: " . $error->getMessage());
-    $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.'),
-                   common_config('site', 'name'),
-                   common_config('site', 'email'));
+    $logmsg = "PEAR error: " . $error->getMessage();
+    if(common_config('site', 'logdebug')) {
+        $logmsg .= " : ". $error->getDebugInfo();
+    }
+    common_log(LOG_ERR, $logmsg);
+    if ($error instanceof DB_DataObject_Error) {
+        $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.'),
+                       common_config('site', 'name'),
+                       common_config('site', 'email'));
+    } else {
+        $msg = _('An important error occured, probably related to email setup. '.
+                 'Check logfiles for more info..');
+    }
 
     $dac = new DBErrorAction($msg, 500);
     $dac->showPage();
@@ -58,7 +68,21 @@ function handleError($error)
 
 function main()
 {
-    global $user, $action;
+    // quick check for fancy URL auto-detection support in installer.
+    if (isset($_SERVER['REDIRECT_URL']) && ((dirname($_SERVER['REQUEST_URI']) . '/check-fancy') === $_SERVER['REDIRECT_URL'])) {
+        die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs.");
+    }
+    global $user, $action, $config;
+
+    Snapshot::check();
+
+    if (!_have_config()) {
+        $msg = sprintf(_("No configuration file found. Try running ".
+                         "the installation program first."));
+        $sac = new ServerErrorAction($msg);
+        $sac->showPage();
+        return;
+    }
 
     // For database errors
 
@@ -88,6 +112,8 @@ function main()
 
     $args = array_merge($args, $_REQUEST);
 
+    Event::handle('ArgsInitialize', array(&$args));
+
     $action = $args['action'];
 
     if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) {
@@ -115,14 +141,14 @@ function main()
 
         // XXX: find somewhere for this little block to live
 
-        if ($config['db']['mirror'] && $action_obj->isReadOnly()) {
-            if (is_array($config['db']['mirror'])) {
+        if (common_config('db', 'mirror') && $action_obj->isReadOnly($args)) {
+            if (is_array(common_config('db', 'mirror'))) {
                 // "load balancing", ha ha
-                $k = array_rand($config['db']['mirror']);
-
-                $mirror = $config['db']['mirror'][$k];
+                $arr = common_config('db', 'mirror');
+                $k = array_rand($arr);
+                $mirror = $arr[$k];
             } else {
-                $mirror = $config['db']['mirror'];
+                $mirror = common_config('db', 'mirror');
             }
             $config['db']['database'] = $mirror;
         }