mmainstreet /
jodel-web
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 | public $rights; |
||
| 13 | |||
| 14 | public $lastPostId = ''; |
||
| 15 | |||
| 16 | function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '') |
||
| 17 | { |
||
| 18 | $this->baseUrl = $baseUrl; |
||
| 19 | $this->country = $country; |
||
| 20 | $this->city = $city; |
||
| 21 | $this->hashtag = urldecode($hashtag); |
||
| 22 | $this->view = $view; |
||
| 23 | $this->postId = $postId; |
||
| 24 | |||
| 25 | if(isUserAdmin()) |
||
| 26 | { |
||
| 27 | $this->rights = 'admin'; |
||
| 28 | } |
||
| 29 | else if(isUserVoter()) |
||
| 30 | { |
||
| 31 | $this->rights = 'voter'; |
||
| 32 | } |
||
| 33 | else |
||
| 34 | { |
||
| 35 | $this->rights = 'user'; |
||
| 36 | } |
||
| 37 | |||
| 38 | if($postId == '') |
||
| 39 | { |
||
| 40 | $this->isDetailedView = FALSE; |
||
| 41 | } |
||
| 42 | else |
||
| 43 | { |
||
| 44 | $this->isDetailedView = TRUE; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | /** |
||
| 48 | * Compute HTML Code |
||
| 49 | */ |
||
| 50 | function jodelToHtml($post) |
||
| 51 | { //ToDO |
||
| 52 | //Replace # with link |
||
| 53 | //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
||
| 54 | |||
| 55 | //Time to time difference |
||
| 56 | $now = new DateTime(); |
||
| 57 | $d = new DateTime($post['created_at']); |
||
| 58 | $timediff = $now->diff($d); |
||
| 59 | |||
| 60 | $timediff_inSeconds = (string)$timediff->format('%s'); |
||
| 61 | $timediff_inMinutes = (string)$timediff->format('%i'); |
||
| 62 | $timediff_inHours = (string)$timediff->format('%h'); |
||
| 63 | $timediff_inDays = (string)$timediff->format('%d'); |
||
| 64 | $timediff_inMonth = (string)$timediff->format('%m'); |
||
| 65 | |||
| 66 | if($timediff_inMonth!=0) |
||
| 67 | { |
||
| 68 | $timediff = $timediff_inMonth . "m"; |
||
| 69 | } |
||
| 70 | else |
||
| 71 | { |
||
| 72 | if($timediff_inDays!=0) |
||
| 73 | { |
||
| 74 | $timediff = $timediff_inDays . "d"; |
||
| 75 | } |
||
| 76 | else |
||
| 77 | { |
||
| 78 | if($timediff_inHours!=0) |
||
| 79 | { |
||
| 80 | $timediff = $timediff_inHours . "h"; |
||
| 81 | } |
||
| 82 | else |
||
| 83 | { |
||
| 84 | if($timediff_inMinutes!=0) |
||
| 85 | { |
||
| 86 | $timediff = $timediff_inMinutes . "m"; |
||
| 87 | } |
||
| 88 | else |
||
| 89 | { |
||
| 90 | $timediff = $timediff_inSeconds . "s"; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | ?> |
||
| 98 | <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;"> |
||
| 99 | <content> |
||
| 100 | <?php |
||
| 101 | if(isset($post['image_url'])) |
||
| 102 | { |
||
| 103 | $regexRest = '/[^\w$ .!?-]+/u'; |
||
| 104 | |||
| 105 | echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">'; |
||
| 106 | } |
||
| 107 | else { |
||
| 108 | echo str_replace(' ', ' ', nl2br(htmlspecialchars($post['message']))); |
||
| 109 | } |
||
| 110 | ?> |
||
| 111 | </content> |
||
| 112 | <aside> |
||
| 113 | <button onclick="vote('<?php echo $post['post_id'];?>', 'up', this)"> |
||
| 114 | <i class="fa fa-angle-up fa-3x"></i> |
||
| 115 | </button> |
||
| 116 | <br><span><?php echo $post["vote_count"];?></span><br> |
||
| 117 | |||
| 118 | <button onclick="vote('<?php echo $post['post_id'];?>', 'down', this)"> |
||
| 119 | <i class="fa fa-angle-down fa-3x"></i> |
||
| 120 | </button> |
||
| 121 | </aside> |
||
| 122 | |||
| 123 | <footer> |
||
| 124 | <span class="wrapper"> |
||
| 125 | |||
| 126 | <span class="time"> |
||
| 127 | <span class="tip" data-tooltip="Time"> |
||
| 128 | <i class="fa fa-clock-o"></i> |
||
| 129 | <?php echo $timediff;?> |
||
| 130 | <span class="tiptext"><?php echo $d->format('Y-m-d H:i:s');?></span> |
||
| 131 | </span> |
||
| 132 | </span> |
||
| 133 | <?php if(!$this->isDetailedView) {?> |
||
| 134 | <span class="comments"> |
||
| 135 | <span data-tooltip="Comments"> |
||
| 136 | <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>"> |
||
| 137 | <i class="fa fa-commenting-o"></i> |
||
| 138 | <?php if(array_key_exists("child_count", $post)) |
||
| 139 | { |
||
| 140 | echo $post["child_count"]; |
||
| 141 | } else echo "0"; |
||
| 142 | ?> |
||
| 143 | </a> |
||
| 144 | </span> |
||
| 145 | |||
| 146 | </span> |
||
| 147 | <?php |
||
| 148 | } |
||
| 149 | if($this->rights == 'admin' || $this->rights == 'voter') |
||
| 150 | { |
||
| 151 | ?> |
||
| 152 | <span class="voting"> |
||
| 153 | <a target="_blank" href="admin.php?postId=<?php echo $post['post_id'] ?>"> |
||
| 154 | <i class="fa fa-thumbs-o-up"></i> Vote |
||
| 155 | </a> |
||
| 156 | </span> |
||
| 157 | <?php |
||
| 158 | } |
||
| 159 | ?> |
||
| 160 | <span class="distance"> |
||
| 161 | <?php |
||
| 162 | if($this->isDetailedView) |
||
| 163 | { |
||
| 164 | if(isset($post['user_handle']) && $post['user_handle'] == 'OJ') |
||
| 165 | { |
||
| 166 | ?> |
||
| 167 | <span data-tooltip="Author"> |
||
| 168 | <i class="fa fa-user-o"></i> OJ | |
||
| 169 | </span> |
||
| 170 | <?php |
||
| 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 | </span> |
||
| 181 | |||
| 182 | </span> |
||
| 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 - Top Jodel from ' . htmlspecialchars($this->city) . ' Web-App and Browser-Client'; |
||
| 197 | |||
| 198 | if($post != '' && array_key_exists('message', $post) && $post['message'] != '' && $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 in ' . htmlspecialchars($this->city) . ' or all over the world.'; |
||
| 214 | |||
| 215 | if($post != '' && array_key_exists('message', $post) && $post['message'] != '' && $this->isDetailedView) |
||
| 216 | { |
||
| 217 | $description = 'On JodelBlue in ' . htmlspecialchars($this->city) . ' with ' . htmlspecialchars($post['vote_count']) . ' Upvotes: ' . substr(htmlspecialchars($post['message']), 0, 130); |
||
| 218 | } |
||
| 219 | |||
| 220 | return $description; |
||
| 221 | } |
||
| 222 | |||
| 223 | function toUrl($msg = '') |
||
| 224 | { |
||
| 225 | $url = $this->baseUrl . 'index.php?country=DE' . |
||
| 226 | '&city=' . urlencode($this->city) . |
||
| 227 | '&hashtag=' . urlencode($this->hashtag) . |
||
| 228 | '&view=' . $this->view; |
||
| 229 | if($this->postId != '') |
||
| 230 | { |
||
| 231 | $url .= '&postId=' . $this->postId . |
||
| 232 | '&getPostDetails=TRUE'; |
||
| 233 | } |
||
| 234 | |||
| 235 | if($msg != '') |
||
| 236 | { |
||
| 237 | $url .= '&msg=' . urlencode($msg); |
||
| 238 | } |
||
| 239 | |||
| 240 | return $url; |
||
| 241 | } |
||
| 242 | |||
| 243 | function changePostId($postId) |
||
| 244 | { |
||
| 245 | $tempView = clone $this; |
||
| 246 | $tempView->postId = $postId; |
||
| 247 | $tempView->isDetailedView = TRUE; |
||
| 248 | return $tempView; |
||
| 249 | } |
||
| 250 | |||
| 251 | function back() |
||
| 252 | { |
||
| 253 | $tempView = clone $this; |
||
| 254 | $tempView->postId = ''; |
||
| 255 | return $tempView; |
||
| 256 | } |
||
| 257 | |||
| 258 | function changeView($view) |
||
| 259 | { |
||
| 260 | $tempView = clone $this; |
||
| 261 | $tempView->view = $view; |
||
| 262 | return $tempView; |
||
| 263 | } |
||
| 264 | |||
| 265 | function getPosts($jodelAccount) |
||
|
0 ignored issues
–
show
|
|||
| 266 | { |
||
| 267 | if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL) |
||
| 268 | { |
||
| 269 | $accountCreator = new GetChannel(); |
||
| 270 | $accountCreator->view = $this->view; |
||
| 271 | $accountCreator->setAccessToken($jodelAccount->accessToken); |
||
| 272 | $accountCreator->channel = $this->hashtag; |
||
| 273 | $accountCreator->lastPostId = $this->lastPostId; |
||
| 274 | $data = $accountCreator->execute(); |
||
| 275 | } |
||
| 276 | else |
||
| 277 | { |
||
| 278 | if($this->lastPostId == '' && $this->view == 'combo') |
||
| 279 | { |
||
| 280 | $url = "/v3/posts/location/combo"; |
||
| 281 | } |
||
| 282 | else |
||
| 283 | { |
||
| 284 | if($this->view == 'discussed') |
||
| 285 | { |
||
| 286 | $url = "/v2/posts/location/discussed/"; |
||
| 287 | } |
||
| 288 | else |
||
| 289 | { |
||
| 290 | if($this->view == 'popular') |
||
| 291 | { |
||
| 292 | $url = "/v2/posts/location/popular/"; |
||
| 293 | } |
||
| 294 | else |
||
| 295 | { |
||
| 296 | $url = "/v2/posts/location/"; |
||
| 297 | } |
||
| 298 | } |
||
| 299 | } |
||
| 300 | |||
| 301 | $accountCreator = new GetPosts(); |
||
| 302 | $accountCreator->setLastPostId($this->lastPostId); |
||
| 303 | $accountCreator->setAccessToken($jodelAccount->accessToken); |
||
| 304 | $accountCreator->setUrl($url); |
||
| 305 | $accountCreator->version = 'v3'; |
||
| 306 | |||
| 307 | $config = parse_ini_file('config/config.ini.php'); |
||
| 308 | $location = new Location(); |
||
| 309 | $location->setLat($config['default_lat']); |
||
| 310 | $location->setLng($config['default_lng']); |
||
| 311 | $location->setCityName($config['default_location']); |
||
| 312 | $accountCreator->location = $location; |
||
| 313 | $data = $accountCreator->execute(); |
||
| 314 | } |
||
| 315 | if(is_array($data) && array_key_exists('recent', $data) && array_key_exists(0, $data['recent'])) |
||
| 316 | { |
||
| 317 | return $data['recent']; |
||
| 318 | } |
||
| 319 | else if(is_array($data) && array_key_exists('posts', $data)&& array_key_exists(0, $data['posts'])) |
||
| 320 | { |
||
| 321 | return $data['posts']; |
||
| 322 | } |
||
| 323 | else |
||
| 324 | { |
||
| 325 | if($this->lastPostId == '') |
||
| 326 | { |
||
| 327 | error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true)); |
||
| 328 | //error_log(print_r($data, true)); |
||
| 329 | |||
| 330 | $notFound[0] = array( |
||
| 331 | "post_id" => "0", |
||
| 332 | "discovered_by" => 0, |
||
| 333 | "message" => "No more Posts found", |
||
| 334 | "created_at" => "2017-02-11T16:44:50.385Z", |
||
| 335 | "updated_at" => "2017-02-11T16:44:50.385Z", |
||
| 336 | "pin_count" => 0, |
||
| 337 | "color" => "5682a3", |
||
| 338 | "got_thanks" => FALSE, |
||
| 339 | "post_own" => "friend", |
||
| 340 | "discovered" => 0, |
||
| 341 | "distance" => 9, |
||
| 342 | "vote_count" => 0, |
||
| 343 | "location" => |
||
| 344 | array("name" => "Berlin", |
||
| 345 | "loc_coordinates" => |
||
| 346 | array( |
||
| 347 | "lat" => 0, |
||
| 348 | "lng" => 0 |
||
| 349 | ), |
||
| 350 | "loc_accuracy" => 0, |
||
| 351 | "country" => "", |
||
| 352 | "city" => "", |
||
| 353 | ), |
||
| 354 | "tags" => |
||
| 355 | array(), |
||
| 356 | "user_handle" => "0" |
||
| 357 | ); |
||
| 358 | return $notFound; |
||
| 359 | } |
||
| 360 | else |
||
| 361 | { |
||
| 362 | return FALSE; |
||
| 363 | } |
||
| 364 | } |
||
| 365 | } |
||
| 366 | } |
||
| 367 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.