-
Notifications
You must be signed in to change notification settings - Fork 0
/
posts.php
executable file
·47 lines (37 loc) · 1.13 KB
/
posts.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
<?php
require_once "lib/User.php";
require_once "lib/Post.php";
require_once "lib/Comment.php";
require_once "lib/PDO.php";
require_once "lib/UsersMapper.php";
require_once "lib/PostsMapper.php";
require_once "lib/CommentMapper.php";
$usersMapper = new UsersMapper($DBH);
$postsMapper = new PostsMapper($DBH);
$commentMapper = new CommentMapper($DBH);
$comments = [];
if (isset($_COOKIE['userscookie']['code'])) {
$code = $_COOKIE['userscookie']['code'];
$user = $usersMapper->getUserbyCode($code);
$userposts = $postsMapper->getAllPostsByUser($user->getID());
$logined = 1;
} else {
$logined = 0;
}
if (isset($_GET['postid'])) {
$post_id = $_GET['postid'];
$comments = $commentMapper->getAllComments($post_id);
$post = $postsMapper->getPost($post_id);
if (isset($_POST['submitcom'])) {
$comment = new Comment;
$comment->setFields($_POST);
$comment->setPostID($post_id);
$commentMapper->addComment($comment);
}
include "templates/postshow.html";
die();
}
$posts =[];
$posts = $postsMapper->getAllPosts();
$numposts = count($posts);
include "templates/listposts.html";