Author
|
zPlus <->
2016-03-23 20:30:32
|
Committer
|
zPlus <->
2016-03-23 20:30:32
|
Commit
|
898d592
(patch)
|
Tree
|
01a17b8
|
Parent(s)
|
|
post, reply: Prevent empty comments
commits diff:
6f0f083..898d592
5 files changed,
32 insertions,
9 deletions
—
download
Diffstat
Diff options
+14/-5
M post.php
12
|
12
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
13
|
13
|
|
{
|
14
|
14
|
|
// Must be logged in
|
15
|
|
- |
if (!Session::is_valid())
|
|
15
|
+ |
if (!Session::is_valid ())
|
16
|
16
|
|
{
|
17
|
17
|
|
header ('Location: ./');
|
18
|
18
|
|
exit ();
|
28
|
28
|
|
// Clear input data
|
29
|
29
|
|
$comment = trim ($_POST['new_comment']);
|
30
|
30
|
|
|
31
|
|
- |
if (strlen($comment) == 0)
|
|
31
|
+ |
// Empty text... do nothing
|
|
32
|
+ |
if (strlen ($comment) == 0)
|
32
|
33
|
|
{
|
33
|
|
- |
header ('Location: ./');
|
34
|
|
- |
exit ();
|
|
34
|
+ |
// Retrieve the post
|
|
35
|
+ |
$post = $db->get_post ($_GET['hash_id']);
|
|
36
|
+ |
|
|
37
|
+ |
if (is_null ($post) || empty ($post))
|
|
38
|
+ |
exit ();
|
|
39
|
+ |
|
|
40
|
+ |
header ('Location: ./' . $post['hashId']);
|
|
41
|
+ |
exit();
|
35
|
42
|
|
}
|
36
|
43
|
|
|
|
44
|
+ |
// Everything seems OK, add the new comment
|
37
|
45
|
|
$post_hash_id = $_GET['hash_id'];
|
38
|
46
|
|
|
39
|
47
|
|
$db->new_comment ($comment, $post_hash_id, Session::get_userid());
|
49
|
57
|
|
// Retrieve the post
|
50
|
58
|
|
$post = $db->get_post ($_GET['hash_id']);
|
51
|
59
|
|
|
52
|
|
- |
if (empty ($post))
|
|
60
|
+ |
// Wrong hash_id
|
|
61
|
+ |
if (is_null ($post) || empty ($post))
|
53
|
62
|
|
{
|
54
|
63
|
|
echo '404';
|
55
|
64
|
|
exit ();
|
+15/-1
M reply.php
32
|
32
|
|
|
33
|
33
|
|
$parent_comment = $db->get_comment ($_POST['parent_comment']);
|
34
|
34
|
|
|
35
|
|
- |
$hash_id = $db->new_reply ($_POST['text'], $parent_comment['hashId'], Session::get_userid ());
|
|
35
|
+ |
$text = trim ($_POST['text']);
|
|
36
|
+ |
|
|
37
|
+ |
// Empty comment. Redirect to parent comment
|
|
38
|
+ |
if (strlen ($text) == 0)
|
|
39
|
+ |
{
|
|
40
|
+ |
header ('Location: ./post/' . $parent_comment['postHashId'] . '#comment-' . $parent_comment['hashId']);
|
|
41
|
+ |
exit ();
|
|
42
|
+ |
}
|
|
43
|
+ |
|
|
44
|
+ |
// We have a text, add the reply and redirect to the new reply
|
|
45
|
+ |
|
|
46
|
+ |
$hash_id = $db->new_reply (
|
|
47
|
+ |
$text,
|
|
48
|
+ |
$parent_comment['hashId'],
|
|
49
|
+ |
Session::get_userid ());
|
36
|
50
|
|
|
37
|
51
|
|
// Can't post?! What happened?!
|
38
|
52
|
|
if (is_null ($hash_id))
|
+1/-1
M submit.php
5
|
5
|
|
require_once 'twig.php';
|
6
|
6
|
|
|
7
|
7
|
|
// Must be logged in
|
8
|
|
- |
if (!Session::is_valid())
|
|
8
|
+ |
if (!Session::is_valid ())
|
9
|
9
|
|
{
|
10
|
10
|
|
header ('Location: ./login');
|
11
|
11
|
|
exit ();
|
+1/-1
M template/post.twig
40
|
40
|
|
|
41
|
41
|
|
{% if user %}
|
42
|
42
|
|
<form action="" method="post" class="new_comment">
|
43
|
|
- |
<textarea name="new_comment" class="form-control" placeholder="Write a comment"></textarea>
|
|
43
|
+ |
<textarea name="new_comment" required="required" class="form-control" placeholder="Write a comment"></textarea>
|
44
|
44
|
|
<input type="submit" value="Add comment" class="btn btn-primary" />
|
45
|
45
|
|
</form>
|
46
|
46
|
|
{% endif %}
|
+1/-1
M template/reply.twig
16
|
16
|
|
<input type="hidden" name="parent_comment" value="{{ comment.hashId }}" />
|
17
|
17
|
|
|
18
|
18
|
|
<div style="margin: 2em 0;">
|
19
|
|
- |
<textarea name="text" rows=10 class="form-control"></textarea>
|
|
19
|
+ |
<textarea name="text" required="required" rows=10 class="form-control"></textarea>
|
20
|
20
|
|
</div>
|
21
|
21
|
|
|
22
|
22
|
|
<div>
|