send linkback when a post is created
[anoweco.git] / www / micropub.php
index 9d91272a7ecf4feb0d6dee4f899e2bf49094ff1f..e028782695fa5ea686b464fa2f125763eb620984 100644 (file)
@@ -82,24 +82,29 @@ function handleCreate($json, $token)
         );
     }
 
-    if (!isset($json->properties->{'in-reply-to'})) {
-        mpError(
-            'HTTP/1.0 400 Bad Request',
-            'invalid_request',
-            'Only replies accepted'
-        );
-    }
-
     $storage = new Storage();
+    $lb      = new Linkback();
     try {
         $id = $storage->addComment($json, $userId);
+        $lb->ping($id);
 
         header('HTTP/1.0 201 Created');
         header('Location: ' . Urls::full(Urls::comment($id)));
         exit();
     } catch (\Exception $e) {
-        //FIXME: return correct status code
-        header('HTTP/1.0 500 Internal Server Error');
+        if ($e->getCode() == 400) {
+            mpError(
+                'HTTP/1.0 400 Bad Request',
+                'invalid_request',
+                $e->getMessage()
+            );
+        }
+
+        mpError(
+            'HTTP/1.0 500 Internal Server Error',
+            'this_violates_the_spec',
+            $e->getMessage()
+        );
         exit();
     }
 }