forked from SAAR-IITP/SAAR-IITP
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpostdata.php
145 lines (133 loc) · 7.45 KB
/
postdata.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
session_start();
if(isset($_GET['post_id'])){
$post_id = $_GET['post_id'];
// $url = 'http://localhost:8080/SAAR-Server/getPostInfo.php?post_id='.$post_id;
$url = 'http://api.saar.iitp.ac.in/getPostInfo.php?post_id='.$post_id;
$response = file_get_contents($url);
// echo $response;
$response = json_decode($response,true);
if($response['status']==409){
echo $response['message'];
}else if($response['status']==210){
$data = $response['data'];
$images = unserialize($data['images']);
echo '
<div class="post_heading">'.$data['title'].'</div>
<div class="subhead" style="">
<div>
<i class="fa fa-clock-o"></i> Posted on: '.$data['post_time'][0].' at '.$data['post_time'][1].' | '.$data['no_of_comment'].' comments
</div>
<div class="btns">
<button id="refresh" class="btn btn-md btn-secondary">Refresh</button>
</div>
</div>
<hr style="margin-top: 50px;">
<div class="jumbotron">
<div class="row">
<div class="col-lg-1 col-sm-2 res">
<img src="'.$data['user_img'].'" class="profile_image" ></img>
<div class="username"><strong>'.$data['user_name'].'</strong></div>
</div>
<div class="col-lg-9 col-sm-8">
<p class="post_body">'.$data['body'].'</p>
<div class="row">';
foreach($images as $image){
echo '<div class="col-sm-6">
<a target="_blank" href="http://localhost/SAAR-IITP/uploads/'.$image.'" ><img class="pp_img" src="http://localhost/SAAR-IITP/uploads/'.$image.'" alt="Image" ></a>
</div>';
}
if($response['data']['user_id']==$_SESSION['user_id']){
echo '</div>
<hr style="margin-top:10px">
<div style="display: inline-block; cursor: pointer;"><i class="fa fa-commenting" aria-hidden="true"></i> '.$data['no_of_comment'].'</div>
<div class="up" id="upvote_post" style="display: inline-block; cursor: pointer;">
<i class="fa fa-thumbs-up"></i> '.$data['upvotes'].'
</div>
<div class="down" id="downvote_post" style="display: inline-block; cursor: pointer;">
<i class="fa fa-thumbs-down"></i> '.$data['downvotes'].'
</div>
</div>
<div class="col-lg-2 col-sm-2">
<div id="delete_post">
<button class="btn btn-danger btn-sm"><i class="fa fa-trash" aria-hidden="true"></i> DELETE POST</button>
</div>
</div>
<div class="post_time" style=""><i class="fa fa-clock-o"></i> Posted on: '.$data['post_time'][0].' at '.$data['post_time'][1].'</div>
</div>';
}
else{
echo '</div>
<hr style="margin-top:10px">
<div style="display: inline-block; cursor: pointer;"><i class="fa fa-commenting" aria-hidden="true"></i> '.$data['no_of_comment'].'</div>
<div class="up" id="upvote_post" style="display: inline-block; cursor: pointer;">
<i class="fa fa-thumbs-up"></i> '.$data['upvotes'].'
</div>
<div class="down" id="downvote_post" style="display: inline-block; cursor: pointer;">
<i class="fa fa-thumbs-down"></i> '.$data['downvotes'].'
</div>
</div>
<div class="col-lg-2 col-sm-2">
</div>
<div class="post_time" style=""><i class="fa fa-clock-o"></i> Posted on: '.$data['post_time'][0].' at '.$data['post_time'][1].'</div>
</div>';
}
echo '</div>
';
$replies = $response['replies'];
foreach($replies as $reply){
if($reply['user_id']==$_SESSION['user_id'])
{
echo '
<div class="jumbotron">
<div class="row">
<div class="col-lg-1 col-sm-2 res">
<img src="'.$reply['user_img'].'" class="profile_image" ></img>
<div class="username"><strong>'.$reply['user_name'].'</strong></div>
</div>
<div class="col-lg-11 col-sm-10">
<p class="post_body">'.$reply['body'].'</p>
<hr style="margin-top:10px">
<div class="up" id="upvote_comment" data-id="'.$reply['comment_id'].'" style="display: inline-block; cursor: pointer;">
<i class="fa fa-thumbs-up"></i> '.$reply['upvotes'].'
</div>
<div class="down" id="downvote_comment" data-id="'.$reply['comment_id'].'" style="display: inline-block; cursor: pointer;">
<i class="fa fa-thumbs-down"></i> '.$reply['downvotes'].'
</div>
<div id="delete_comment" data-id="'.$reply['comment_id'].'" style="display: inline-block; cursor: pointer;">
<button class="btn btn-primary">delete</button>
</div>
<span><i class="fa fa-clock-o"></i> Commented on: '.$reply['time'][0].' at '.$reply['time'][1].'</span>
</div>
</div>
</div>
';
}else{
echo '
<div class="jumbotron">
<div class="row">
<div class="col-lg-1 col-sm-2 res">
<img src="'.$reply['user_img'].'" class="profile_image" ></img>
<div class="username"><strong>'.$reply['user_name'].'</strong></div>
</div>
<div class="col-lg-11 col-sm-10">
<p class="post_body">'.$reply['body'].'</p>
<hr style="margin-top:10px">
<div class="up" id="upvote_comment" data-id="'.$reply['comment_id'].'" style="display: inline-block; cursor: pointer;">
<i class="fa fa-thumbs-up"></i> '.$reply['upvotes'].'
</div>
<div class="down" id="downvote_comment" data-id="'.$reply['comment_id'].'" style="display: inline-block; cursor: pointer;">
<i class="fa fa-thumbs-down"></i> '.$reply['downvotes'].'
</div>
<span><i class="fa fa-clock-o"></i> Commented on: '.$reply['time'][0].' at '.$reply['time'][1].'</span>
</div>
</div>
</div>
';
}
}
}
}else{
echo "Post not found";
}
?>