--- /dev/null
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta charset="utf-8"/>
+ <title>Like of {{attribute(json, 'like-of').0}}</title>
+ </head>
+ <body class="h-entry">
+ <h1>Like #{{crow.comment_id}}</h1>
+ <p>
+ {% spaceless %}
+ <a class="p-author h-card" href="{{author.url}}">
+ <img class="u-photo" src="{{author.imageurl}}" alt="" width="32" height="32" />
+ {{author.name}}</a>
+ {% endspaceless %}
+ likes
+ <a rel="u-like-of"
+ href="{{attribute(json, 'like-of').0}}">{{attribute(json, 'like-of').0}}</a>.
+ </p>
+ </body>
+</html>
);
$ofUrl = '';
+ $type = null;
if (isset($json->properties->{'in-reply-to'})) {
$ofUrl = reset($json->properties->{'in-reply-to'});
+ $type = 'reply';
+ } else if (isset($json->properties->{'like-of'})) {
+ $ofUrl = reset($json->properties->{'like-of'});
+ $type = 'like';
+ } else {
+ throw new \Exception(
+ 'Invalid post type, only reply and like allowed',
+ 400
+ );
}
+
$stmt->execute(
array(
':userId' => $userId,
':ofUrl' => $ofUrl,
- ':type' => reset($json->type),
+ ':type' => $type,
':json' => json_encode($json),
)
);
exit(1);
}
-if (isset($comment->properties->content['html'])) {
- $htmlContent = $comment->properties->content['html'];
-} else {
- $htmlContent = nl2br($comment->properties->content[0]);
-}
-
$rowComment = $comment->Xrow;
$rowUser = $comment->user;
-render(
- 'comment',
- array(
- 'json' => $comment->properties,
- 'crow' => $rowComment,
- 'comment' => $comment,
- 'author' => array(
- 'name' => $rowUser->user_name,
- 'url' => Urls::full(Urls::user($rowUser->user_id)),
- 'imageurl' => Urls::userImg($rowUser),
- ),
- 'htmlContent' => $htmlContent,
- 'replyUrl' => Urls::full(
- '/reply.php?url=' . urlencode(Urls::full($rowComment->comment_id))
- ),
- )
+
+$vars = array(
+ 'json' => $comment->properties,
+ 'crow' => $rowComment,
+ 'comment' => $comment,
+ 'author' => array(
+ 'name' => $rowUser->user_name,
+ 'url' => Urls::full(Urls::user($rowUser->user_id)),
+ 'imageurl' => Urls::userImg($rowUser),
+ ),
+ 'replyUrl' => Urls::full(
+ '/reply.php?url=' . urlencode(Urls::full($rowComment->comment_id))
+ ),
);
+
+if ($rowComment->comment_type == 'like') {
+ $template = 'post-like';
+} else {
+ //reply
+ $template = 'post-reply';
+ if (isset($comment->properties->content['html'])) {
+ $htmlContent = $comment->properties->content['html'];
+ } else {
+ $htmlContent = nl2br($comment->properties->content[0]);
+ }
+ $vars['htmlContent'] = $htmlContent;
+}
+
+render($template, $vars);
?>
);
}
- if (!isset($json->properties->{'in-reply-to'})) {
- mpError(
- 'HTTP/1.0 400 Bad Request',
- 'invalid_request',
- 'Only replies accepted'
- );
- }
-
$storage = new Storage();
try {
$id = $storage->addComment($json, $userId);
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();
}
}