]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - index.php
utility superclass for plugins
[quix0rs-gnu-social.git] / index.php
index 3cecb5c8b6c3825d5e2e116ba05a2574191231ba..0a79b9731d0aaa97ce321ec47d41bef37c270460 100644 (file)
--- a/index.php
+++ b/index.php
@@ -47,7 +47,10 @@ if (!$user && common_config('site', 'private') &&
 
 $actionfile = INSTALLDIR."/actions/$action.php";
 
-if (file_exists($actionfile)) {
+if (!file_exists($actionfile)) {
+    $cac = new ClientErrorAction(_('Unknown action'), 404);
+    $cac->showPage();
+} else {
 
     include_once $actionfile;
 
@@ -55,7 +58,7 @@ if (file_exists($actionfile)) {
 
     $action_obj = new $action_class();
 
-    if ($config['db']['mirror'] && $action_obj->is_readonly()) {
+    if ($config['db']['mirror'] && $action_obj->isReadOnly()) {
         if (is_array($config['db']['mirror'])) {
             // "load balancing", ha ha
             $k = array_rand($config['db']['mirror']);
@@ -66,9 +69,24 @@ if (file_exists($actionfile)) {
         }
         $config['db']['database'] = $mirror;
     }
-    if (call_user_func(array($action_obj, 'prepare'), $_REQUEST)) {
-        call_user_func(array($action_obj, 'handle'), $_REQUEST);
+
+    try {
+        if ($action_obj->prepare($_REQUEST)) {
+            $action_obj->handle($_REQUEST);
+        }
+    } catch (ClientException $cex) {
+        $cac = new ClientErrorAction($cex->getMessage(), $cex->getCode());
+        $cac->showPage();
+    } catch (ServerException $sex) { // snort snort guffaw
+        $sac = new ServerErrorAction($sex->getMessage(), $sex->getCode());
+        $sac->showPage();
+    } catch (Exception $ex) {
+        $sac = new ServerErrorAction($ex->getMessage());
+        $sac->showPage();
     }
-} else {
-    common_user_error(_('Unknown action'));
-}
\ No newline at end of file
+}
+
+// XXX: cleanup exit() calls or add an exit handler so
+// this always gets called
+
+Event::handle('CleanupPlugin');