1
0

mwmbl.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. class mwmbl{
  3. public function __construct(){
  4. include "lib/backend.php";
  5. $this->backend = new backend("mwmbl");
  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. try{
  52. $html = $this->get(
  53. $this->backend->get_ip(), // no next page!
  54. "https://mwmbl.org/app/home/",
  55. [
  56. "q" => $search
  57. ]
  58. );
  59. }catch(Exception $error){
  60. throw new Exception("Failed to fetch HTML");
  61. }
  62. $out = [
  63. "status" => "ok",
  64. "spelling" => [
  65. "type" => "no_correction",
  66. "using" => null,
  67. "correction" => null
  68. ],
  69. "npt" => null,
  70. "answer" => [],
  71. "web" => [],
  72. "image" => [],
  73. "video" => [],
  74. "news" => [],
  75. "related" => []
  76. ];
  77. $this->fuckhtml->load($html);
  78. $results =
  79. $this->fuckhtml
  80. ->getElementsByClassName(
  81. "result",
  82. "li"
  83. );
  84. foreach($results as $result){
  85. $this->fuckhtml->load($result);
  86. $p =
  87. $this->fuckhtml
  88. ->getElementsByTagName("p");
  89. $out["web"][] = [
  90. "title" =>
  91. $this->titledots(
  92. $this->fuckhtml
  93. ->getTextContent(
  94. $this->fuckhtml
  95. ->getElementsByClassName(
  96. "title",
  97. $p
  98. )[0]
  99. )
  100. ),
  101. "description" =>
  102. $this->titledots(
  103. $this->fuckhtml
  104. ->getTextContent(
  105. $this->fuckhtml
  106. ->getElementsByClassName(
  107. "extract",
  108. $p
  109. )[0]
  110. )
  111. ),
  112. "url" =>
  113. $this->fuckhtml
  114. ->getTextContent(
  115. $this->fuckhtml
  116. ->getElementsByTagName("a")
  117. [0]
  118. ["attributes"]
  119. ["href"]
  120. ),
  121. "date" => null,
  122. "type" => "web",
  123. "thumb" => [
  124. "url" => null,
  125. "ratio" => null
  126. ],
  127. "sublink" => [],
  128. "table" => []
  129. ];
  130. }
  131. return $out;
  132. }
  133. private function titledots($title){
  134. return rtrim($title, "…");
  135. }
  136. }