images.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /*
  3. Initialize random shit
  4. */
  5. include "lib/frontend.php";
  6. $frontend = new frontend();
  7. [$scraper, $filters] = $frontend->getscraperfilters("images");
  8. $get = $frontend->parsegetfilters($_GET, $filters);
  9. $frontend->loadheader(
  10. $get,
  11. $filters,
  12. "images"
  13. );
  14. $payload = [
  15. "images" => "",
  16. "nextpage" => ""
  17. ];
  18. try{
  19. $results = $scraper->image($get);
  20. }catch(Exception $error){
  21. echo
  22. $frontend->drawerror(
  23. "Shit",
  24. 'This scraper returned an error:' .
  25. '<div class="code">' . htmlspecialchars($error->getMessage()) . '</div>' .
  26. 'Things you can try:' .
  27. '<ul>' .
  28. '<li>Use a different scraper</li>' .
  29. '<li>Remove keywords that could cause errors</li>' .
  30. '<li>Use another 4get instance</li>' .
  31. '</ul><br>' .
  32. 'If the error persists, please <a href="/about">contact the administrator</a>.'
  33. );
  34. die();
  35. }
  36. if(count($results["image"]) === 0){
  37. $payload["images"] =
  38. '<div class="infobox">' .
  39. "<h1>Nobody here but us chickens!</h1>" .
  40. 'Have you tried:' .
  41. '<ul>' .
  42. '<li>Using a different scraper</li>' .
  43. '<li>Using fewer keywords</li>' .
  44. '<li>Defining broader filters (Is NSFW turned off?)</li>' .
  45. '</ul>' .
  46. '</div>';
  47. }
  48. foreach($results["image"] as $image){
  49. $domain = htmlspecialchars(parse_url($image["url"], PHP_URL_HOST));
  50. $c = count($image["source"]) - 1;
  51. if(
  52. preg_match(
  53. '/^data:/',
  54. $image["source"][$c]["url"]
  55. )
  56. ){
  57. $src = htmlspecialchars($image["source"][$c]["url"]);
  58. }else{
  59. $src = "/proxy?i=" . urlencode($image["source"][$c]["url"]) . "&s=thumb";
  60. }
  61. $payload["images"] .=
  62. '<div class="image-wrapper" title="' . htmlspecialchars($image["title"]) .'" data-json="' . htmlspecialchars(json_encode($image["source"])) . '">' .
  63. '<div class="image">' .
  64. '<a href="' . htmlspecialchars($image["source"][0]["url"]) . '" rel="noreferrer nofollow" class="thumb">' .
  65. '<img src="' . $src . '" alt="thumbnail">' .
  66. '<div class="duration">' . $image["source"][0]["width"] . 'x' . $image["source"][0]["height"] . '</div>' .
  67. '</a>' .
  68. '<a href="' . htmlspecialchars($image["url"]) . '" rel="noreferrer nofollow">' .
  69. '<div class="title">' . htmlspecialchars($domain) . '</div>' .
  70. '<div class="description">' . $frontend->highlighttext($get["s"], $image["title"]) . '</div>' .
  71. '</a>' .
  72. '</div>' .
  73. '</div>';
  74. }
  75. if($results["npt"] !== null){
  76. $payload["nextpage"] =
  77. '<a href="' . $frontend->htmlnextpage($get, $results["npt"], "images") . '" class="nextpage img">Next page &gt;</a>';
  78. }
  79. echo $frontend->load("images.html", $payload);