crowdview.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. class crowdview{
  3. public function __construct(){
  4. include "lib/backend.php";
  5. $this->backend = new backend("crowdview");
  6. include "lib/fuckhtml.php";
  7. $this->fuckhtml = new fuckhtml();
  8. }
  9. public function getfilters($page){
  10. return [];
  11. }
  12. private function get($proxy, $url, $get = []){
  13. $curlproc = curl_init();
  14. if($get !== []){
  15. $get = http_build_query($get);
  16. $url .= "?" . $get;
  17. }
  18. curl_setopt($curlproc, CURLOPT_URL, $url);
  19. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  20. curl_setopt($curlproc, CURLOPT_HTTPHEADER,
  21. ["User-Agent: " . config::USER_AGENT,
  22. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
  23. "Accept-Language: en-US,en;q=0.5",
  24. "Accept-Encoding: gzip",
  25. "DNT: 1",
  26. "Connection: keep-alive",
  27. "Upgrade-Insecure-Requests: 1",
  28. "Sec-Fetch-Dest: document",
  29. "Sec-Fetch-Mode: navigate",
  30. "Sec-Fetch-Site: none",
  31. "Sec-Fetch-User: ?1"]
  32. );
  33. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  34. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  35. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  36. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  37. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  38. $this->backend->assign_proxy($curlproc, $proxy);
  39. $data = curl_exec($curlproc);
  40. if(curl_errno($curlproc)){
  41. throw new Exception(curl_error($curlproc));
  42. }
  43. curl_close($curlproc);
  44. return $data;
  45. }
  46. public function web($get){
  47. $search = $get["s"];
  48. if(strlen($search) === 0){
  49. throw new Exception("Search term is empty!");
  50. }
  51. $proxy = $this->backend->get_ip();
  52. try{
  53. $json = $this->get(
  54. $proxy,
  55. "https://crowdview-next-js.onrender.com/api/search-v3",
  56. [
  57. "query" => $search
  58. ]
  59. );
  60. }catch(Exception $error){
  61. throw new Exception("Failed to fetch JSON");
  62. }
  63. $out = [
  64. "status" => "ok",
  65. "spelling" => [
  66. "type" => "no_correction",
  67. "using" => null,
  68. "correction" => null
  69. ],
  70. "npt" => null,
  71. "answer" => [],
  72. "web" => [],
  73. "image" => [],
  74. "video" => [],
  75. "news" => [],
  76. "related" => []
  77. ];
  78. $json = json_decode($json, true);
  79. if($json === NULL){
  80. throw new Exception("Failed to decode JSON");
  81. }
  82. foreach($json["results"] as $item){
  83. $description = explode("<b>", $item["snippet"], 2);
  84. $out["web"][] = [
  85. "title" => $this->sanitize($item["title"]),
  86. "description" => $this->sanitize($description[1]),
  87. "url" => $item["link"],
  88. "date" => strtotime($description[0]),
  89. "type" => "web",
  90. "thumb" => [
  91. "url" => null,
  92. "ratio" => null
  93. ],
  94. "sublink" => [],
  95. "table" => []
  96. ];
  97. }
  98. return $out;
  99. }
  100. private function sanitize($html){
  101. return
  102. trim(
  103. $this->fuckhtml
  104. ->getTextContent(
  105. html_entity_decode(
  106. $html
  107. )
  108. ),
  109. ". "
  110. );
  111. }
  112. }