|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class View |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
public $view; |
|
6
|
|
|
public $lastPostId = ''; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Compute HTML Code |
|
10
|
|
|
*/ |
|
11
|
|
|
function jodelToHtml($post, $view = 'time', $isDetailedView = FALSE) |
|
|
|
|
|
|
12
|
|
|
{ //ToDO |
|
|
|
|
|
|
13
|
|
|
//Replace # with link |
|
14
|
|
|
//preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
//Time to time difference |
|
17
|
|
|
$now = new DateTime(); |
|
|
|
|
|
|
18
|
|
|
$d = new DateTime($post['created_at']); |
|
|
|
|
|
|
19
|
|
|
$timediff = $now->diff($d); |
|
20
|
|
|
|
|
21
|
|
|
$timediff_inSeconds = (string)$timediff->format('%s'); |
|
22
|
|
|
$timediff_inMinutes = (string)$timediff->format('%i'); |
|
23
|
|
|
$timediff_inHours = (string)$timediff->format('%h'); |
|
|
|
|
|
|
24
|
|
|
$timediff_inDays = (string)$timediff->format('%d'); |
|
|
|
|
|
|
25
|
|
|
$timediff_inMonth = (string)$timediff->format('%m'); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
if($timediff_inMonth!=0) |
|
28
|
|
|
{ |
|
29
|
|
|
$timediff = $timediff_inMonth . "m"; |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
else |
|
32
|
|
|
{ |
|
33
|
|
|
if($timediff_inDays!=0) |
|
34
|
|
|
{ |
|
35
|
|
|
$timediff = $timediff_inDays . "d"; |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
else |
|
38
|
|
|
{ |
|
39
|
|
|
if($timediff_inHours!=0) |
|
40
|
|
|
{ |
|
41
|
|
|
$timediff = $timediff_inHours . "h"; |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
else |
|
44
|
|
|
{ |
|
45
|
|
|
if($timediff_inMinutes!=0) |
|
46
|
|
|
{ |
|
47
|
|
|
$timediff = $timediff_inMinutes . "m"; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
else |
|
50
|
|
|
{ |
|
51
|
|
|
$timediff = $timediff_inSeconds . "s"; |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
?> |
|
59
|
|
|
<article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;"> |
|
|
|
|
|
|
60
|
|
|
<content> |
|
61
|
|
|
<?php |
|
62
|
|
|
if(isset($post['image_url'])) |
|
63
|
|
|
{ |
|
64
|
|
|
$regexRest = '/[^\w$ .!?-]+/u'; |
|
65
|
|
|
|
|
66
|
|
|
echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">'; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
else { |
|
69
|
|
|
echo str_replace(' ', ' ', nl2br(htmlspecialchars($post['message']))); |
|
70
|
|
|
} |
|
71
|
|
|
?> |
|
72
|
|
|
</content> |
|
73
|
|
|
<aside> |
|
74
|
|
|
<?php |
|
75
|
|
View Code Duplication |
if($isDetailedView) |
|
|
|
|
|
|
76
|
|
|
{?> |
|
77
|
|
|
<a href="index.php?vote=up&getPostDetails=true&postId=<?php echo $post['post_id'];?>&postId_parent=<?php echo htmlspecialchars($_GET['postId']);?>" rel="nofollow"> |
|
|
|
|
|
|
78
|
|
|
<?php } |
|
79
|
|
|
else |
|
80
|
|
|
{?> |
|
81
|
|
|
<a href="index.php?vote=up&postId=<?php echo $post['post_id'];?>" rel="nofollow"> |
|
82
|
|
|
<?php } ?> |
|
83
|
|
|
<i class="fa fa-angle-up fa-3x"></i> |
|
84
|
|
|
</a> |
|
85
|
|
|
<br /> |
|
86
|
|
|
<?php echo $post["vote_count"];?><br /> |
|
|
|
|
|
|
87
|
|
|
<?php |
|
88
|
|
View Code Duplication |
if($isDetailedView) |
|
|
|
|
|
|
89
|
|
|
{?> |
|
90
|
|
|
<a href="index.php?vote=down&getPostDetails=true&postId=<?php echo $post['post_id'];?>&postId_parent=<?php echo htmlspecialchars($_GET['postId']);?>" rel="nofollow"> |
|
|
|
|
|
|
91
|
|
|
<?php } |
|
92
|
|
|
else |
|
93
|
|
|
{?> |
|
94
|
|
|
<a href="index.php?vote=down&postId=<?php echo $post['post_id'];?>" rel="nofollow"> |
|
95
|
|
|
<?php } ?> |
|
96
|
|
|
<i class="fa fa-angle-down fa-3x"></i> |
|
97
|
|
|
</a> |
|
98
|
|
|
</aside> |
|
99
|
|
|
|
|
100
|
|
|
<footer> |
|
101
|
|
|
<table> |
|
102
|
|
|
<tr> |
|
103
|
|
|
<td class="time"> |
|
104
|
|
|
<span class="tip" data-tooltip="Time"> |
|
105
|
|
|
<i class="fa fa-clock-o"></i> |
|
106
|
|
|
<?php echo $timediff;?> |
|
107
|
|
|
<span class="tiptext"><?php echo $d->format('Y-m-d H:i:s');?></span> |
|
108
|
|
|
</span> |
|
109
|
|
|
</td> |
|
110
|
|
|
<td class="comments"> |
|
111
|
|
|
<?php if(!$isDetailedView) {?> |
|
112
|
|
|
<span data-tooltip="Comments"> |
|
113
|
|
|
<a href="index.php?getPostDetails=true&view=<?php echo $view;?>&postId=<?php echo $post["post_id"];?>"> |
|
|
|
|
|
|
114
|
|
|
<i class="fa fa-commenting-o"></i> |
|
115
|
|
|
<?php if(array_key_exists("child_count", $post)) { |
|
|
|
|
|
|
116
|
|
|
echo $post["child_count"]; |
|
|
|
|
|
|
117
|
|
|
} else echo "0"; |
|
|
|
|
|
|
118
|
|
|
?> |
|
119
|
|
|
</a> |
|
120
|
|
|
</span> |
|
121
|
|
|
<?php } ?> |
|
122
|
|
|
</td> |
|
123
|
|
|
<td class="distance"> |
|
124
|
|
|
<?php |
|
125
|
|
|
if($isDetailedView) |
|
126
|
|
|
{ |
|
127
|
|
|
if(isset($post["parent_creator"]) && $post["parent_creator"] == 1) |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
?> |
|
130
|
|
|
<span data-tooltip="Author"> |
|
131
|
|
|
<i class="fa fa-user-o"></i> OJ | |
|
132
|
|
|
</span> |
|
133
|
|
|
<?php |
|
134
|
|
|
} |
|
135
|
|
|
else |
|
136
|
|
|
{ |
|
137
|
|
|
//Is not parent Jodel in detailed View |
|
138
|
|
|
if(!array_key_exists('child_count', $post) && array_key_exists('parent_creator', $post)) |
|
|
|
|
|
|
139
|
|
|
{ |
|
140
|
|
|
?> |
|
141
|
|
|
<span data-tooltip="Author"> |
|
142
|
|
|
<i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> | |
|
|
|
|
|
|
143
|
|
|
</span> |
|
144
|
|
|
<?php |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
?> |
|
149
|
|
|
|
|
150
|
|
|
<span class="tip" data-tooltip="Distance"> |
|
151
|
|
|
<i class="fa fa-map-marker"></i> |
|
152
|
|
|
<?php echo $post['distance'];?> km |
|
153
|
|
|
<span class="tiptext"><?php echo $post['location']['name'];?></span> |
|
154
|
|
|
</span> |
|
155
|
|
|
</td> |
|
156
|
|
|
</tr> |
|
157
|
|
|
</table> |
|
158
|
|
|
</footer> |
|
159
|
|
|
</article> |
|
160
|
|
|
<?php |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Gets the title. |
|
166
|
|
|
* |
|
167
|
|
|
* @return string The title. |
|
168
|
|
|
*/ |
|
169
|
|
|
function getTitle($post, $view = 'time', $isDetailedView = FALSE) |
|
|
|
|
|
|
170
|
|
|
{ |
|
171
|
|
|
$title = 'JodelBlue - Web-App and Browser-Client'; |
|
172
|
|
|
|
|
173
|
|
|
if($isDetailedView) |
|
174
|
|
|
{ |
|
175
|
|
|
$title = 'JodelBlue: ' . substr(htmlspecialchars($post['message']), 0, 44); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
return $title; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Gets the meta description. |
|
183
|
|
|
* |
|
184
|
|
|
* @return string The meta description. |
|
185
|
|
|
*/ |
|
186
|
|
|
function getMetaDescription($post, $view = 'time', $isDetailedView = FALSE) |
|
|
|
|
|
|
187
|
|
|
{ |
|
188
|
|
|
$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.'; |
|
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
if($isDetailedView) |
|
191
|
|
|
{ |
|
192
|
|
|
$description = 'On JodelBlue with ' . htmlspecialchars($post['vote_count']) . ' Upvotes: ' . substr(htmlspecialchars($post['message']), 0, 140); |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
return $description; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
function getCaptcha($accessToken) |
|
|
|
|
|
|
199
|
|
|
{ |
|
200
|
|
|
$accountCreator = new GetCaptcha(); |
|
201
|
|
|
$accountCreator->setAccessToken($accessToken); |
|
202
|
|
|
$captcha = $accountCreator->execute(); |
|
203
|
|
|
|
|
204
|
|
|
return array("image_url" => $captcha['image_url'], "key" => $captcha['key']); |
|
|
|
|
|
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
function showCaptcha($accessToken, $deviceUid) |
|
|
|
|
|
|
208
|
|
|
{ |
|
209
|
|
|
$accountCreator = new GetCaptcha(); |
|
210
|
|
|
$accountCreator->setAccessToken($accessToken); |
|
211
|
|
|
$captcha = $accountCreator->execute(); |
|
212
|
|
|
|
|
213
|
|
|
echo $captcha['image_url']; |
|
214
|
|
|
echo('<br><img width="100%" src="' . $captcha['image_url'] . '">'); |
|
215
|
|
|
echo "<br>Key: " . $captcha['key']; |
|
|
|
|
|
|
216
|
|
|
echo "<br>"; |
|
|
|
|
|
|
217
|
|
|
|
|
218
|
|
|
//Form |
|
219
|
|
|
|
|
220
|
|
|
echo '<form method="get">'; |
|
221
|
|
|
echo '<p>Enter Key (copy pasta from top): <input type="text" value="' . $captcha['key'] . '" name="key" /></p>'; |
|
222
|
|
|
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>'; |
|
|
|
|
|
|
223
|
|
|
echo '<input type="hidden" name="deviceUid" value="' . $deviceUid . '">'; |
|
224
|
|
|
echo '<input type="hidden" name="pw" value="upVote">'; |
|
225
|
|
|
echo '<p><input type="submit" /></p>'; |
|
226
|
|
|
echo '</form>'; |
|
227
|
|
|
|
|
228
|
|
|
die(); |
|
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
View Code Duplication |
function getPosts($lastPostId, $accessToken, $url, $version = 'v2') |
|
|
|
|
|
|
233
|
|
|
{ |
|
234
|
|
|
$accountCreator = new GetPosts(); |
|
235
|
|
|
$accountCreator->setLastPostId($lastPostId); |
|
236
|
|
|
$accountCreator->setAccessToken($accessToken); |
|
237
|
|
|
$accountCreator->setUrl($url); |
|
238
|
|
|
$accountCreator->version = $version; |
|
239
|
|
|
|
|
240
|
|
|
$config = parse_ini_file('config/config.ini.php'); |
|
|
|
|
|
|
241
|
|
|
$location = new Location(); |
|
242
|
|
|
$location->setLat($config['default_lat']); |
|
243
|
|
|
$location->setLng($config['default_lng']); |
|
244
|
|
|
$location->setCityName($config['default_location']); |
|
245
|
|
|
$accountCreator->location = $location; |
|
246
|
|
|
$data = $accountCreator->execute(); |
|
|
|
|
|
|
247
|
|
|
|
|
248
|
|
|
return $data; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
} |
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.