search.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php require "misc/header.php"; ?>
  2. <title>
  3. <?php
  4. $query = htmlspecialchars(trim($_REQUEST["q"]));
  5. echo $query;
  6. ?> - Binternet</title>
  7. </head>
  8. <body>
  9. <form class="searchContainer" method="get" autocomplete="off">
  10. <h1><a class="no-decoration" href="./"><span>B</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. $query = $_GET['q'];
  26. $baseurl = "https://pinterest.com/resource/BaseSearchResource/get/?data=%7B%22options%22%3A%7B%22query%22%3A%22{}%22%7D%7D";
  27. $search = function($query) use($baseurl)
  28. {
  29. $url = str_replace("{}", str_replace(" ", "%20", $query), $baseurl);
  30. $json = file_get_contents($url);
  31. $data = json_decode($json);
  32. $images = array();
  33. foreach ($data->{"resource_response"}->{"data"}->{"results"} as $result)
  34. {
  35. $image = $result->{"images"}->{"orig"};
  36. $url = $image->{"url"};
  37. array_push($images, $url);
  38. echo "<a href='/image_proxy.php?url=", $url, "'>";
  39. echo "<img src='/image_proxy.php?url=", $url, "'></a>";
  40. }
  41. return $images;
  42. };
  43. $images = $search("$query");
  44. echo "<br><br><br><br>";
  45. include "misc/footer.php";
  46. ?>