qwant.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. <?php
  2. class qwant{
  3. public function __construct(){
  4. include "lib/backend.php";
  5. $this->backend = new backend("qwant");
  6. }
  7. public function getfilters($page){
  8. $base = [
  9. "nsfw" => [
  10. "display" => "NSFW",
  11. "option" => [
  12. "yes" => "Yes",
  13. "maybe" => "Maybe",
  14. "no" => "No"
  15. ]
  16. ],
  17. "country" => [
  18. "display" => "Country",
  19. "option" => [
  20. "en_US" => "United States",
  21. "fr_FR" => "France",
  22. "en_GB" => "Great Britain",
  23. "de_DE" => "Germany",
  24. "it_IT" => "Italy",
  25. "es_AR" => "Argentina",
  26. "en_AU" => "Australia",
  27. "es_ES" => "Spain (es)",
  28. "ca_ES" => "Spain (ca)",
  29. "cs_CZ" => "Czech Republic",
  30. "ro_RO" => "Romania",
  31. "el_GR" => "Greece",
  32. "zh_CN" => "China",
  33. "zh_HK" => "Hong Kong",
  34. "en_NZ" => "New Zealand",
  35. "fr_FR" => "France",
  36. "th_TH" => "Thailand",
  37. "ko_KR" => "South Korea",
  38. "sv_SE" => "Sweden",
  39. "nb_NO" => "Norway",
  40. "da_DK" => "Denmark",
  41. "hu_HU" => "Hungary",
  42. "et_EE" => "Estonia",
  43. "es_MX" => "Mexico",
  44. "es_CL" => "Chile",
  45. "en_CA" => "Canada (en)",
  46. "fr_CA" => "Canada (fr)",
  47. "en_MY" => "Malaysia",
  48. "bg_BG" => "Bulgaria",
  49. "fi_FI" => "Finland",
  50. "pl_PL" => "Poland",
  51. "nl_NL" => "Netherlands",
  52. "pt_PT" => "Portugal",
  53. "de_CH" => "Switzerland (de)",
  54. "fr_CH" => "Switzerland (fr)",
  55. "it_CH" => "Switzerland (it)",
  56. "de_AT" => "Austria",
  57. "fr_BE" => "Belgium (fr)",
  58. "nl_BE" => "Belgium (nl)",
  59. "en_IE" => "Ireland",
  60. "he_IL" => "Israel"
  61. ]
  62. ]
  63. ];
  64. switch($page){
  65. case "web":
  66. $base = array_merge(
  67. $base,
  68. [
  69. "time" => [
  70. "display" => "Time posted",
  71. "option" => [
  72. "any" => "Any time",
  73. "day" => "Past 24 hours",
  74. "week" => "Past week",
  75. "month" => "Past month"
  76. ]
  77. ],
  78. "extendedsearch" => [
  79. // no display, wont show in interface
  80. "option" => [
  81. "yes" => "Yes",
  82. "no" => "No"
  83. ]
  84. ]
  85. ]
  86. );
  87. break;
  88. case "images":
  89. $base = array_merge(
  90. $base,
  91. [
  92. "time" => [
  93. "display" => "Time posted",
  94. "option" => [
  95. "any" => "Any time",
  96. "day" => "Past 24 hours",
  97. "week" => "Past week",
  98. "month" => "Past month"
  99. ]
  100. ],
  101. "size" => [
  102. "display" => "Size",
  103. "option" => [
  104. "any" => "Any size",
  105. "large" => "Large",
  106. "medium" => "Medium",
  107. "small" => "Small"
  108. ]
  109. ],
  110. "color" => [
  111. "display" => "Color",
  112. "option" => [
  113. "any" => "Any color",
  114. "coloronly" => "Color only",
  115. "monochrome" => "Monochrome",
  116. "black" => "Black",
  117. "brown" => "Brown",
  118. "gray" => "Gray",
  119. "white" => "White",
  120. "yellow" => "Yellow",
  121. "orange" => "Orange",
  122. "red" => "Red",
  123. "pink" => "Pink",
  124. "purple" => "Purple",
  125. "blue" => "Blue",
  126. "teal" => "Teal",
  127. "green" => "Green"
  128. ]
  129. ],
  130. "imagetype" => [
  131. "display" => "Type",
  132. "option" => [
  133. "any" => "Any type",
  134. "animatedgif" => "Animated GIF",
  135. "photo" => "Photograph",
  136. "transparent" => "Transparent"
  137. ]
  138. ],
  139. "license" => [
  140. "display" => "License",
  141. "option" => [
  142. "any" => "Any license",
  143. "share" => "Non-commercial reproduction and sharing",
  144. "sharecommercially" => "Reproduction and sharing",
  145. "modify" => "Non-commercial reproduction, sharing and modification",
  146. "modifycommercially" => "Reproduction, sharing and modification",
  147. "public" => "Public domain"
  148. ]
  149. ]
  150. ]
  151. );
  152. break;
  153. case "videos":
  154. $base = array_merge(
  155. $base,
  156. [
  157. "order" => [
  158. "display" => "Order by",
  159. "option" => [
  160. "relevance" => "Relevance",
  161. "views" => "Views",
  162. "date" => "Most recent",
  163. ]
  164. ],
  165. "source" => [
  166. "display" => "Source",
  167. "option" => [
  168. "any" => "Any source",
  169. "youtube" => "YouTube",
  170. "dailymotion" => "Dailymotion",
  171. ]
  172. ]
  173. ]
  174. );
  175. break;
  176. case "news":
  177. $base = array_merge(
  178. $base,
  179. [
  180. "time" => [
  181. "display" => "Time posted",
  182. "option" => [
  183. "any" => "Any time",
  184. "hour" => "Less than 1 hour ago",
  185. "day" => "Past 24 hours",
  186. "week" => "Past week",
  187. "month" => "Past month"
  188. ]
  189. ],
  190. "order" => [
  191. "display" => "Order by",
  192. "option" => [
  193. "relevance" => "Relevance",
  194. "date" => "Most recent"
  195. ]
  196. ]
  197. ]
  198. );
  199. break;
  200. }
  201. return $base;
  202. }
  203. private function get($proxy, $url, $get = []){
  204. $headers = [
  205. "User-Agent: " . config::USER_AGENT,
  206. "Accept: application/json, text/plain, */*",
  207. "Accept-Language: en-US,en;q=0.5",
  208. "Accept-Encoding: gzip",
  209. "DNT: 1",
  210. "Connection: keep-alive",
  211. "Origin: https://www.qwant.com",
  212. "Referer: https://www.qwant.com/",
  213. "Sec-Fetch-Dest: empty",
  214. "Sec-Fetch-Mode: cors",
  215. "Sec-Fetch-Site: same-site",
  216. "TE: trailers"
  217. ];
  218. $curlproc = curl_init();
  219. if($get !== []){
  220. $get = http_build_query($get);
  221. $url .= "?" . $get;
  222. }
  223. curl_setopt($curlproc, CURLOPT_URL, $url);
  224. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  225. curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
  226. // Bypass HTTP/2 check
  227. curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
  228. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  229. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  230. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  231. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  232. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  233. $this->backend->assign_proxy($curlproc, $proxy);
  234. $data = curl_exec($curlproc);
  235. if(curl_errno($curlproc)){
  236. throw new Exception(curl_error($curlproc));
  237. }
  238. curl_close($curlproc);
  239. return $data;
  240. }
  241. public function web($get){
  242. if($get["npt"]){
  243. // get next page data
  244. [$params, $proxy] = $this->backend->get($get["npt"], "web");
  245. $params = json_decode($params, true);
  246. }else{
  247. // get _GET data instead
  248. $search = $get["s"];
  249. if(strlen($search) === 0){
  250. throw new Exception("Search term is empty!");
  251. }
  252. if(strlen($search) > 2048){
  253. throw new Exception("Search term is too long!");
  254. }
  255. $proxy = $this->backend->get_ip();
  256. $params = [
  257. "q" => $search,
  258. "freshness" => $get["time"],
  259. "count" => 10,
  260. "locale" => $get["country"],
  261. "offset" => 0,
  262. "device" => "desktop",
  263. "tgp" => 3,
  264. "safesearch" => 0,
  265. "displayed" => "true"
  266. ];
  267. switch($get["nsfw"]){
  268. case "yes": $params["safesearch"] = 0; break;
  269. case "maybe": $params["safesearch"] = 1; break;
  270. case "no": $params["safesearch"] = 2; break;
  271. }
  272. }
  273. /*
  274. $handle = fopen("scraper/qwant_web.json", "r");
  275. $json = fread($handle, filesize("scraper/qwant_web.json"));
  276. fclose($handle);*/
  277. try{
  278. $json =
  279. $this->get(
  280. $proxy,
  281. "https://fdn.qwant.com/v3/search/web",
  282. $params
  283. );
  284. }catch(Exception $error){
  285. throw new Exception("Could not fetch JSON");
  286. }
  287. $json = json_decode($json, true);
  288. if($json === NULL){
  289. throw new Exception("Failed to decode JSON");
  290. }
  291. if(isset($json["data"]["message"][0])){
  292. throw new Exception("Server returned an error:\n" . $json["data"]["message"][0]);
  293. }
  294. if($json["status"] != "success"){
  295. if($json["data"]["error_code"] === 5){
  296. return $out;
  297. }
  298. throw new Exception("Server returned an error code: " . $json["data"]["error_code"]);
  299. }
  300. if(!isset($json["data"]["result"]["items"]["mainline"])){
  301. throw new Exception("Server did not return a result object");
  302. }
  303. // data is OK, parse
  304. $out = [
  305. "status" => "ok",
  306. "spelling" => [
  307. "type" => "no_correction",
  308. "using" => null,
  309. "correction" => null
  310. ],
  311. "npt" => null,
  312. "answer" => [],
  313. "web" => [],
  314. "image" => [],
  315. "video" => [],
  316. "news" => [],
  317. "related" => []
  318. ];
  319. // get instant answer
  320. if(
  321. $get["extendedsearch"] == "yes" &&
  322. isset($json["data"]["result"]["items"]["sidebar"][0]["endpoint"])
  323. ){
  324. try{
  325. $answer =
  326. $this->get(
  327. $proxy,
  328. "https://api.qwant.com/v3" .
  329. $json["data"]["result"]["items"]["sidebar"][0]["endpoint"],
  330. []
  331. );
  332. $answer = json_decode($answer, true);
  333. if(
  334. $answer === null ||
  335. $answer["status"] != "success" ||
  336. $answer["data"]["result"] === null
  337. ){
  338. throw new Exception();
  339. }
  340. // parse answer
  341. $out["answer"][] = [
  342. "title" => $answer["data"]["result"]["title"],
  343. "description" => [
  344. [
  345. "type" => "text",
  346. "value" => $this->trimdots($answer["data"]["result"]["description"])
  347. ]
  348. ],
  349. "url" => $answer["data"]["result"]["url"],
  350. "thumb" =>
  351. $answer["data"]["result"]["thumbnail"]["landscape"] == null ?
  352. null :
  353. $this->unshitimage(
  354. $answer["data"]["result"]["thumbnail"]["landscape"],
  355. false
  356. ),
  357. "table" => [],
  358. "sublink" => []
  359. ];
  360. }catch(Exception $error){
  361. // do nothing in case of failure
  362. }
  363. }
  364. // get word correction
  365. if(isset($json["data"]["query"]["queryContext"]["alteredQuery"])){
  366. $out["spelling"] = [
  367. "type" => "including",
  368. "using" => $json["data"]["query"]["queryContext"]["alteredQuery"],
  369. "correction" => $json["data"]["query"]["queryContext"]["alterationOverrideQuery"]
  370. ];
  371. }
  372. // check for next page
  373. if($json["data"]["result"]["lastPage"] === false){
  374. $params["offset"] = $params["offset"] + 10;
  375. $out["npt"] =
  376. $this->backend->store(
  377. json_encode($params),
  378. "web",
  379. $proxy
  380. );
  381. }
  382. // parse results
  383. foreach($json["data"]["result"]["items"]["mainline"] as $item){
  384. switch($item["type"]){ // ignores ads
  385. case "web":
  386. foreach($item["items"] as $result){
  387. if(isset($result["thumbnailUrl"])){
  388. $thumb = [
  389. "url" => $this->unshitimage($result["thumbnailUrl"]),
  390. "ratio" => "16:9"
  391. ];
  392. }else{
  393. $thumb = [
  394. "url" => null,
  395. "ratio" => null
  396. ];
  397. }
  398. $sublinks = [];
  399. if(isset($result["links"])){
  400. foreach($result["links"] as $link){
  401. $sublinks[] = [
  402. "title" => $this->trimdots($link["title"]),
  403. "date" => null,
  404. "description" => isset($link["desc"]) ? $this->trimdots($link["desc"]) : null,
  405. "url" => $link["url"]
  406. ];
  407. }
  408. }
  409. $out["web"][] = [
  410. "title" => $this->trimdots($result["title"]),
  411. "description" => $this->trimdots($result["desc"]),
  412. "url" => $result["url"],
  413. "date" => null,
  414. "type" => "web",
  415. "thumb" => $thumb,
  416. "sublink" => $sublinks,
  417. "table" => []
  418. ];
  419. }
  420. break;
  421. case "images":
  422. foreach($item["items"] as $image){
  423. $out["image"][] = [
  424. "title" => $image["title"],
  425. "source" => [
  426. [
  427. "url" => $image["media"],
  428. "width" => (int)$image["width"],
  429. "height" => (int)$image["height"]
  430. ],
  431. [
  432. "url" => $this->unshitimage($image["thumbnail"]),
  433. "width" => $image["thumb_width"],
  434. "height" => $image["thumb_height"]
  435. ]
  436. ],
  437. "url" => $image["url"]
  438. ];
  439. }
  440. break;
  441. case "videos":
  442. foreach($item["items"] as $video){
  443. $out["video"][] = [
  444. "title" => $video["title"],
  445. "description" => null,
  446. "date" => (int)$video["date"],
  447. "duration" => $video["duration"] === null ? null : $video["duration"] / 1000,
  448. "views" => null,
  449. "thumb" =>
  450. $video["thumbnail"] === null ?
  451. [
  452. "url" => null,
  453. "ratio" => null,
  454. ] :
  455. [
  456. "url" => $this->unshitimage($video["thumbnail"]),
  457. "ratio" => "16:9",
  458. ],
  459. "url" => $video["url"]
  460. ];
  461. }
  462. break;
  463. case "related_searches":
  464. foreach($item["items"] as $related){
  465. $out["related"][] = $related["text"];
  466. }
  467. break;
  468. }
  469. }
  470. return $out;
  471. }
  472. public function image($get){
  473. if($get["npt"]){
  474. [$params, $proxy] =
  475. $this->backend->get(
  476. $get["npt"],
  477. "images"
  478. );
  479. $params = json_decode($params, true);
  480. }else{
  481. $search = $get["s"];
  482. if(strlen($search) === 0){
  483. throw new Exception("Search term is empty!");
  484. }
  485. $proxy = $this->backend->get_ip();
  486. $params = [
  487. "t" => "images",
  488. "q" => $search,
  489. "count" => 125,
  490. "locale" => $get["country"],
  491. "offset" => 0, // increment by 125
  492. "device" => "desktop",
  493. "tgp" => 3
  494. ];
  495. if($get["time"] != "any"){
  496. $params["freshness"] = $get["time"];
  497. }
  498. foreach(["size", "color", "imagetype", "license"] as $p){
  499. if($get[$p] != "any"){
  500. $params[$p] = $get[$p];
  501. }
  502. }
  503. switch($get["nsfw"]){
  504. case "yes": $params["safesearch"] = 0; break;
  505. case "maybe": $params["safesearch"] = 1; break;
  506. case "no": $params["safesearch"] = 2; break;
  507. }
  508. }
  509. try{
  510. $json = $this->get(
  511. $proxy,
  512. "https://api.qwant.com/v3/search/images",
  513. $params,
  514. );
  515. }catch(Exception $err){
  516. throw new Exception("Failed to get JSON");
  517. }
  518. /*
  519. $handle = fopen("scraper/yandex.json", "r");
  520. $json = fread($handle, filesize("scraper/yandex.json"));
  521. fclose($handle);*/
  522. $json = json_decode($json, true);
  523. if($json === null){
  524. throw new Exception("Failed to decode JSON");
  525. }
  526. if($json["status"] != "success"){
  527. throw new Exception("Qwant returned an API error");
  528. }
  529. $out = [
  530. "status" => "ok",
  531. "npt" => null,
  532. "image" => []
  533. ];
  534. if($json["data"]["result"]["lastPage"] === false){
  535. $params["offset"] = $params["offset"] + 125;
  536. $out["npt"] = $this->backend->store(
  537. json_encode($params),
  538. "images",
  539. $proxy
  540. );
  541. }
  542. foreach($json["data"]["result"]["items"] as $image){
  543. $out["image"][] = [
  544. "title" => $this->trimdots($image["title"]),
  545. "source" => [
  546. [
  547. "url" => $image["media"],
  548. "width" => $image["width"],
  549. "height" => $image["height"]
  550. ],
  551. [
  552. "url" => $this->unshitimage($image["thumbnail"]),
  553. "width" => $image["thumb_width"],
  554. "height" => $image["thumb_height"]
  555. ]
  556. ],
  557. "url" => $image["url"]
  558. ];
  559. }
  560. return $out;
  561. }
  562. public function video($get){
  563. $search = $get["s"];
  564. if(strlen($search) === 0){
  565. throw new Exception("Search term is empty!");
  566. }
  567. $params = [
  568. "t" => "videos",
  569. "q" => $search,
  570. "count" => 50,
  571. "locale" => $get["country"],
  572. "offset" => 0, // dont implement pagination
  573. "device" => "desktop",
  574. "tgp" => 3
  575. ];
  576. switch($get["nsfw"]){
  577. case "yes": $params["safesearch"] = 0; break;
  578. case "maybe": $params["safesearch"] = 1; break;
  579. case "no": $params["safesearch"] = 2; break;
  580. }
  581. try{
  582. $json =
  583. $this->get(
  584. $this->backend->get_ip(),
  585. "https://api.qwant.com/v3/search/videos",
  586. $params
  587. );
  588. }catch(Exception $error){
  589. throw new Exception("Could not fetch JSON");
  590. }
  591. /*
  592. $handle = fopen("scraper/yandex-video.json", "r");
  593. $json = fread($handle, filesize("scraper/yandex-video.json"));
  594. fclose($handle);
  595. */
  596. $json = json_decode($json, true);
  597. if($json === null){
  598. throw new Exception("Could not parse JSON");
  599. }
  600. if($json["status"] != "success"){
  601. throw new Exception("Qwant returned an API error");
  602. }
  603. $out = [
  604. "status" => "ok",
  605. "npt" => null,
  606. "video" => [],
  607. "author" => [],
  608. "livestream" => [],
  609. "playlist" => [],
  610. "reel" => []
  611. ];
  612. foreach($json["data"]["result"]["items"] as $video){
  613. if(empty($video["thumbnail"])){
  614. $thumb = [
  615. "url" => null,
  616. "ratio" => null
  617. ];
  618. }else{
  619. $thumb = [
  620. "url" => $this->unshitimage($video["thumbnail"], false),
  621. "ratio" => "16:9"
  622. ];
  623. }
  624. $duration = (int)$video["duration"];
  625. $out["video"][] = [
  626. "title" => $video["title"],
  627. "description" => $this->limitstrlen($video["desc"]),
  628. "author" => [
  629. "name" => $video["channel"],
  630. "url" => null,
  631. "avatar" => null
  632. ],
  633. "date" => (int)$video["date"],
  634. "duration" => $duration === 0 ? null : $duration,
  635. "views" => null,
  636. "thumb" => $thumb,
  637. "url" => preg_replace("/\?syndication=.+/", "", $video["url"])
  638. ];
  639. }
  640. return $out;
  641. }
  642. public function news($get){
  643. $search = $get["s"];
  644. if(strlen($search) === 0){
  645. throw new Exception("Search term is empty!");
  646. }
  647. $params = [
  648. "t" => "news",
  649. "q" => $search,
  650. "count" => 50,
  651. "locale" => $get["country"],
  652. "offset" => 0, // dont implement pagination
  653. "device" => "desktop",
  654. "tgp" => 3
  655. ];
  656. switch($get["nsfw"]){
  657. case "yes": $params["safesearch"] = 0; break;
  658. case "maybe": $params["safesearch"] = 1; break;
  659. case "no": $params["safesearch"] = 2; break;
  660. }
  661. try{
  662. $json =
  663. $this->get(
  664. $this->backend->get_ip(),
  665. "https://api.qwant.com/v3/search/news",
  666. $params
  667. );
  668. }catch(Exception $error){
  669. throw new Exception("Could not fetch JSON");
  670. }
  671. /*
  672. $handle = fopen("scraper/yandex-video.json", "r");
  673. $json = fread($handle, filesize("scraper/yandex-video.json"));
  674. fclose($handle);
  675. */
  676. $json = json_decode($json, true);
  677. if($json === null){
  678. throw new Exception("Could not parse JSON");
  679. }
  680. if($json["status"] != "success"){
  681. throw new Exception("Qwant returned an API error");
  682. }
  683. $out = [
  684. "status" => "ok",
  685. "npt" => null,
  686. "news" => []
  687. ];
  688. foreach($json["data"]["result"]["items"] as $news){
  689. if(empty($news["media"][0]["pict_big"]["url"])){
  690. $thumb = [
  691. "url" => null,
  692. "ratio" => null
  693. ];
  694. }else{
  695. $thumb = [
  696. "url" => $this->unshitimage($news["media"][0]["pict_big"]["url"], false),
  697. "ratio" => "16:9"
  698. ];
  699. }
  700. $out["news"][] = [
  701. "title" => $news["title"],
  702. "author" => $news["press_name"],
  703. "description" => $this->trimdots($news["desc"]),
  704. "date" => (int)$news["date"],
  705. "thumb" => $thumb,
  706. "url" => $news["url"]
  707. ];
  708. }
  709. return $out;
  710. }
  711. private function limitstrlen($text){
  712. return explode("\n", wordwrap($text, 300, "\n"))[0];
  713. }
  714. private function trimdots($text){
  715. return trim($text, ". ");
  716. }
  717. private function unshitimage($url, $is_bing = true){
  718. // https://s1.qwant.com/thumbr/0x0/8/d/f6de4deb2c2b12f55d8bdcaae576f9f62fd58a05ec0feeac117b354d1bf5c2/th.jpg?u=https%3A%2F%2Fwww.bing.com%2Fth%3Fid%3DOIP.vvDWsagzxjoKKP_rOqhwrQAAAA%26w%3D160%26h%3D160%26c%3D7%26pid%3D5.1&q=0&b=1&p=0&a=0
  719. parse_str(parse_url($url)["query"], $parts);
  720. if($is_bing){
  721. $parse = parse_url($parts["u"]);
  722. parse_str($parse["query"], $parts);
  723. return "https://" . $parse["host"] . "/th?id=" . urlencode($parts["id"]);
  724. }
  725. return $parts["u"];
  726. }
  727. }