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 = '#all', $view = 'time', $postId = '') |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$this->baseUrl = $baseUrl; |
18
|
|
|
$this->country = $country; |
19
|
|
|
$this->city = $city; |
|
|
|
|
20
|
|
|
$this->hashtag = $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
|
|
|
<table> |
127
|
|
|
<tr> |
128
|
|
|
<td 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
|
|
|
</td> |
135
|
|
|
<td class="comments"> |
136
|
|
|
<?php if(!$this->isDetailedView) {?> |
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
|
|
|
<?php } ?> |
147
|
|
|
</td> |
148
|
|
|
<td class="distance"> |
149
|
|
|
<?php |
150
|
|
|
if($this->isDetailedView) |
151
|
|
|
{ |
152
|
|
|
if(isset($post["parent_creator"]) && $post["parent_creator"] == 1) |
|
|
|
|
153
|
|
|
{ |
154
|
|
|
?> |
155
|
|
|
<span data-tooltip="Author"> |
156
|
|
|
<i class="fa fa-user-o"></i> OJ | |
157
|
|
|
</span> |
158
|
|
|
<?php |
159
|
|
|
} |
160
|
|
|
else |
161
|
|
|
{ |
162
|
|
|
//Is not parent Jodel in detailed View |
163
|
|
|
if(!array_key_exists('child_count', $post) && array_key_exists('parent_creator', $post)) |
|
|
|
|
164
|
|
|
{ |
165
|
|
|
?> |
166
|
|
|
<span data-tooltip="Author"> |
167
|
|
|
<i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> | |
|
|
|
|
168
|
|
|
</span> |
169
|
|
|
<?php |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
?> |
174
|
|
|
|
175
|
|
|
<span class="tip" data-tooltip="Distance"> |
176
|
|
|
<i class="fa fa-map-marker"></i> |
177
|
|
|
<?php echo $post['distance'];?> km |
178
|
|
|
<span class="tiptext"><?php echo $post['location']['name'];?></span> |
179
|
|
|
</span> |
180
|
|
|
</td> |
181
|
|
|
</tr> |
182
|
|
|
</table> |
183
|
|
|
</footer> |
184
|
|
|
</article> |
185
|
|
|
<?php |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Gets the title. |
191
|
|
|
* |
192
|
|
|
* @return string The title. |
193
|
|
|
*/ |
194
|
|
|
function getTitle($post) |
|
|
|
|
195
|
|
|
{ |
196
|
|
|
$title = 'JodelBlue - Web-App and Browser-Client'; |
197
|
|
|
|
198
|
|
|
if($this->isDetailedView) |
199
|
|
|
{ |
200
|
|
|
$title = 'JodelBlue: ' . substr(htmlspecialchars($post['message']), 0, 44); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return $title; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Gets the meta description. |
208
|
|
|
* |
209
|
|
|
* @return string The meta description. |
210
|
|
|
*/ |
211
|
|
|
function getMetaDescription($post) |
|
|
|
|
212
|
|
|
{ |
213
|
|
|
$description = 'JodelBlue is a Web-App and Browser-Client for the Jodel App. No registration required! Browse Jodels all over the world. Send your own Jodels or upvote others.'; |
|
|
|
|
214
|
|
|
|
215
|
|
|
if($this->isDetailedView) |
216
|
|
|
{ |
217
|
|
|
$description = 'On JodelBlue with ' . htmlspecialchars($post['vote_count']) . ' Upvotes: ' . substr(htmlspecialchars($post['message']), 0, 140); |
|
|
|
|
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
return $description; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
function getCaptcha($accessToken) |
|
|
|
|
224
|
|
|
{ |
225
|
|
|
$accountCreator = new GetCaptcha(); |
226
|
|
|
$accountCreator->setAccessToken($accessToken); |
227
|
|
|
$captcha = $accountCreator->execute(); |
228
|
|
|
|
229
|
|
|
return array("image_url" => $captcha['image_url'], "key" => $captcha['key']); |
|
|
|
|
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
function showCaptcha($accessToken, $deviceUid) |
|
|
|
|
233
|
|
|
{ |
234
|
|
|
$accountCreator = new GetCaptcha(); |
235
|
|
|
$accountCreator->setAccessToken($accessToken); |
236
|
|
|
$captcha = $accountCreator->execute(); |
237
|
|
|
|
238
|
|
|
echo $captcha['image_url']; |
239
|
|
|
echo('<br><img width="100%" src="' . $captcha['image_url'] . '">'); |
240
|
|
|
echo "<br>Key: " . $captcha['key']; |
|
|
|
|
241
|
|
|
echo "<br>"; |
|
|
|
|
242
|
|
|
|
243
|
|
|
//Form |
244
|
|
|
|
245
|
|
|
echo '<form method="get">'; |
246
|
|
|
echo '<p>Enter Key (copy pasta from top): <input type="text" value="' . $captcha['key'] . '" name="key" /></p>'; |
247
|
|
|
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>'; |
|
|
|
|
248
|
|
|
echo '<input type="hidden" name="deviceUid" value="' . $deviceUid . '">'; |
249
|
|
|
echo '<input type="hidden" name="pw" value="upVote">'; |
250
|
|
|
echo '<p><input type="submit" /></p>'; |
251
|
|
|
echo '</form>'; |
252
|
|
|
|
253
|
|
|
die(); |
|
|
|
|
254
|
|
|
|
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
function toUrl() |
|
|
|
|
258
|
|
|
{ |
259
|
|
|
$url = $this->baseUrl . 'index.php?country=DE' . |
260
|
|
|
'&city=' . $this->city . |
261
|
|
|
'&hashtag=' . urlencode($this->hashtag) . |
262
|
|
|
'&view=' . $this->view; |
263
|
|
|
if($this->postId != '') |
264
|
|
|
{ |
265
|
|
|
$url .= '&postId=' . $this->postId . |
266
|
|
|
'&getPostDetails=TRUE'; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
return $url; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
function changePostId($postId) |
|
|
|
|
273
|
|
|
{ |
274
|
|
|
$tempView = clone $this; |
|
|
|
|
275
|
|
|
$tempView->postId = $postId; |
|
|
|
|
276
|
|
|
$tempView->isDetailedView = TRUE; |
277
|
|
|
return $tempView; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
function back() |
|
|
|
|
281
|
|
|
{ |
282
|
|
|
$tempView = clone $this; |
|
|
|
|
283
|
|
|
$tempView->postId = ''; |
284
|
|
|
return $tempView; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
function changeView($view) |
|
|
|
|
288
|
|
|
{ |
289
|
|
|
$tempView = clone $this; |
|
|
|
|
290
|
|
|
$tempView->view = $view; |
291
|
|
|
return $tempView; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
function getPosts($jodelAccount) |
|
|
|
|
295
|
|
|
{ |
296
|
|
|
if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL) |
297
|
|
|
{ |
298
|
|
|
$accountCreator = new GetChannel(); |
|
|
|
|
299
|
|
|
$accountCreator->view = $this->view; |
300
|
|
|
$accountCreator->setAccessToken($jodelAccount->accessToken); |
301
|
|
|
$accountCreator->channel = $this->hashtag; |
|
|
|
|
302
|
|
|
$accountCreator->lastPostId = $this->lastPostId; |
303
|
|
|
$data = $accountCreator->execute(); |
|
|
|
|
304
|
|
|
} |
305
|
|
|
else |
306
|
|
|
{ |
307
|
|
|
if($this->lastPostId == '' && $this->view == 'combo') |
308
|
|
|
{ |
309
|
|
|
$url = "/v3/posts/location/combo"; |
|
|
|
|
310
|
|
|
} |
311
|
|
|
else |
312
|
|
|
{ |
313
|
|
|
if($this->view == 'discussed') |
314
|
|
|
{ |
315
|
|
|
$url = "/v2/posts/location/discussed/"; |
|
|
|
|
316
|
|
|
} |
317
|
|
|
else |
318
|
|
|
{ |
319
|
|
|
if($this->view == 'popular') |
320
|
|
|
{ |
321
|
|
|
$url = "/v2/posts/location/popular/"; |
|
|
|
|
322
|
|
|
} |
323
|
|
|
else |
324
|
|
|
{ |
325
|
|
|
$url = "/v2/posts/location/"; |
|
|
|
|
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
$accountCreator = new GetPosts(); |
331
|
|
|
$accountCreator->setLastPostId($this->lastPostId); |
332
|
|
|
$accountCreator->setAccessToken($jodelAccount->accessToken); |
333
|
|
|
$accountCreator->setUrl($url); |
334
|
|
|
$accountCreator->version = 'v3'; |
335
|
|
|
|
336
|
|
|
$config = parse_ini_file('config/config.ini.php'); |
|
|
|
|
337
|
|
|
$location = new Location(); |
338
|
|
|
$location->setLat($config['default_lat']); |
339
|
|
|
$location->setLng($config['default_lng']); |
340
|
|
|
$location->setCityName($config['default_location']); |
341
|
|
|
$accountCreator->location = $location; |
342
|
|
|
$data = $accountCreator->execute(); |
|
|
|
|
343
|
|
|
} |
344
|
|
|
if(array_key_exists('recent', $data)) |
345
|
|
|
{ |
346
|
|
|
return $data['recent']; |
347
|
|
|
} |
348
|
|
|
else if(array_key_exists('posts', $data)) |
349
|
|
|
{ |
350
|
|
|
return $data['posts']; |
351
|
|
|
} |
352
|
|
|
else |
353
|
|
|
{ |
354
|
|
|
error_log('Fehler View getPosts '); |
355
|
|
|
error_log(print_r($data, true)); |
356
|
|
|
|
357
|
|
|
$notFound[0] = array( |
|
|
|
|
358
|
|
|
"post_id" => "0", |
|
|
|
|
359
|
|
|
"discovered_by" => 0, |
|
|
|
|
360
|
|
|
"message" => "Not found", |
|
|
|
|
361
|
|
|
"created_at" => "2017-02-11T16:44:50.385Z", |
|
|
|
|
362
|
|
|
"updated_at" => "2017-02-11T16:44:50.385Z", |
|
|
|
|
363
|
|
|
"pin_count" => 0, |
|
|
|
|
364
|
|
|
"color" => "FFBA00", |
|
|
|
|
365
|
|
|
"got_thanks" => FALSE, |
|
|
|
|
366
|
|
|
"post_own" => "friend", |
|
|
|
|
367
|
|
|
"discovered" => 0, |
|
|
|
|
368
|
|
|
"distance" => 9, |
|
|
|
|
369
|
|
|
"vote_count" => 0, |
|
|
|
|
370
|
|
|
"location" => |
|
|
|
|
371
|
|
|
array("name" => "Berlin", |
|
|
|
|
372
|
|
|
"loc_coordinates" => |
|
|
|
|
373
|
|
|
array( |
374
|
|
|
"lat" => 0, |
|
|
|
|
375
|
|
|
"lng" => 0 |
|
|
|
|
376
|
|
|
), |
377
|
|
|
"loc_accuracy" => 0, |
|
|
|
|
378
|
|
|
"country" => "", |
|
|
|
|
379
|
|
|
"city" => "", |
|
|
|
|
380
|
|
|
), |
381
|
|
|
"tags" => |
|
|
|
|
382
|
|
|
array(), |
383
|
|
|
"user_handle" => "0" |
|
|
|
|
384
|
|
|
); |
385
|
|
|
return $notFound; |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
} |
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.