@@ -2,107 +2,107 @@ discard block |
||
2 | 2 | |
3 | 3 | class View |
4 | 4 | { |
5 | - public $country; |
|
6 | - public $city; |
|
7 | - public $hashtag; |
|
5 | + public $country; |
|
6 | + public $city; |
|
7 | + public $hashtag; |
|
8 | 8 | public $view; |
9 | - public $postId; |
|
10 | - public $isDetailedView; |
|
11 | - public $baseUrl; |
|
9 | + public $postId; |
|
10 | + public $isDetailedView; |
|
11 | + public $baseUrl; |
|
12 | 12 | |
13 | 13 | public $lastPostId = ''; |
14 | 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 | - } |
|
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 | 33 | /** |
34 | 34 | * Compute HTML Code |
35 | 35 | */ |
36 | 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 | - ?> |
|
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 | 84 | <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;"> |
85 | 85 | <content> |
86 | 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 | - ?> |
|
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 | 97 | </content> |
98 | 98 | <aside> |
99 | 99 | <?php |
100 | - if($this->isDetailedView) |
|
101 | - {?> |
|
100 | + if($this->isDetailedView) |
|
101 | + {?> |
|
102 | 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 | 103 | <?php } |
104 | - else |
|
105 | - {?> |
|
104 | + else |
|
105 | + {?> |
|
106 | 106 | <a href="index.php?vote=up&postId=<?php echo $post['post_id'];?>" rel="nofollow"> |
107 | 107 | <?php } ?> |
108 | 108 | <i class="fa fa-angle-up fa-3x"></i> |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | <br /> |
111 | 111 | <?php echo $post["vote_count"];?><br /> |
112 | 112 | <?php |
113 | - if($this->isDetailedView) |
|
114 | - {?> |
|
113 | + if($this->isDetailedView) |
|
114 | + {?> |
|
115 | 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 | 116 | <?php } |
117 | - else |
|
118 | - {?> |
|
117 | + else |
|
118 | + {?> |
|
119 | 119 | <a href="index.php?vote=down&postId=<?php echo $post['post_id'];?>" rel="nofollow"> |
120 | 120 | <?php } ?> |
121 | 121 | <i class="fa fa-angle-down fa-3x"></i> |
@@ -138,39 +138,39 @@ discard block |
||
138 | 138 | <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>"> |
139 | 139 | <i class="fa fa-commenting-o"></i> |
140 | 140 | <?php if(array_key_exists("child_count", $post)) { |
141 | - echo $post["child_count"]; |
|
142 | - } else echo "0"; |
|
143 | - ?> |
|
141 | + echo $post["child_count"]; |
|
142 | + } else echo "0"; |
|
143 | + ?> |
|
144 | 144 | </a> |
145 | 145 | </span> |
146 | 146 | <?php } ?> |
147 | 147 | </td> |
148 | 148 | <td class="distance"> |
149 | 149 | <?php |
150 | - if($this->isDetailedView) |
|
151 | - { |
|
152 | - if(isset($post["parent_creator"]) && $post["parent_creator"] == 1) |
|
153 | - { |
|
154 | - ?> |
|
150 | + if($this->isDetailedView) |
|
151 | + { |
|
152 | + if(isset($post["parent_creator"]) && $post["parent_creator"] == 1) |
|
153 | + { |
|
154 | + ?> |
|
155 | 155 | <span data-tooltip="Author"> |
156 | 156 | <i class="fa fa-user-o"></i> OJ | |
157 | 157 | </span> |
158 | 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 | - ?> |
|
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 | 166 | <span data-tooltip="Author"> |
167 | 167 | <i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> | |
168 | 168 | </span> |
169 | 169 | <?php |
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - ?> |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + ?> |
|
174 | 174 | |
175 | 175 | <span class="tip" data-tooltip="Distance"> |
176 | 176 | <i class="fa fa-map-marker"></i> |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | </footer> |
184 | 184 | </article> |
185 | 185 | <?php |
186 | - } |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | 189 | /** |
@@ -254,135 +254,135 @@ discard block |
||
254 | 254 | |
255 | 255 | } |
256 | 256 | |
257 | - function toUrl() |
|
258 | - { |
|
259 | - $url = $this->baseUrl . 'index.php?country=DE' . |
|
260 | - '&city=' . urlencode($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 | - } |
|
257 | + function toUrl() |
|
258 | + { |
|
259 | + $url = $this->baseUrl . 'index.php?country=DE' . |
|
260 | + '&city=' . urlencode($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 | 293 | |
294 | 294 | function getPosts($jodelAccount) |
295 | 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 | - } |
|
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 | 387 | } |
388 | 388 | } |
389 | 389 | \ No newline at end of file |