-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjodels.php
255 lines (233 loc) · 7.94 KB
/
jodels.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
session_start();
require 'functions/jodelmeta.php';
//Set default values for head & load it
$title = "Posts | SocialDomayn";
$stylesheet = "jodel.css";
include 'functions/header.php';
//Load API functions
require 'functions/apicalls.php';
$config = require('config.php');
require 'functions/votes.php';
require 'functions/usermanipulation.php';
require 'functions/admintools.php';
$apiroot = $config->apiUrl;
$baseurl = $config->baseUrl;
$uploaddir = $config->image_upload_dir;
$mainaction = true;
if(!isset($_SESSION['userid'])) {
header('Location: ' . $config->baseUrl . 'login.php');
}
//get ID of the user
$userid = $_SESSION['userid'];
//Get data about the user and save it in session values
$callurl = $apiroot . "jodlers?transform=1&filter=jodlerID,eq," . $userid;
$userjson = getCall($callurl);
$user = json_decode($userjson, true);
foreach($user['jodlers'] as $jodler){
$karma = $jodler['karma'];
$accstate = $jodler['account_state'];
}
$_SESSION['karma'] = $karma;
$_SESSION['acctype'] = $accstate;
//If a user is a normal user and has enough reputation, promote to mod
if($karma >= $config->karma_calc['promote_mod'] && $accstate == 1){
//set dummy caps for manipulateUserFunction
$mycaps = array();
$mycaps['promote_to_mod'] = true;
$updated = manipulateUser($userid, 2, $mycaps);
//destroy caps to aviod abuse
unset($mycaps);
}
if(isset($_GET['deletepost'])){
$post2delete = $_GET['deletepost'];
deletePost($post2delete);
header('Location: ' . $baseurl . 'jodels.php');
}
//if joels.php?upvotejodel=$jodelID is called, upvote it
if(isset($_GET['upvotejodel'])){
$mainaction = false;
voteJodel( $_GET['upvotejodel'], "up");
}
//if jodels.php?downvotejodel=$jodelID ist called, downvote post
if(isset($_GET['downvotejodel'])){
$mainaction = false;
voteJodel( $_GET['downvotejodel'], "down");
}
if($mainaction == true){
//If jodels.php?sort=$sort is called, post should be sorted
if(isset($_GET['sort'])){
$parameter = $_GET['sort'];
//check how posts should be sorted
switch ($parameter){
case "latest":
$sort = "latest";
break;
case "hot":
$sort = "hot";
break;
case "popular":
$sort = "popular";
break;
case "my":
$sort = "my";
break;
case "mycomms":
$sort= "mycomms";
break;
case "myvotes":
$sort = "myvotes";
break;
default:
$sort = "latest";
}
}
?>
<!-- Top / Main Navigation -->
<div id="top"></div>
<ul class="nav justify-content-center">
<!-- Refresh page -->
<li class="nav-item">
<a class="nav-link" href="javascript:window.location.reload();"><i class="fa fa-refresh" aria-hidden="true"></i></a>
</li>
<!-- Latest posts -->
<li class="nav-item">
<a class="nav-link <?php if($sort == 'latest' || !isset($sort)){ echo 'active';}?>" href="?sort=latest"><?php echo $config->app_vocabulary['latest'];?></a>
</li>
<!-- Most comments -->
<li class="nav-item">
<a class="nav-link <?php if($sort == 'hot'){ echo 'active';}?>" href="?sort=hot"><?php echo $config->app_vocabulary['hotest'];?></a>
</li>
<!-- most votes -->
<li class="nav-item">
<a class="nav-link <?php if($sort == 'popular'){ echo 'active';}?>" href="?sort=popular"><?php echo $config->app_vocabulary['popular'];?></a>
</li>
<!-- user profile -->
<li class="nav-item">
<a class="nav-link <?php if($sort == 'my' || $sort =='mycomms' || $sort =='myvotes'){ echo 'active';}?>" href="user.php"><i class="fa fa-user" aria-hidden="true"></i><?php echo $karma;?></a>
</li>
</ul>
<!-- must check in stylesheet -->
<div class="test"></div>
<?php
if(isset($_SESSION['errorMsg'])) {
?>
<div class="alert alert-danger" role="alert">
<strong>Holy guacamole!</strong> <?php echo $_SESSION['errorMsg'];?>
</div>
<?php
}
//set up url where posts are stored
$postsUrl = $apiroot . "jodeldata?transform=1";
//setup post filter (as selected in main menu)
switch ($sort){
case "latest":
$filter = "";
break;
case "hot":
$filter = "&order=comments_cnt,desc";
break;
case "popular":
$filter = "&order=votes_cnt,desc";
break;
case "my":
$filter="&filter=jodlerIDFK,eq," . $userid;
break;
case "mycomms":
$commenturl = $apiroot . "comments?transform=1,filter=jodlerIDFK,eq," . $userid;
$commentsjson = getCall($commenturl);
$comments = json_decode($commentsjson, true);
$filter = "";
foreach($comments['comments'] as $comment){
$filter .= "&filter[]=jodelID,eq," . $comment['jodelIDFK'];
}
$filter .= "&satisfy=any";
break;
case "myvotes":
$voteurl = $apiroot . "jodelvotes?transform=1&userIDFK,eq," . $userid;
$votesjson = getCall($voteurl);
$votes = json_decode($votesjson, true);
$filter = "";
foreach($votes['jodelvotes'] as $vote){
$filter .= "&filter[]=jodelID,eq," . $vote['jodelIDFK'];
}
$filter .= "&satisfy=any";
break;
default:
$filter = "";
}
//setup api call with filter
$jodelsUrl = $postsUrl . $filter;
$posts = getCall($jodelsUrl);
$postdata = json_decode($posts, true);
//process posts
/*
$reportjson = getCall($apiroot . "reports?transform=1");
$reports = json_decode($reportjson, true);
$postAndResons = array();
foreach($reports['reports'] as $report){
$postAndResons[$report['jodelIDFK']] = $report['abuseIDFK'];
}
*/
if(file_exists('user/notice.txt')){
$notice = file_get_contents('user/notice.txt');
?>
<div class="card card-inverse mb-3 text-center" style="background-color: grey;">
<div class="card-block">
<blockquote class="card-blockquote">
<?php
echo $notice;
?>
</blockquote>
</div>
</div>
<?php
}
foreach($postdata['jodeldata'] as $post){
if($post['score'] <= $config->postmeta['needed_score_mod'] /* && $postAndResons[$post['jodelID']] != $config->postmeta['system_mod_id']*/){
$reported = reportContent( "post", $post['jodelID'], $config->postmeta['system_mod_id']);
}
//setup layout
if($post['votes_cnt'] > $config->postmeta['needed_downvotes']){
?>
<div class="card card-inverse mb-3 text-center" id="<?php echo $post['jodelID'];?>" style="background-color: #<?php echo $post['colorhex'];?>;">
<div class="card-block">
<blockquote class="card-blockquote">
<?php
//post isn't downvoted
if(!isset($post['path'])){
echo $post['jodel'];
} else {
echo '<br><img src="' . $uploaddir . $post['path'] . '" alt="jodelimage">';
}
?>
<!-- voting and number of votes -->
<div class="jodelvotes">
<a href="?upvotejodel=<?php echo $post['jodelID'];?>"<i class="fa fa-angle-up" aria-hidden="true"></i></a><br>
<?php echo $post['votes_cnt'] . "<br>";?>
<a href="?downvotejodel=<?php echo $post['jodelID'];?>"<i class="fa fa-angle-down" aria-hidden="true"></i></a>
</div>
<div class="clear"></div>
<!-- end voting and number of votes -->
<!-- post metadata -->
<div class="jodelmeta">
<?php
$timeago = jodelage($post['createdate']);
?>
<?php echo " ";?><i class="fa fa-clock-o" aria-hidden="true"></i><span id="<?php echo 'time-' . $post['jodelID'];?>"><?php echo $timeago;?></span>
<?php echo " " ;?><a href="comments.php?showcomment=<?php echo $post['jodelID'];?>"><i class="fa fa-comment" aria-hidden="true"></i><?php echo $post['comments_cnt'];?></a>
<?php if ($post['account_state'] == 4){echo '<i class="adminmark fa fa-check-square" aria-hidden="true"></i>';}?>
<?php if ($post['jodlerIDFK'] == $userid){ echo '<a href="?deletepost=' . $post['jodelID'] . '"><i class="fa fa-trash-o" aria-hidden="true"></i></a>';}?>
<!-- end post metadata -->
</blockquote>
</div> <!-- end post card somewhere here -->
</div><?php
}
}
?>
<!-- new post button -->
<div class="newpost"><a href="new.php"><i class="fa fa-plus-circle" aria-hidden="true"></a></i></div>
<?php
//include footer
include 'functions/footer.php';
}