search.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php require "misc/header.php"; ?>
  2. <title>
  3. <?php
  4. $query = htmlspecialchars(trim($_REQUEST["q"]));
  5. echo $query;
  6. ?> - Pinternet</title>
  7. </head>
  8. <body>
  9. <form class="searchContainer" method="get" autocomplete="off">
  10. <h1><a class="no-decoration" href="./"><span>P</span>inter<span>n</span>et</a></h1>
  11. <input type="text" name="q"
  12. <?php
  13. $query_encoded = urlencode($query);
  14. if (1 > strlen($query) || strlen($query) > 64)
  15. {
  16. header("Location: ./");
  17. die();
  18. }
  19. echo "value=\"$query\"";
  20. ?>
  21. <br>
  22. <hr>
  23. </form>
  24. <?php
  25. //require "engines/pinterest.php";
  26. $query = $_GET['q'];
  27. //$imgResults = get_image_results($query);
  28. //print_image_results($imgResults);
  29. $baseurl = "https://pinterest.com/resource/BaseSearchResource/get/?data=%7B%22options%22%3A%7B%22query%22%3A%22{}%22%7D%7D";
  30. $search = function($query) use($baseurl)
  31. {
  32. $url = str_replace("{}", str_replace(" ", "%20", $query), $baseurl);
  33. $json = file_get_contents($url);
  34. $data = json_decode($json);
  35. $images = array();
  36. foreach ($data->{"resource_response"}->{"data"}->{"results"} as $result)
  37. {
  38. $image = $result->{"images"}->{"orig"};
  39. $url = $image->{"url"};
  40. array_push($images, $url);
  41. echo "<img src='/image_proxy.php?url=", $url, "'>";
  42. }
  43. return $images;
  44. };
  45. $images = $search("$query");
  46. echo "<br><br>";
  47. echo "<hr>";
  48. print(count($images)." images found");
  49. include "misc/footer.php";
  50. ?>