-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_post.php
103 lines (90 loc) · 2.98 KB
/
view_post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?
require 'init.php';
$post_id = $_GET['id'];
$post = get_post_by_id($post_id);
if (!$post) {
display_not_found_page();
}
$comments = get_post_comments($post_id);
$comment_text = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$comment_text = $_POST['comment'];
if ($comment_text == '') {
$errors[] = "Коментар не може бути порожнім.";
}
if (!$errors) {
$user_id = get_current_user_id();
add_comment($post_id, $user_id, $comment_text);
redirect(APP_URL . '/view_post.php?id=' . $post_id);
}
}?>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Tubogram</title>
<? echo js_and_css() ?>
</head>
<?
if (get_current_user_id()) {
page_header('logged');
} else {
page_header('not_logged');
}
?>
<div class="video-player">
<? echo create_youtube_iframe(get_video_id_from_youtube_link($post['link'])) ?>
</div>
<div class="container" style="width: 845px">
<br>
<h4>
Запощено
<a href="<? echo APP_URL . '/user.php?id=' . $post['user_id'] ?>">
<? echo get_username_by_user_id($post['user_id']) ?></a>
<? echo format_date($post['created_at']) ?>
<div class="pull-right">
<? like_button($post_id, get_current_user_id()) ?>
</div>
</h4>
</div>
<div class="container">
<h2>Коментарі <span class="text-muted">
(<? echo get_count_of_comments_by_post_id($post_id) ?>)
</span></h2>
<? if (get_current_user_id()): ?>
<? if ($errors) display_errors($errors) ?>
<div class="well">
<form method="POST" action="<? echo APP_URL ?>/view_post.php?id=<?echo escape_html($post_id) ?>">
<div class="form-group">
<textarea class="form-control" rows="3" name="comment" placeholder="Уведіть ваш коментар"></textarea>
</div>
<input class="btn btn-default" type="submit" value="Додати коментар">
</form>
</div>
<? else: ?>
<div class="alert alert-info">
Для того, щоб залишати коментарі та ставити лайк
<a href="<? echo APP_URL . '/login.php' ?>">увійдіть</a> або
<a href="<? echo APP_URL . '/registration.php' ?>">зареєструйтеся</a>.
</div>
<? endif ?>
<? display_comments($comments) ?>
</div>
<? page_footer() ?>
<script>
$('.like-button.logged-in').on('click', function() {
var $count = $(this).find('.count');
var postId = $(this).data('post');
var liked = $(this).hasClass('liked');
var url = liked ? 'dislike_post.php' : 'like_post.php';
$(this).toggleClass('liked');
$.post(url, {post_id: postId}, function (data) {
$count.text(data);
});
});
$('.like-button').hoverablePopover({
placement: 'left',
trigger: 'manual',
html: true
});
</script>