+ // quick check for fancy URL auto-detection support in installer.
+ if (isset($_SERVER['REDIRECT_URL']) && (preg_replace("/^\/$/", "", (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;
+
+ 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
+
+ PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
+
+ // XXX: we need a little more structure in this script
+
+ // get and cache current user
+
+ $user = common_current_user();
+
+ // initialize language env
+
+ common_init_language();
+
+ $path = getPath($_REQUEST);
+
+ $r = Router::get();
+
+ $args = $r->map($path);
+
+ if (!$args) {
+ $cac = new ClientErrorAction(_('Unknown page'), 404);
+ $cac->showPage();
+ return;
+ }
+
+ $args = array_merge($args, $_REQUEST);
+
+ Event::handle('ArgsInitialize', array(&$args));
+
+ $action = $args['action'];
+
+ if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) {
+ common_redirect(common_local_url('public'));
+ return;
+ }
+
+ // If the site is private, and they're not on one of the "public"
+ // parts of the site, redirect to login
+
+ if (!$user && common_config('site', 'private')
+ && !isLoginAction($action)
+ && !preg_match('/rss$/', $action)
+ && !preg_match('/^Api/', $action)
+ ) {
+ // set returnto
+ $rargs =& common_copy_args($args);
+ unset($rargs['action']);
+ if (common_config('site', 'fancy')) {
+ unset($rargs['p']);