ftm.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. class ftm{
  3. public function __construct(){
  4. include "lib/backend.php";
  5. $this->backend = new backend("ftm");
  6. }
  7. public function getfilters($page){
  8. return [];
  9. }
  10. private function get($proxy, $url, $search, $offset){
  11. $curlproc = curl_init();
  12. curl_setopt($curlproc, CURLOPT_URL, $url);
  13. $payload =
  14. json_encode(
  15. [
  16. "search" => $search,
  17. "offset" => $offset
  18. ]
  19. );
  20. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  21. curl_setopt($curlproc, CURLOPT_HTTPHEADER,
  22. ["User-Agent: " . config::USER_AGENT,
  23. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
  24. "Accept-Language: en-US,en;q=0.5",
  25. "Accept-Encoding: gzip",
  26. "Content-Length: " . strlen($payload),
  27. "Content-Type: application/json",
  28. "DNT: 1",
  29. "Connection: keep-alive",
  30. "Origin: https://findthatmeme.com",
  31. "Referer: https://findthatmeme.com/?search=" . urlencode($search),
  32. "Upgrade-Insecure-Requests: 1",
  33. "Sec-Fetch-Dest: document",
  34. "Sec-Fetch-Mode: navigate",
  35. "Sec-Fetch-Site: none",
  36. "Sec-Fetch-User: ?1",
  37. "X-Auth-Key: undefined",
  38. "X-CSRF-Validation-Header: true"]
  39. );
  40. curl_setopt($curlproc, CURLOPT_POST, true);
  41. curl_setopt($curlproc, CURLOPT_POSTFIELDS, $payload);
  42. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  43. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  44. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  45. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  46. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  47. $this->backend->assign_proxy($curlproc, $proxy);
  48. $data = curl_exec($curlproc);
  49. if(curl_errno($curlproc)){
  50. throw new Exception(curl_error($curlproc));
  51. }
  52. curl_close($curlproc);
  53. return $data;
  54. }
  55. public function image($get){
  56. $out = [
  57. "status" => "ok",
  58. "npt" => null,
  59. "image" => []
  60. ];
  61. if($get["npt"]){
  62. [$data, $proxy] = $this->backend->get($get["npt"], "images");
  63. $data = json_decode($data, true);
  64. $count = $data["count"];
  65. $search = $data["search"];
  66. }else{
  67. $search = $get["s"];
  68. if(strlen($search) === 0){
  69. throw new Exception("Search term is empty!");
  70. }
  71. $count = 0;
  72. $proxy = $this->backend->get_ip();
  73. }
  74. try{
  75. $json =
  76. json_decode(
  77. $this->get(
  78. $proxy,
  79. "https://findthatmeme.com/api/v1/search",
  80. $search,
  81. $count
  82. ),
  83. true
  84. );
  85. }catch(Exception $error){
  86. throw new Exception("Failed to fetch JSON");
  87. }
  88. if($json === null){
  89. throw new Exception("Failed to decode JSON");
  90. }
  91. foreach($json as $item){
  92. $count++;
  93. if($item["type"] == "VIDEO"){
  94. $thumb = "thumb/" . $item["thumbnail"];
  95. }else{
  96. $thumb = $item["image_path"];
  97. }
  98. $out["image"][] = [
  99. "title" => date("jS \of F Y @ g:ia", strtotime($item["created_at"])),
  100. "source" => [
  101. [
  102. "url" =>
  103. "https://s3.thehackerblog.com/findthatmeme/" .
  104. $thumb,
  105. "width" => null,
  106. "height" => null
  107. ]
  108. ],
  109. "url" => $item["source_page_url"]
  110. ];
  111. }
  112. $out["npt"] =
  113. $this->backend->store(
  114. json_encode([
  115. "count" => $count,
  116. "search" => $search
  117. ]),
  118. "images",
  119. $proxy
  120. );
  121. return $out;
  122. }
  123. }