Update composer package pear2/services_linkback from v0.3.0 to v0.4.0
[anoweco.git] / www / comment.php
1 <?php
2 namespace anoweco;
3 require 'www-header.php';
4
5 if (!isset($_GET['id'])) {
6     header('HTTP/1.0 400 Bad Request');
7     header('Content-Type: text/plain');
8     echo "id parameter missing\n";
9     exit(1);
10 }
11 if (!is_numeric($_GET['id'])) {
12     header('HTTP/1.0 400 Bad Request');
13     header('Content-Type: text/plain');
14     echo "Invalid id parameter value\n";
15     exit(1);
16 }
17
18 $id = intval($_GET['id']);
19
20 $storage = new Storage();
21 $comment = $storage->getJsonComment($id);
22 if ($comment === null) {
23     header('HTTP/1.0 404 Not Found');
24     header('Content-Type: text/plain');
25     echo "Comment not found\n";
26     exit(1);
27 }
28
29 $rowComment = $comment->Xrow;
30 $rowUser    = $comment->user;
31
32 $vars = array(
33     'json' => $comment->properties,
34     'crow' => $rowComment,
35     'comment' => $comment,
36     'author'  => array(
37         'name' => $rowUser->user_name,
38         'url'  => Urls::full(Urls::user($rowUser->user_id)),
39         'imageurl' => Urls::userImg($rowUser),
40     ),
41     'postUrl' => Urls::full(Urls::comment($rowComment->comment_id)),
42     'replyUrl' => Urls::reply(
43         Urls::full(Urls::comment($rowComment->comment_id))
44     ),
45 );
46
47 if ($rowComment->comment_type == 'like') {
48     $template = 'post-like';
49 } else {
50     //reply
51     $template = 'post-reply';
52     if (isset($comment->properties->content['html'])) {
53         $htmlContent = $comment->properties->content['html'];
54     } else {
55         $htmlContent = nl2br($comment->properties->content[0]);
56     }
57     $vars['htmlContent'] = $htmlContent;
58 }
59
60 if (isset($linkbackEndpoint) && $linkbackEndpoint) {
61     header('X-Pingback: ' . $linkbackEndpoint);
62     header('Link: <' . $linkbackEndpoint . '>; rel="webmention"');
63 }
64
65 render($template, $vars);
66 ?>