pre-fill auth form with $me data
[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->getComment($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 if (isset($comment->properties->content['html'])) {
30     $htmlContent = $comment->properties->content['html'];
31 } else {
32     $htmlContent = nl2br($comment->properties->content[0]);
33 }
34
35 $rowComment = $comment->Xrow;
36 $rowUser    = $comment->user;
37 render(
38     'comment',
39     array(
40         'json' => $comment->properties,
41         'crow' => $rowComment,
42         'comment' => $comment,
43         'author'  => array(
44             'name' => $rowUser->user_name,
45             'url'  => Urls::full(Urls::user($rowUser->user_id)),
46             'imageurl' => Urls::userImg($rowUser),
47         ),
48         'htmlContent' => $htmlContent,
49         'replyUrl' => Urls::full(
50             '/reply.php?url=' . urlencode(Urls::full($rowComment->comment_id))
51         ),
52     )
53 );
54 ?>