-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwitter_comments.php
101 lines (80 loc) · 2.82 KB
/
twitter_comments.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
<?php
/**
* File of miniTwitter
*
* @author Daniel Plewinski
* @author email: [email protected]
* @link https://github.com/daniel-plewinski/miniTwitter
*/
session_start();
ob_start();
if(!isset($_SESSION["userID"])){
header("location: twitter_wall.php");
die();
}
require 'config.php';
require 'src/User.php';
require 'src/Comment.php';
require 'src/Tweet.php';
include 'template/header.php';
?>
<div class="container">
<?php
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['twit']) && is_numeric(($_GET['twit']))) {
$twitId = $_GET['twit'];
$_SESSION['twitID'] = $twitId;
$tweet = Tweet::getTweetbyID($conn, $twitId);
$tweetAuthorId = Tweet::getAuthorIdByTweetbyID($conn, $twitId);
$tweetAuthorName = USER::getUsernameByID($conn, $tweetAuthorId);
$tweetDate = Tweet::getTweetDateByTweetbyID($conn, $twitId);
$commentsAr = Comment::getCommentsByTweetId($conn, $twitId);
echo "<strong>$tweetAuthorName</strong> pisze w dniu $tweetDate:";
echo "<h3>$tweet</h3>";
echo "<ul>";
foreach ($commentsAr as $comment) {
$commentAuthorId = Comment::getAuthorIdByCommentID($conn, $comment['id']);
$commentAuthorName = USER::getUsernameByID($conn, $commentAuthorId);
echo "<li>" ;
echo $comment['comment_content'] . "<br>";
echo "<i>Napisany przez <strong>" . $commentAuthorName . "</strong> w dniu " . $comment['comment_date'] . "</i>";
echo "</li>";
}
echo "</ul>";
} else {
header("location: twitter_wall.php");
}
} else {
header("location: twitter_wall.php");
}
?>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
</div>
<div>
<form action="" method="post" role="form">
<legend>Dodaj komentarz</legend>
<div class="form-group">
<label for="content">Treść komentarza:</label>
<textarea class="form-control" rows="5" name="content" id="content"></textarea>
</div>
<button type="submit" class="btn btn-primary">Dodaj</button>
</form>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] === "POST") {
if (!empty($_POST['content'])) {
$commentContent = $_POST['content'];
$comment = new Comment();
$comment->setCommentContent($commentContent);
$comment->setUserId($_SESSION['userID']);
$comment->setTweetId($_SESSION['twitID']);
$comment->saveCommentToDB($conn);
echo "Tweet został opublikowany";
} else {
echo "Tweet nie może być pusty";
}
}
?>
</div>
</body>
</html>