news.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. Initialize random shit
  4. */
  5. include "data/config.php";
  6. include "lib/frontend.php";
  7. $frontend = new frontend();
  8. [$scraper, $filters] = $frontend->getscraperfilters("news");
  9. $get = $frontend->parsegetfilters($_GET, $filters);
  10. /*
  11. Captcha
  12. */
  13. include "lib/bot_protection.php";
  14. new bot_protection($frontend, $get, $filters, "news", true);
  15. $payload = [
  16. "timetaken" => microtime(true),
  17. "class" => "",
  18. "right-left" => "",
  19. "right-right" => "",
  20. "left" => ""
  21. ];
  22. try{
  23. $results = $scraper->news($get);
  24. }catch(Exception $error){
  25. $frontend->drawscrapererror($error->getMessage(), $get, "news", $payload["timetaken"]);
  26. }
  27. /*
  28. Populate links
  29. */
  30. if(count($results["news"]) === 0){
  31. $payload["left"] =
  32. '<div class="infobox">' .
  33. "<h1>Nobody here but us chickens!</h1>" .
  34. 'Have you tried:' .
  35. '<ul>' .
  36. '<li>Using a different scraper</li>' .
  37. '<li>Using fewer keywords</li>' .
  38. '<li>Defining broader filters (Is NSFW turned off?)</li>' .
  39. '</ul>' .
  40. '</div>';
  41. }
  42. foreach($results["news"] as $news){
  43. $greentext = [];
  44. if($news["date"] !== null){
  45. $greentext[] = date("jS M y @ g:ia", $news["date"]);
  46. }
  47. if($news["author"] !== null){
  48. $greentext[] = htmlspecialchars($news["author"]);
  49. }
  50. if(count($greentext) !== 0){
  51. $greentext = implode(" • ", $greentext);
  52. }else{
  53. $greentext = null;
  54. }
  55. $n = null;
  56. $payload["left"] .= $frontend->drawtextresult($news, $greentext, $n, $get["s"]);
  57. }
  58. if($results["npt"] !== null){
  59. $payload["left"] .=
  60. '<a href="' . $frontend->htmlnextpage($get, $results["npt"], "news") . '" class="nextpage">Next page &gt;</a>';
  61. }
  62. echo $frontend->load("search.html", $payload);