1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class View |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public $country; |
6
|
|
|
public $city; |
7
|
|
|
public $hashtag; |
8
|
|
|
public $view; |
9
|
|
|
public $postId; |
10
|
|
|
public $isDetailedView; |
11
|
|
|
public $baseUrl; |
12
|
|
|
|
13
|
|
|
public $lastPostId = ''; |
14
|
|
|
|
15
|
|
|
function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '') |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$this->baseUrl = $baseUrl; |
18
|
|
|
$this->country = $country; |
19
|
|
|
$this->city = $city; |
|
|
|
|
20
|
|
|
$this->hashtag = urldecode($hashtag); |
21
|
|
|
$this->view = $view; |
|
|
|
|
22
|
|
|
$this->postId = $postId; |
|
|
|
|
23
|
|
|
|
24
|
|
|
if($postId == '') |
25
|
|
|
{ |
26
|
|
|
$this->isDetailedView = FALSE; |
27
|
|
|
} |
28
|
|
|
else |
29
|
|
|
{ |
30
|
|
|
$this->isDetailedView = TRUE; |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
/** |
34
|
|
|
* Compute HTML Code |
35
|
|
|
*/ |
36
|
|
|
function jodelToHtml($post) |
|
|
|
|
37
|
|
|
{ //ToDO |
|
|
|
|
38
|
|
|
//Replace # with link |
39
|
|
|
//preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
|
|
|
|
40
|
|
|
|
41
|
|
|
//Time to time difference |
42
|
|
|
$now = new DateTime(); |
|
|
|
|
43
|
|
|
$d = new DateTime($post['created_at']); |
|
|
|
|
44
|
|
|
$timediff = $now->diff($d); |
45
|
|
|
|
46
|
|
|
$timediff_inSeconds = (string)$timediff->format('%s'); |
47
|
|
|
$timediff_inMinutes = (string)$timediff->format('%i'); |
48
|
|
|
$timediff_inHours = (string)$timediff->format('%h'); |
|
|
|
|
49
|
|
|
$timediff_inDays = (string)$timediff->format('%d'); |
|
|
|
|
50
|
|
|
$timediff_inMonth = (string)$timediff->format('%m'); |
|
|
|
|
51
|
|
|
|
52
|
|
|
if($timediff_inMonth!=0) |
53
|
|
|
{ |
54
|
|
|
$timediff = $timediff_inMonth . "m"; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
else |
57
|
|
|
{ |
58
|
|
|
if($timediff_inDays!=0) |
59
|
|
|
{ |
60
|
|
|
$timediff = $timediff_inDays . "d"; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
else |
63
|
|
|
{ |
64
|
|
|
if($timediff_inHours!=0) |
65
|
|
|
{ |
66
|
|
|
$timediff = $timediff_inHours . "h"; |
|
|
|
|
67
|
|
|
} |
68
|
|
|
else |
69
|
|
|
{ |
70
|
|
|
if($timediff_inMinutes!=0) |
71
|
|
|
{ |
72
|
|
|
$timediff = $timediff_inMinutes . "m"; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
else |
75
|
|
|
{ |
76
|
|
|
$timediff = $timediff_inSeconds . "s"; |
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
?> |
84
|
|
|
<article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;"> |
|
|
|
|
85
|
|
|
<content> |
86
|
|
|
<?php |
87
|
|
|
if(isset($post['image_url'])) |
88
|
|
|
{ |
89
|
|
|
$regexRest = '/[^\w$ .!?-]+/u'; |
90
|
|
|
|
91
|
|
|
echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">'; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
else { |
94
|
|
|
echo str_replace(' ', ' ', nl2br(htmlspecialchars($post['message']))); |
95
|
|
|
} |
96
|
|
|
?> |
97
|
|
|
</content> |
98
|
|
|
<aside> |
99
|
|
|
<?php |
100
|
|
View Code Duplication |
if($this->isDetailedView) |
|
|
|
|
101
|
|
|
{?> |
102
|
|
|
<a href="index.php?vote=up&getPostDetails=true&postId=<?php echo $post['post_id'];?>&postId_parent=<?php echo htmlspecialchars($_GET['postId']);?>" rel="nofollow"> |
|
|
|
|
103
|
|
|
<?php } |
104
|
|
|
else |
105
|
|
|
{?> |
106
|
|
|
<a href="index.php?vote=up&postId=<?php echo $post['post_id'];?>" rel="nofollow"> |
107
|
|
|
<?php } ?> |
108
|
|
|
<i class="fa fa-angle-up fa-3x"></i> |
109
|
|
|
</a> |
110
|
|
|
<br /> |
111
|
|
|
<?php echo $post["vote_count"];?><br /> |
|
|
|
|
112
|
|
|
<?php |
113
|
|
View Code Duplication |
if($this->isDetailedView) |
|
|
|
|
114
|
|
|
{?> |
115
|
|
|
<a href="index.php?vote=down&getPostDetails=true&postId=<?php echo $post['post_id'];?>&postId_parent=<?php echo htmlspecialchars($_GET['postId']);?>" rel="nofollow"> |
|
|
|
|
116
|
|
|
<?php } |
117
|
|
|
else |
118
|
|
|
{?> |
119
|
|
|
<a href="index.php?vote=down&postId=<?php echo $post['post_id'];?>" rel="nofollow"> |
120
|
|
|
<?php } ?> |
121
|
|
|
<i class="fa fa-angle-down fa-3x"></i> |
122
|
|
|
</a> |
123
|
|
|
</aside> |
124
|
|
|
|
125
|
|
|
<footer> |
126
|
|
|
<span class="wrapper"> |
127
|
|
|
|
128
|
|
|
<span class="time"> |
129
|
|
|
<span class="tip" data-tooltip="Time"> |
130
|
|
|
<i class="fa fa-clock-o"></i> |
131
|
|
|
<?php echo $timediff;?> |
132
|
|
|
<span class="tiptext"><?php echo $d->format('Y-m-d H:i:s');?></span> |
133
|
|
|
</span> |
134
|
|
|
</span> |
135
|
|
|
<?php if(!$this->isDetailedView) {?> |
136
|
|
|
<span class="comments"> |
137
|
|
|
<span data-tooltip="Comments"> |
138
|
|
|
<a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>"> |
139
|
|
|
<i class="fa fa-commenting-o"></i> |
140
|
|
|
<?php if(array_key_exists("child_count", $post)) { |
|
|
|
|
141
|
|
|
echo $post["child_count"]; |
|
|
|
|
142
|
|
|
} else echo "0"; |
|
|
|
|
143
|
|
|
?> |
144
|
|
|
</a> |
145
|
|
|
</span> |
146
|
|
|
|
147
|
|
|
</span> |
148
|
|
|
<?php |
149
|
|
|
} |
150
|
|
|
if (isUserAdmin()) |
151
|
|
|
{ |
152
|
|
|
?> |
153
|
|
|
<span class="voting"> |
154
|
|
|
<a target="_blank" href="admin.php?postId=<?php echo $post['post_id'] ?>"> |
155
|
|
|
<i class="fa fa-thumbs-o-up"></i> Vote |
156
|
|
|
</a> |
157
|
|
|
</span> |
158
|
|
|
<?php |
159
|
|
|
} |
160
|
|
|
?> |
161
|
|
|
<span class="distance"> |
162
|
|
|
<?php |
163
|
|
|
if($this->isDetailedView) |
164
|
|
|
{ |
165
|
|
|
if(isset($post["parent_creator"]) && $post["parent_creator"] == 1) |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
?> |
168
|
|
|
<span data-tooltip="Author"> |
169
|
|
|
<i class="fa fa-user-o"></i> OJ | |
170
|
|
|
</span> |
171
|
|
|
<?php |
172
|
|
|
} |
173
|
|
|
else |
174
|
|
|
{ |
175
|
|
|
//Is not parent Jodel in detailed View |
176
|
|
|
if(!array_key_exists('child_count', $post) && array_key_exists('parent_creator', $post)) |
|
|
|
|
177
|
|
|
{ |
178
|
|
|
?> |
179
|
|
|
<span data-tooltip="Author"> |
180
|
|
|
<i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> | |
|
|
|
|
181
|
|
|
</span> |
182
|
|
|
<?php |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
?> |
187
|
|
|
|
188
|
|
|
<span class="tip" data-tooltip="Distance"> |
189
|
|
|
<i class="fa fa-map-marker"></i> |
190
|
|
|
<?php echo $post['distance'];?> km |
191
|
|
|
<span class="tiptext"><?php echo $post['location']['name'];?></span> |
192
|
|
|
</span> |
193
|
|
|
</span> |
194
|
|
|
|
195
|
|
|
</span> |
196
|
|
|
</footer> |
197
|
|
|
</article> |
198
|
|
|
<?php |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Gets the title. |
204
|
|
|
* |
205
|
|
|
* @return string The title. |
206
|
|
|
*/ |
207
|
|
|
function getTitle($post = '') |
|
|
|
|
208
|
|
|
{ |
209
|
|
|
$title = 'JodelBlue - Top Jodel from ' . htmlspecialchars($this->city) . ' Web-App and Browser-Client'; |
210
|
|
|
|
211
|
|
|
if($post != '' && isset($post['message']) && $post['message'] != '' && $this->isDetailedView) |
212
|
|
|
{ |
213
|
|
|
$title = 'JodelBlue: ' . substr(htmlspecialchars($post['message']), 0, 44); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
return $title; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Gets the meta description. |
221
|
|
|
* |
222
|
|
|
* @return string The meta description. |
223
|
|
|
*/ |
224
|
|
|
function getMetaDescription($post = '') |
|
|
|
|
225
|
|
|
{ |
226
|
|
|
$description = 'JodelBlue is a Web-App and Browser-Client for the Jodel App. No registration required! Browse Jodels in ' . htmlspecialchars($this->city) . ' or all over the world. Send your own Jodels or upvote others.'; |
|
|
|
|
227
|
|
|
|
228
|
|
|
if($post != '' && $this->isDetailedView) |
229
|
|
|
{ |
230
|
|
|
$description = 'On JodelBlue in ' . htmlspecialchars($this->city) . ' with ' . htmlspecialchars($post['vote_count']) . ' Upvotes: ' . substr(htmlspecialchars($post['message']), 0, 130); |
|
|
|
|
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
return $description; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
function getCaptcha($accessToken) |
|
|
|
|
237
|
|
|
{ |
238
|
|
|
$accountCreator = new GetCaptcha(); |
239
|
|
|
$accountCreator->setAccessToken($accessToken); |
240
|
|
|
$captcha = $accountCreator->execute(); |
241
|
|
|
|
242
|
|
|
return array("image_url" => $captcha['image_url'], "key" => $captcha['key']); |
|
|
|
|
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
function showCaptcha($accessToken, $deviceUid) |
|
|
|
|
246
|
|
|
{ |
247
|
|
|
$accountCreator = new GetCaptcha(); |
248
|
|
|
$accountCreator->setAccessToken($accessToken); |
249
|
|
|
$captcha = $accountCreator->execute(); |
250
|
|
|
|
251
|
|
|
echo $captcha['image_url']; |
252
|
|
|
echo('<br><img width="100%" src="' . $captcha['image_url'] . '">'); |
253
|
|
|
echo "<br>Key: " . $captcha['key']; |
|
|
|
|
254
|
|
|
echo "<br>"; |
|
|
|
|
255
|
|
|
|
256
|
|
|
//Form |
257
|
|
|
|
258
|
|
|
echo '<form method="get">'; |
259
|
|
|
echo '<p>Enter Key (copy pasta from top): <input type="text" value="' . $captcha['key'] . '" name="key" /></p>'; |
260
|
|
|
echo '<p>Find the Coons (example: they are on picture 3, 4 and 5. You enter 2-3-4. Becouse we start counting at 0): <input type="text" name="solution" /></p>'; |
|
|
|
|
261
|
|
|
echo '<input type="hidden" name="deviceUid" value="' . $deviceUid . '">'; |
262
|
|
|
echo '<input type="hidden" name="pw" value="upVote">'; |
263
|
|
|
echo '<p><input type="submit" /></p>'; |
264
|
|
|
echo '</form>'; |
265
|
|
|
|
266
|
|
|
die(); |
|
|
|
|
267
|
|
|
|
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
function toUrl() |
|
|
|
|
271
|
|
|
{ |
272
|
|
|
$url = $this->baseUrl . 'index.php?country=DE' . |
273
|
|
|
'&city=' . urlencode($this->city) . |
274
|
|
|
'&hashtag=' . urlencode($this->hashtag) . |
275
|
|
|
'&view=' . $this->view; |
276
|
|
|
if($this->postId != '') |
277
|
|
|
{ |
278
|
|
|
$url .= '&postId=' . $this->postId . |
279
|
|
|
'&getPostDetails=TRUE'; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
return $url; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
function changePostId($postId) |
|
|
|
|
286
|
|
|
{ |
287
|
|
|
$tempView = clone $this; |
|
|
|
|
288
|
|
|
$tempView->postId = $postId; |
|
|
|
|
289
|
|
|
$tempView->isDetailedView = TRUE; |
290
|
|
|
return $tempView; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
function back() |
|
|
|
|
294
|
|
|
{ |
295
|
|
|
$tempView = clone $this; |
|
|
|
|
296
|
|
|
$tempView->postId = ''; |
297
|
|
|
return $tempView; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
function changeView($view) |
|
|
|
|
301
|
|
|
{ |
302
|
|
|
$tempView = clone $this; |
|
|
|
|
303
|
|
|
$tempView->view = $view; |
304
|
|
|
return $tempView; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
function getPosts($jodelAccount) |
|
|
|
|
308
|
|
|
{ |
309
|
|
|
if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL) |
310
|
|
|
{ |
311
|
|
|
$accountCreator = new GetChannel(); |
|
|
|
|
312
|
|
|
$accountCreator->view = $this->view; |
313
|
|
|
$accountCreator->setAccessToken($jodelAccount->accessToken); |
314
|
|
|
$accountCreator->channel = $this->hashtag; |
|
|
|
|
315
|
|
|
$accountCreator->lastPostId = $this->lastPostId; |
316
|
|
|
$data = $accountCreator->execute(); |
|
|
|
|
317
|
|
|
} |
318
|
|
|
else |
319
|
|
|
{ |
320
|
|
|
if($this->lastPostId == '' && $this->view == 'combo') |
321
|
|
|
{ |
322
|
|
|
$url = "/v3/posts/location/combo"; |
|
|
|
|
323
|
|
|
} |
324
|
|
|
else |
325
|
|
|
{ |
326
|
|
|
if($this->view == 'discussed') |
327
|
|
|
{ |
328
|
|
|
$url = "/v2/posts/location/discussed/"; |
|
|
|
|
329
|
|
|
} |
330
|
|
|
else |
331
|
|
|
{ |
332
|
|
|
if($this->view == 'popular') |
333
|
|
|
{ |
334
|
|
|
$url = "/v2/posts/location/popular/"; |
|
|
|
|
335
|
|
|
} |
336
|
|
|
else |
337
|
|
|
{ |
338
|
|
|
$url = "/v2/posts/location/"; |
|
|
|
|
339
|
|
|
} |
340
|
|
|
} |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
$accountCreator = new GetPosts(); |
344
|
|
|
$accountCreator->setLastPostId($this->lastPostId); |
345
|
|
|
$accountCreator->setAccessToken($jodelAccount->accessToken); |
346
|
|
|
$accountCreator->setUrl($url); |
347
|
|
|
$accountCreator->version = 'v3'; |
348
|
|
|
|
349
|
|
|
$config = parse_ini_file('config/config.ini.php'); |
|
|
|
|
350
|
|
|
$location = new Location(); |
351
|
|
|
$location->setLat($config['default_lat']); |
352
|
|
|
$location->setLng($config['default_lng']); |
353
|
|
|
$location->setCityName($config['default_location']); |
354
|
|
|
$accountCreator->location = $location; |
355
|
|
|
$data = $accountCreator->execute(); |
|
|
|
|
356
|
|
|
} |
357
|
|
|
if(array_key_exists('recent', $data)) |
358
|
|
|
{ |
359
|
|
|
return $data['recent']; |
360
|
|
|
} |
361
|
|
|
else if(array_key_exists('posts', $data)) |
362
|
|
|
{ |
363
|
|
|
return $data['posts']; |
364
|
|
|
} |
365
|
|
|
else |
366
|
|
|
{ |
367
|
|
|
error_log('Fehler View getPosts '); |
368
|
|
|
error_log(print_r($data, true)); |
369
|
|
|
|
370
|
|
|
$notFound[0] = array( |
|
|
|
|
371
|
|
|
"post_id" => "0", |
|
|
|
|
372
|
|
|
"discovered_by" => 0, |
|
|
|
|
373
|
|
|
"message" => "Not found", |
|
|
|
|
374
|
|
|
"created_at" => "2017-02-11T16:44:50.385Z", |
|
|
|
|
375
|
|
|
"updated_at" => "2017-02-11T16:44:50.385Z", |
|
|
|
|
376
|
|
|
"pin_count" => 0, |
|
|
|
|
377
|
|
|
"color" => "FFBA00", |
|
|
|
|
378
|
|
|
"got_thanks" => FALSE, |
|
|
|
|
379
|
|
|
"post_own" => "friend", |
|
|
|
|
380
|
|
|
"discovered" => 0, |
|
|
|
|
381
|
|
|
"distance" => 9, |
|
|
|
|
382
|
|
|
"vote_count" => 0, |
|
|
|
|
383
|
|
|
"location" => |
|
|
|
|
384
|
|
|
array("name" => "Berlin", |
|
|
|
|
385
|
|
|
"loc_coordinates" => |
|
|
|
|
386
|
|
|
array( |
387
|
|
|
"lat" => 0, |
|
|
|
|
388
|
|
|
"lng" => 0 |
|
|
|
|
389
|
|
|
), |
390
|
|
|
"loc_accuracy" => 0, |
|
|
|
|
391
|
|
|
"country" => "", |
|
|
|
|
392
|
|
|
"city" => "", |
|
|
|
|
393
|
|
|
), |
394
|
|
|
"tags" => |
|
|
|
|
395
|
|
|
array(), |
396
|
|
|
"user_handle" => "0" |
|
|
|
|
397
|
|
|
); |
398
|
|
|
return $notFound; |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
} |
|
|
|
|
402
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.