images.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. $payload["images"] .=
  50. '<div class="image-wrapper" title="' . htmlspecialchars($image["title"]) .'" data-json="' . htmlspecialchars(json_encode($image["source"])) . '">' .
  51. '<div class="image">' .
  52. '<a href="' . htmlspecialchars($image["source"][0]["url"]) . '" rel="noreferrer nofollow" class="thumb">' .
  53. '<img src="' . $frontend->htmlimage($image["source"][count($image["source"]) - 1]["url"], "thumb") . '" alt="thumbnail">';
  54. if($image["source"][0]["width"] !== null){
  55. $payload["images"] .= '<div class="duration">' . $image["source"][0]["width"] . 'x' . $image["source"][0]["height"] . '</div>';
  56. }
  57. $payload["images"] .=
  58. '</a>' .
  59. '<a href="' . htmlspecialchars($image["url"]) . '" rel="noreferrer nofollow">' .
  60. '<div class="title">' . htmlspecialchars(parse_url($image["url"], PHP_URL_HOST)) . '</div>' .
  61. '<div class="description">' . $frontend->highlighttext($get["s"], $image["title"]) . '</div>' .
  62. '</a>' .
  63. '</div>' .
  64. '</div>';
  65. }
  66. if($results["npt"] !== null){
  67. $payload["nextpage"] =
  68. '<a href="' . $frontend->htmlnextpage($get, $results["npt"], "images") . '" class="nextpage img">Next page &gt;</a>';
  69. }
  70. echo $frontend->load("images.html", $payload);