]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - index.php
Merge branch 'testing' of gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / index.php
index 997ee6197f27a1b55e222dc932def5f24a4dbd79..06ff9900fd5bff24466be4cbd6ee5ffaeb87ac6e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -29,7 +29,7 @@
  * @author   Robin Millette <millette@controlyourself.ca>
  * @author   Sarven Capadisli <csarven@controlyourself.ca>
  * @author   Tom Adams <tom@holizz.com>
- * 
+ *
  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
  */
 
@@ -146,12 +146,27 @@ function formatBacktraceLine($n, $line)
     return $out;
 }
 
-function checkMirror($action_obj, $args)
+function setupRW()
 {
     global $config;
 
     static $alwaysRW = array('session', 'remember_me');
 
+    // 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';
+
+    foreach ($alwaysRW as $table) {
+        $config['db']['table_'.$table] = 'rw';
+    }
+}
+
+function checkMirror($action_obj, $args)
+{
+    global $config;
+
     if (common_config('db', 'mirror') && $action_obj->isReadOnly($args)) {
         if (is_array(common_config('db', 'mirror'))) {
             // "load balancing", ha ha
@@ -162,16 +177,6 @@ function checkMirror($action_obj, $args)
             $mirror = common_config('db', 'mirror');
         }
 
-        // 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';
-
-        foreach ($alwaysRW as $table) {
-            $config['db']['table_'.$table] = 'rw';
-        }
-
         // everyone else uses the mirror
 
         $config['db']['database'] = $mirror;
@@ -237,9 +242,13 @@ function main()
 
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
 
+    // Make sure RW database is setup
+
+    setupRW();
+
     // XXX: we need a little more structure in this script
 
-    // get and cache current user
+    // get and cache current user (may hit RW!)
 
     $user = common_current_user();
 
@@ -276,8 +285,23 @@ function main()
     if (!$user && common_config('site', 'private')
         && !isLoginAction($action)
         && !preg_match('/rss$/', $action)
-        && !preg_match('/^Api/', $action)
-    ) {
+        && $action != 'robotstxt'
+        && !preg_match('/^Api/', $action)) {
+
+        // set returnto
+        $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'));
         return;
     }