1
0

google.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507
  1. <?php
  2. class google{
  3. private const is_class = ".";
  4. private const is_id = "#";
  5. public function __construct(){
  6. include "lib/fuckhtml.php";
  7. $this->fuckhtml = new fuckhtml();
  8. include "lib/nextpage.php";
  9. $this->nextpage = new nextpage("google");
  10. }
  11. public function getfilters($page){
  12. switch($page){
  13. case "web":
  14. return [
  15. "country" => [ // gl=<country>
  16. "display" => "Country",
  17. "option" => [
  18. "any" => "Instance's country",
  19. "af" => "Afghanistan",
  20. "al" => "Albania",
  21. "dz" => "Algeria",
  22. "as" => "American Samoa",
  23. "ad" => "Andorra",
  24. "ao" => "Angola",
  25. "ai" => "Anguilla",
  26. "aq" => "Antarctica",
  27. "ag" => "Antigua and Barbuda",
  28. "ar" => "Argentina",
  29. "am" => "Armenia",
  30. "aw" => "Aruba",
  31. "au" => "Australia",
  32. "at" => "Austria",
  33. "az" => "Azerbaijan",
  34. "bs" => "Bahamas",
  35. "bh" => "Bahrain",
  36. "bd" => "Bangladesh",
  37. "bb" => "Barbados",
  38. "by" => "Belarus",
  39. "be" => "Belgium",
  40. "bz" => "Belize",
  41. "bj" => "Benin",
  42. "bm" => "Bermuda",
  43. "bt" => "Bhutan",
  44. "bo" => "Bolivia",
  45. "ba" => "Bosnia and Herzegovina",
  46. "bw" => "Botswana",
  47. "bv" => "Bouvet Island",
  48. "br" => "Brazil",
  49. "io" => "British Indian Ocean Territory",
  50. "bn" => "Brunei Darussalam",
  51. "bg" => "Bulgaria",
  52. "bf" => "Burkina Faso",
  53. "bi" => "Burundi",
  54. "kh" => "Cambodia",
  55. "cm" => "Cameroon",
  56. "ca" => "Canada",
  57. "cv" => "Cape Verde",
  58. "ky" => "Cayman Islands",
  59. "cf" => "Central African Republic",
  60. "td" => "Chad",
  61. "cl" => "Chile",
  62. "cn" => "China",
  63. "cx" => "Christmas Island",
  64. "cc" => "Cocos (Keeling) Islands",
  65. "co" => "Colombia",
  66. "km" => "Comoros",
  67. "cg" => "Congo",
  68. "cd" => "Congo, the Democratic Republic",
  69. "ck" => "Cook Islands",
  70. "cr" => "Costa Rica",
  71. "ci" => "Cote D'ivoire",
  72. "hr" => "Croatia",
  73. "cu" => "Cuba",
  74. "cy" => "Cyprus",
  75. "cz" => "Czech Republic",
  76. "dk" => "Denmark",
  77. "dj" => "Djibouti",
  78. "dm" => "Dominica",
  79. "do" => "Dominican Republic",
  80. "ec" => "Ecuador",
  81. "eg" => "Egypt",
  82. "sv" => "El Salvador",
  83. "gq" => "Equatorial Guinea",
  84. "er" => "Eritrea",
  85. "ee" => "Estonia",
  86. "et" => "Ethiopia",
  87. "fk" => "Falkland Islands (Malvinas)",
  88. "fo" => "Faroe Islands",
  89. "fj" => "Fiji",
  90. "fi" => "Finland",
  91. "fr" => "France",
  92. "gf" => "French Guiana",
  93. "pf" => "French Polynesia",
  94. "tf" => "French Southern Territories",
  95. "ga" => "Gabon",
  96. "gm" => "Gambia",
  97. "ge" => "Georgia",
  98. "de" => "Germany",
  99. "gh" => "Ghana",
  100. "gi" => "Gibraltar",
  101. "gr" => "Greece",
  102. "gl" => "Greenland",
  103. "gd" => "Grenada",
  104. "gp" => "Guadeloupe",
  105. "gu" => "Guam",
  106. "gt" => "Guatemala",
  107. "gn" => "Guinea",
  108. "gw" => "Guinea-Bissau",
  109. "gy" => "Guyana",
  110. "ht" => "Haiti",
  111. "hm" => "Heard Island and Mcdonald Islands",
  112. "va" => "Holy See (Vatican City State)",
  113. "hn" => "Honduras",
  114. "hk" => "Hong Kong",
  115. "hu" => "Hungary",
  116. "is" => "Iceland",
  117. "in" => "India",
  118. "id" => "Indonesia",
  119. "ir" => "Iran, Islamic Republic",
  120. "iq" => "Iraq",
  121. "ie" => "Ireland",
  122. "il" => "Israel",
  123. "it" => "Italy",
  124. "jm" => "Jamaica",
  125. "jp" => "Japan",
  126. "jo" => "Jordan",
  127. "kz" => "Kazakhstan",
  128. "ke" => "Kenya",
  129. "ki" => "Kiribati",
  130. "kp" => "Korea, Democratic People's Republic",
  131. "kr" => "Korea, Republic",
  132. "kw" => "Kuwait",
  133. "kg" => "Kyrgyzstan",
  134. "la" => "Lao People's Democratic Republic",
  135. "lv" => "Latvia",
  136. "lb" => "Lebanon",
  137. "ls" => "Lesotho",
  138. "lr" => "Liberia",
  139. "ly" => "Libyan Arab Jamahiriya",
  140. "li" => "Liechtenstein",
  141. "lt" => "Lithuania",
  142. "lu" => "Luxembourg",
  143. "mo" => "Macao",
  144. "mk" => "Macedonia, the Former Yugosalv Republic",
  145. "mg" => "Madagascar",
  146. "mw" => "Malawi",
  147. "my" => "Malaysia",
  148. "mv" => "Maldives",
  149. "ml" => "Mali",
  150. "mt" => "Malta",
  151. "mh" => "Marshall Islands",
  152. "mq" => "Martinique",
  153. "mr" => "Mauritania",
  154. "mu" => "Mauritius",
  155. "yt" => "Mayotte",
  156. "mx" => "Mexico",
  157. "fm" => "Micronesia, Federated States",
  158. "md" => "Moldova, Republic",
  159. "mc" => "Monaco",
  160. "mn" => "Mongolia",
  161. "ms" => "Montserrat",
  162. "ma" => "Morocco",
  163. "mz" => "Mozambique",
  164. "mm" => "Myanmar",
  165. "na" => "Namibia",
  166. "nr" => "Nauru",
  167. "np" => "Nepal",
  168. "nl" => "Netherlands",
  169. "an" => "Netherlands Antilles",
  170. "nc" => "New Caledonia",
  171. "nz" => "New Zealand",
  172. "ni" => "Nicaragua",
  173. "ne" => "Niger",
  174. "ng" => "Nigeria",
  175. "nu" => "Niue",
  176. "nf" => "Norfolk Island",
  177. "mp" => "Northern Mariana Islands",
  178. "no" => "Norway",
  179. "om" => "Oman",
  180. "pk" => "Pakistan",
  181. "pw" => "Palau",
  182. "ps" => "Palestinian Territory, Occupied",
  183. "pa" => "Panama",
  184. "pg" => "Papua New Guinea",
  185. "py" => "Paraguay",
  186. "pe" => "Peru",
  187. "ph" => "Philippines",
  188. "pn" => "Pitcairn",
  189. "pl" => "Poland",
  190. "pt" => "Portugal",
  191. "pr" => "Puerto Rico",
  192. "qa" => "Qatar",
  193. "re" => "Reunion",
  194. "ro" => "Romania",
  195. "ru" => "Russian Federation",
  196. "rw" => "Rwanda",
  197. "sh" => "Saint Helena",
  198. "kn" => "Saint Kitts and Nevis",
  199. "lc" => "Saint Lucia",
  200. "pm" => "Saint Pierre and Miquelon",
  201. "vc" => "Saint Vincent and the Grenadines",
  202. "ws" => "Samoa",
  203. "sm" => "San Marino",
  204. "st" => "Sao Tome and Principe",
  205. "sa" => "Saudi Arabia",
  206. "sn" => "Senegal",
  207. "cs" => "Serbia and Montenegro",
  208. "sc" => "Seychelles",
  209. "sl" => "Sierra Leone",
  210. "sg" => "Singapore",
  211. "sk" => "Slovakia",
  212. "si" => "Slovenia",
  213. "sb" => "Solomon Islands",
  214. "so" => "Somalia",
  215. "za" => "South Africa",
  216. "gs" => "South Georgia and the South Sandwich Islands",
  217. "es" => "Spain",
  218. "lk" => "Sri Lanka",
  219. "sd" => "Sudan",
  220. "sr" => "Suriname",
  221. "sj" => "Svalbard and Jan Mayen",
  222. "sz" => "Swaziland",
  223. "se" => "Sweden",
  224. "ch" => "Switzerland",
  225. "sy" => "Syrian Arab Republic",
  226. "tw" => "Taiwan, Province of China",
  227. "tj" => "Tajikistan",
  228. "tz" => "Tanzania, United Republic",
  229. "th" => "Thailand",
  230. "tl" => "Timor-Leste",
  231. "tg" => "Togo",
  232. "tk" => "Tokelau",
  233. "to" => "Tonga",
  234. "tt" => "Trinidad and Tobago",
  235. "tn" => "Tunisia",
  236. "tr" => "Turkey",
  237. "tm" => "Turkmenistan",
  238. "tc" => "Turks and Caicos Islands",
  239. "tv" => "Tuvalu",
  240. "ug" => "Uganda",
  241. "ua" => "Ukraine",
  242. "ae" => "United Arab Emirates",
  243. "uk" => "United Kingdom",
  244. "us" => "United States",
  245. "um" => "United States Minor Outlying Islands",
  246. "uy" => "Uruguay",
  247. "uz" => "Uzbekistan",
  248. "vu" => "Vanuatu",
  249. "ve" => "Venezuela",
  250. "vn" => "Viet Nam",
  251. "vg" => "Virgin Islands, British",
  252. "vi" => "Virgin Islands, U.S.",
  253. "wf" => "Wallis and Futuna",
  254. "eh" => "Western Sahara",
  255. "ye" => "Yemen",
  256. "zm" => "Zambia",
  257. "zw" => "Zimbabwe"
  258. ]
  259. ],
  260. "nsfw" => [
  261. "display" => "NSFW",
  262. "option" => [
  263. "yes" => "Yes", // safe=active
  264. "no" => "No" // safe=off
  265. ]
  266. ],
  267. "lang" => [ // lr=<lang> (prefix lang with "lang_")
  268. "display" => "Language",
  269. "option" => [
  270. "any" => "Any language",
  271. "ar" => "Arabic",
  272. "bg" => "Bulgarian",
  273. "ca" => "Catalan",
  274. "cs" => "Czech",
  275. "da" => "Danish",
  276. "de" => "German",
  277. "el" => "Greek",
  278. "en" => "English",
  279. "es" => "Spanish",
  280. "et" => "Estonian",
  281. "fi" => "Finnish",
  282. "fr" => "French",
  283. "hr" => "Croatian",
  284. "hu" => "Hungarian",
  285. "id" => "Indonesian",
  286. "is" => "Icelandic",
  287. "it" => "Italian",
  288. "iw" => "Hebrew",
  289. "ja" => "Japanese",
  290. "ko" => "Korean",
  291. "lt" => "Lithuanian",
  292. "lv" => "Latvian",
  293. "nl" => "Dutch",
  294. "no" => "Norwegian",
  295. "pl" => "Polish",
  296. "pt" => "Portuguese",
  297. "ro" => "Romanian",
  298. "ru" => "Russian",
  299. "sk" => "Slovak",
  300. "sl" => "Slovenian",
  301. "sr" => "Serbian",
  302. "sv" => "Swedish",
  303. "tr" => "Turkish",
  304. "zh-CN" => "Chinese (Simplified)",
  305. "zh-TW" => "Chinese (Traditional)"
  306. ]
  307. ],
  308. "newer" => [ // &sort=review-date:r:20090301:20090430
  309. "display" => "Newer than",
  310. "option" => "_DATE"
  311. ],
  312. "older" => [
  313. "display" => "Older than",
  314. "option" => "_DATE"
  315. ]
  316. ];
  317. break;
  318. case "images":
  319. return [
  320. "country" => [ // gl=<country>
  321. "display" => "Country",
  322. "option" => [
  323. "any" => "Instance's country",
  324. "af" => "Afghanistan",
  325. "al" => "Albania",
  326. "dz" => "Algeria",
  327. "as" => "American Samoa",
  328. "ad" => "Andorra",
  329. "ao" => "Angola",
  330. "ai" => "Anguilla",
  331. "aq" => "Antarctica",
  332. "ag" => "Antigua and Barbuda",
  333. "ar" => "Argentina",
  334. "am" => "Armenia",
  335. "aw" => "Aruba",
  336. "au" => "Australia",
  337. "at" => "Austria",
  338. "az" => "Azerbaijan",
  339. "bs" => "Bahamas",
  340. "bh" => "Bahrain",
  341. "bd" => "Bangladesh",
  342. "bb" => "Barbados",
  343. "by" => "Belarus",
  344. "be" => "Belgium",
  345. "bz" => "Belize",
  346. "bj" => "Benin",
  347. "bm" => "Bermuda",
  348. "bt" => "Bhutan",
  349. "bo" => "Bolivia",
  350. "ba" => "Bosnia and Herzegovina",
  351. "bw" => "Botswana",
  352. "bv" => "Bouvet Island",
  353. "br" => "Brazil",
  354. "io" => "British Indian Ocean Territory",
  355. "bn" => "Brunei Darussalam",
  356. "bg" => "Bulgaria",
  357. "bf" => "Burkina Faso",
  358. "bi" => "Burundi",
  359. "kh" => "Cambodia",
  360. "cm" => "Cameroon",
  361. "ca" => "Canada",
  362. "cv" => "Cape Verde",
  363. "ky" => "Cayman Islands",
  364. "cf" => "Central African Republic",
  365. "td" => "Chad",
  366. "cl" => "Chile",
  367. "cn" => "China",
  368. "cx" => "Christmas Island",
  369. "cc" => "Cocos (Keeling) Islands",
  370. "co" => "Colombia",
  371. "km" => "Comoros",
  372. "cg" => "Congo",
  373. "cd" => "Congo, the Democratic Republic",
  374. "ck" => "Cook Islands",
  375. "cr" => "Costa Rica",
  376. "ci" => "Cote D'ivoire",
  377. "hr" => "Croatia",
  378. "cu" => "Cuba",
  379. "cy" => "Cyprus",
  380. "cz" => "Czech Republic",
  381. "dk" => "Denmark",
  382. "dj" => "Djibouti",
  383. "dm" => "Dominica",
  384. "do" => "Dominican Republic",
  385. "ec" => "Ecuador",
  386. "eg" => "Egypt",
  387. "sv" => "El Salvador",
  388. "gq" => "Equatorial Guinea",
  389. "er" => "Eritrea",
  390. "ee" => "Estonia",
  391. "et" => "Ethiopia",
  392. "fk" => "Falkland Islands (Malvinas)",
  393. "fo" => "Faroe Islands",
  394. "fj" => "Fiji",
  395. "fi" => "Finland",
  396. "fr" => "France",
  397. "gf" => "French Guiana",
  398. "pf" => "French Polynesia",
  399. "tf" => "French Southern Territories",
  400. "ga" => "Gabon",
  401. "gm" => "Gambia",
  402. "ge" => "Georgia",
  403. "de" => "Germany",
  404. "gh" => "Ghana",
  405. "gi" => "Gibraltar",
  406. "gr" => "Greece",
  407. "gl" => "Greenland",
  408. "gd" => "Grenada",
  409. "gp" => "Guadeloupe",
  410. "gu" => "Guam",
  411. "gt" => "Guatemala",
  412. "gn" => "Guinea",
  413. "gw" => "Guinea-Bissau",
  414. "gy" => "Guyana",
  415. "ht" => "Haiti",
  416. "hm" => "Heard Island and Mcdonald Islands",
  417. "va" => "Holy See (Vatican City State)",
  418. "hn" => "Honduras",
  419. "hk" => "Hong Kong",
  420. "hu" => "Hungary",
  421. "is" => "Iceland",
  422. "in" => "India",
  423. "id" => "Indonesia",
  424. "ir" => "Iran, Islamic Republic",
  425. "iq" => "Iraq",
  426. "ie" => "Ireland",
  427. "il" => "Israel",
  428. "it" => "Italy",
  429. "jm" => "Jamaica",
  430. "jp" => "Japan",
  431. "jo" => "Jordan",
  432. "kz" => "Kazakhstan",
  433. "ke" => "Kenya",
  434. "ki" => "Kiribati",
  435. "kp" => "Korea, Democratic People's Republic",
  436. "kr" => "Korea, Republic",
  437. "kw" => "Kuwait",
  438. "kg" => "Kyrgyzstan",
  439. "la" => "Lao People's Democratic Republic",
  440. "lv" => "Latvia",
  441. "lb" => "Lebanon",
  442. "ls" => "Lesotho",
  443. "lr" => "Liberia",
  444. "ly" => "Libyan Arab Jamahiriya",
  445. "li" => "Liechtenstein",
  446. "lt" => "Lithuania",
  447. "lu" => "Luxembourg",
  448. "mo" => "Macao",
  449. "mk" => "Macedonia, the Former Yugosalv Republic",
  450. "mg" => "Madagascar",
  451. "mw" => "Malawi",
  452. "my" => "Malaysia",
  453. "mv" => "Maldives",
  454. "ml" => "Mali",
  455. "mt" => "Malta",
  456. "mh" => "Marshall Islands",
  457. "mq" => "Martinique",
  458. "mr" => "Mauritania",
  459. "mu" => "Mauritius",
  460. "yt" => "Mayotte",
  461. "mx" => "Mexico",
  462. "fm" => "Micronesia, Federated States",
  463. "md" => "Moldova, Republic",
  464. "mc" => "Monaco",
  465. "mn" => "Mongolia",
  466. "ms" => "Montserrat",
  467. "ma" => "Morocco",
  468. "mz" => "Mozambique",
  469. "mm" => "Myanmar",
  470. "na" => "Namibia",
  471. "nr" => "Nauru",
  472. "np" => "Nepal",
  473. "nl" => "Netherlands",
  474. "an" => "Netherlands Antilles",
  475. "nc" => "New Caledonia",
  476. "nz" => "New Zealand",
  477. "ni" => "Nicaragua",
  478. "ne" => "Niger",
  479. "ng" => "Nigeria",
  480. "nu" => "Niue",
  481. "nf" => "Norfolk Island",
  482. "mp" => "Northern Mariana Islands",
  483. "no" => "Norway",
  484. "om" => "Oman",
  485. "pk" => "Pakistan",
  486. "pw" => "Palau",
  487. "ps" => "Palestinian Territory, Occupied",
  488. "pa" => "Panama",
  489. "pg" => "Papua New Guinea",
  490. "py" => "Paraguay",
  491. "pe" => "Peru",
  492. "ph" => "Philippines",
  493. "pn" => "Pitcairn",
  494. "pl" => "Poland",
  495. "pt" => "Portugal",
  496. "pr" => "Puerto Rico",
  497. "qa" => "Qatar",
  498. "re" => "Reunion",
  499. "ro" => "Romania",
  500. "ru" => "Russian Federation",
  501. "rw" => "Rwanda",
  502. "sh" => "Saint Helena",
  503. "kn" => "Saint Kitts and Nevis",
  504. "lc" => "Saint Lucia",
  505. "pm" => "Saint Pierre and Miquelon",
  506. "vc" => "Saint Vincent and the Grenadines",
  507. "ws" => "Samoa",
  508. "sm" => "San Marino",
  509. "st" => "Sao Tome and Principe",
  510. "sa" => "Saudi Arabia",
  511. "sn" => "Senegal",
  512. "cs" => "Serbia and Montenegro",
  513. "sc" => "Seychelles",
  514. "sl" => "Sierra Leone",
  515. "sg" => "Singapore",
  516. "sk" => "Slovakia",
  517. "si" => "Slovenia",
  518. "sb" => "Solomon Islands",
  519. "so" => "Somalia",
  520. "za" => "South Africa",
  521. "gs" => "South Georgia and the South Sandwich Islands",
  522. "es" => "Spain",
  523. "lk" => "Sri Lanka",
  524. "sd" => "Sudan",
  525. "sr" => "Suriname",
  526. "sj" => "Svalbard and Jan Mayen",
  527. "sz" => "Swaziland",
  528. "se" => "Sweden",
  529. "ch" => "Switzerland",
  530. "sy" => "Syrian Arab Republic",
  531. "tw" => "Taiwan, Province of China",
  532. "tj" => "Tajikistan",
  533. "tz" => "Tanzania, United Republic",
  534. "th" => "Thailand",
  535. "tl" => "Timor-Leste",
  536. "tg" => "Togo",
  537. "tk" => "Tokelau",
  538. "to" => "Tonga",
  539. "tt" => "Trinidad and Tobago",
  540. "tn" => "Tunisia",
  541. "tr" => "Turkey",
  542. "tm" => "Turkmenistan",
  543. "tc" => "Turks and Caicos Islands",
  544. "tv" => "Tuvalu",
  545. "ug" => "Uganda",
  546. "ua" => "Ukraine",
  547. "ae" => "United Arab Emirates",
  548. "uk" => "United Kingdom",
  549. "us" => "United States",
  550. "um" => "United States Minor Outlying Islands",
  551. "uy" => "Uruguay",
  552. "uz" => "Uzbekistan",
  553. "vu" => "Vanuatu",
  554. "ve" => "Venezuela",
  555. "vn" => "Viet Nam",
  556. "vg" => "Virgin Islands, British",
  557. "vi" => "Virgin Islands, U.S.",
  558. "wf" => "Wallis and Futuna",
  559. "eh" => "Western Sahara",
  560. "ye" => "Yemen",
  561. "zm" => "Zambia",
  562. "zw" => "Zimbabwe"
  563. ]
  564. ],
  565. "nsfw" => [
  566. "display" => "NSFW",
  567. "option" => [
  568. "yes" => "Yes", // safe=active
  569. "no" => "No" // safe=off
  570. ]
  571. ],
  572. "lang" => [ // lr=<lang> (prefix lang with "lang_")
  573. "display" => "Language",
  574. "option" => [
  575. "any" => "Any language",
  576. "ar" => "Arabic",
  577. "bg" => "Bulgarian",
  578. "ca" => "Catalan",
  579. "cs" => "Czech",
  580. "da" => "Danish",
  581. "de" => "German",
  582. "el" => "Greek",
  583. "en" => "English",
  584. "es" => "Spanish",
  585. "et" => "Estonian",
  586. "fi" => "Finnish",
  587. "fr" => "French",
  588. "hr" => "Croatian",
  589. "hu" => "Hungarian",
  590. "id" => "Indonesian",
  591. "is" => "Icelandic",
  592. "it" => "Italian",
  593. "iw" => "Hebrew",
  594. "ja" => "Japanese",
  595. "ko" => "Korean",
  596. "lt" => "Lithuanian",
  597. "lv" => "Latvian",
  598. "nl" => "Dutch",
  599. "no" => "Norwegian",
  600. "pl" => "Polish",
  601. "pt" => "Portuguese",
  602. "ro" => "Romanian",
  603. "ru" => "Russian",
  604. "sk" => "Slovak",
  605. "sl" => "Slovenian",
  606. "sr" => "Serbian",
  607. "sv" => "Swedish",
  608. "tr" => "Turkish",
  609. "zh-CN" => "Chinese (Simplified)",
  610. "zh-TW" => "Chinese (Traditional)"
  611. ]
  612. ],
  613. "newer" => [ // &sort=review-date:r:20090301:20090430
  614. "display" => "Newer than",
  615. "option" => "_DATE"
  616. ],
  617. "older" => [
  618. "display" => "Older than",
  619. "option" => "_DATE"
  620. ],
  621. "size" => [ // tbs=isz:<size>
  622. "display" => "Size",
  623. "option" => [
  624. "any" => "Any size",
  625. "l" => "Large",
  626. "m" => "Medium",
  627. "i" => "Icon"
  628. ]
  629. ],
  630. "colortype" => [ // imgColorType=<color>
  631. "display" => "Color type",
  632. "option" => [
  633. "any" => "Any color type",
  634. "color" => "Colored",
  635. "gray" => "Gray",
  636. "mono" => "Black & white",
  637. "trans" => "Transparent"
  638. ]
  639. ],
  640. "color" => [ // imgDominantColor=<color>
  641. "display" => "Color",
  642. "option" => [
  643. "any" => "Any color",
  644. "red" => "Red",
  645. "orange" => "Orange",
  646. "yellow" => "Yellow",
  647. "green" => "Green",
  648. "teal" => "Teal",
  649. "blue" => "Blue",
  650. "purple" => "Purple",
  651. "pink" => "Pink",
  652. "white" => "White",
  653. "gray" => "Gray",
  654. "black" => "Black",
  655. "brown" => "Brown"
  656. ]
  657. ],
  658. "type" => [ // imgType=<type>
  659. "display" => "Type",
  660. "option" => [
  661. "any" => "Any type",
  662. "face" => "Faces",
  663. "clipart" => "Clip Art",
  664. "lineart" => "Line Drawing",
  665. "stock" => "Stock",
  666. "animated" => "Animated"
  667. ]
  668. ],
  669. "rights" => [ // tbs=il:<rights>
  670. "display" => "Usage rights",
  671. "option" => [
  672. "any" => "No license",
  673. "cl" => "Creative Commons licenses",
  674. "ol" => "Commercial & other licenses"
  675. ]
  676. ]
  677. ];
  678. break;
  679. }
  680. }
  681. private function get($url, $get = []){
  682. $headers = [
  683. "User-Agent: Mozilla/5.0 (Linux; U; Android 2.3.3; pt-pt; LG-P500h-parrot Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MMS/LG-Android-MMS-V1.0/1.2",
  684. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
  685. "Accept-Language: en-US,en;q=0.5",
  686. "Accept-Encoding: gzip",
  687. "DNT: 1",
  688. "Connection: keep-alive",
  689. "Upgrade-Insecure-Requests: 1",
  690. "Sec-Fetch-Dest: document",
  691. "Sec-Fetch-Mode: navigate",
  692. "Sec-Fetch-Site: none",
  693. "Sec-Fetch-User: ?1"
  694. ];
  695. $curlproc = curl_init();
  696. if($get !== []){
  697. $get = http_build_query($get);
  698. $url .= "?" . $get;
  699. }
  700. curl_setopt($curlproc, CURLOPT_URL, $url);
  701. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  702. curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
  703. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  704. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  705. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  706. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  707. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  708. $data = curl_exec($curlproc);
  709. if(curl_errno($curlproc)){
  710. throw new Exception(curl_error($curlproc));
  711. }
  712. curl_close($curlproc);
  713. return $data;
  714. }
  715. public function web($get){
  716. $search = $get["s"];
  717. $country = $get["country"];
  718. $nsfw = $get["nsfw"];
  719. $lang = $get["lang"];
  720. $older = $get["older"];
  721. $newer = $get["newer"];
  722. $params = [
  723. "num" => 20 // get 20 results
  724. ];
  725. // country
  726. if($country != "any"){
  727. $params["gl"] = $country;
  728. }
  729. // nsfw
  730. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  731. // language
  732. if($lang != "any"){
  733. $params["lr"] = "lang_" . $lang;
  734. }
  735. // &sort=review-date:r:20090301:20090430
  736. $older = $older === false ? false : date("Ymd", $older);
  737. $newer = $newer === false ? false : date("Ymd", $newer);
  738. if(
  739. $older !== false &&
  740. $newer === false
  741. ){
  742. $newer = date("Ymd", time());
  743. }
  744. if(
  745. $older !== false ||
  746. $newer !== false
  747. ){
  748. $params["sort"] = "review-date:r:" . $older . ":" . $newer;
  749. }
  750. $handle = fopen("scraper/google.html", "r");
  751. $html = fread($handle, filesize("scraper/google.html"));
  752. fclose($handle);
  753. $this->fuckhtml->load($html);
  754. $out = [
  755. "status" => "ok",
  756. "spelling" => [
  757. "type" => "no_correction",
  758. "using" => null,
  759. "correction" => null
  760. ],
  761. "npt" => null,
  762. "answer" => [],
  763. "web" => [],
  764. "image" => [],
  765. "video" => [],
  766. "news" => [],
  767. "related" => []
  768. ];
  769. $styles =
  770. $this->fuckhtml
  771. ->getElementsByTagName("style");
  772. $this->computedstyle = [];
  773. $this->ask = [];
  774. foreach($styles as $style){
  775. $this->computedstyle =
  776. array_merge(
  777. $this->computedstyle,
  778. $this->parsestyles($style["innerHTML"])
  779. );
  780. }
  781. // get images in javascript var
  782. preg_match(
  783. '/google\.ldi=({[^}]+})/',
  784. $html,
  785. $this->js_image
  786. );
  787. if(count($this->js_image) !== 0){
  788. $this->js_image = json_decode($this->js_image[1], true);
  789. }else{
  790. $this->js_image = [];
  791. }
  792. // additional js_images present in <script> tags
  793. // ugh i fucking hate you
  794. $scripts =
  795. $this->fuckhtml
  796. ->getElementsByTagName("script");
  797. foreach($scripts as $script){
  798. if(!isset($script["innerHTML"])){
  799. continue;
  800. }
  801. preg_match_all(
  802. '/var s=\'(data:image[^\']+)\';var i=\[\'([^\']+)\'];/',
  803. $script["innerHTML"],
  804. $image_grep
  805. );
  806. if(count($image_grep[0]) !== 0){
  807. $this->js_image[trim($image_grep[2][0])] =
  808. $this->fuckhtml
  809. ->getTextContent(
  810. $image_grep[1][0]
  811. );
  812. }
  813. // even more javascript crap
  814. // "People also ask" node is loaded trough javascript
  815. preg_match_all(
  816. '/window\.jsl\.dh\(\'([^\']+)\',\'(.+)\'\);/',
  817. $script["innerHTML"],
  818. $ask_grep
  819. );
  820. for($i=0; $i<count($ask_grep[0]); $i++){
  821. $this->ask[trim($ask_grep[1][$i])] =
  822. stripcslashes(
  823. $ask_grep[2][$i]
  824. );
  825. }
  826. }
  827. // get nodes
  828. // fuck you google!!!!!!!!!!!!!!
  829. $containers =
  830. $this->fuckhtml
  831. ->getElementsByClassName(
  832. $this->findstyles(
  833. [
  834. "background-color" => "#fff",
  835. "margin-bottom" => "10px",
  836. "-webkit-box-shadow" => "0 1px 6px rgba(32,33,36,0.28)",
  837. "border-radius" => "8px"
  838. ],
  839. self::is_class
  840. ),
  841. "div"
  842. );
  843. foreach($containers as $container){
  844. $this->fuckhtml->load($container);
  845. // get link at the top
  846. $link =
  847. $this->fuckhtml
  848. ->getElementsByTagName(
  849. "a"
  850. );
  851. if(count($link) !== 0){
  852. $link =
  853. $this->decodeurl(
  854. $link
  855. [0]
  856. ["attributes"]
  857. ["href"]
  858. );
  859. }
  860. /*
  861. Check for carousel presence
  862. */
  863. $carousel =
  864. $this->fuckhtml
  865. ->getElementsByClassName(
  866. "pcitem",
  867. "div"
  868. );
  869. $title =
  870. $this->fuckhtml
  871. ->getElementsByClassName(
  872. $this->findstyles(
  873. [
  874. "color" => "#1967d2",
  875. "font-size" => "20px",
  876. "line-height" => "26px"
  877. ],
  878. self::is_class
  879. ),
  880. "div"
  881. );
  882. if(count($carousel) !== 0){
  883. $carousel_title =
  884. $this->fuckhtml
  885. ->getElementsByClassName(
  886. $this->findstyles(
  887. [
  888. "font-size" => "16px",
  889. "line-height" => "20px",
  890. "font-weight" => "400"
  891. ],
  892. self::is_class
  893. ),
  894. "div"
  895. );
  896. $sublink = []; // twitter carousel sublinks
  897. foreach($carousel as $item){
  898. $this->fuckhtml->load($item);
  899. $url =
  900. $this->decodeurl(
  901. $this->fuckhtml
  902. ->getElementsByTagName(
  903. "a"
  904. )[0]
  905. ["attributes"]
  906. ["href"]
  907. );
  908. // detect if its a twitter carousel or
  909. // a list of news articles
  910. $grey_node =
  911. $this->fuckhtml
  912. ->getElementsByClassName(
  913. $this->findstyles(
  914. [
  915. "white-space" => "pre-line",
  916. "word-wrap" => "break-word"
  917. ],
  918. self::is_class
  919. ),
  920. "div"
  921. );
  922. if(count($carousel_title) !== 0){
  923. switch(
  924. strtolower(
  925. $this->fuckhtml
  926. ->getTextContent(
  927. $carousel_title[0]
  928. )
  929. )
  930. ){
  931. case "top stories":
  932. $img =
  933. $this->fuckhtml
  934. ->getElementsByTagName("img");
  935. if(
  936. count($img) !== 0 &&
  937. isset($img[0]["attributes"]["id"]) &&
  938. isset($this->js_image[$img[0]["attributes"]["id"]])
  939. ){
  940. $img = [
  941. "url" => $this->getimage($img[0]["attributes"]["id"]),
  942. "ratio" => "16:9"
  943. ];
  944. }else{
  945. $img = [
  946. "url" => null,
  947. "ratio" => null
  948. ];
  949. }
  950. /*
  951. Is a news node
  952. */
  953. $out["news"][] = [
  954. "title" =>
  955. $this->fuckhtml
  956. ->getTextContent(
  957. $grey_node[0]
  958. ),
  959. "description" => null,
  960. "date" =>
  961. strtotime(
  962. explode(
  963. "\n",
  964. $grey_node[1]["innerHTML"]
  965. )[1]
  966. ),
  967. "thumb" => $img,
  968. "url" => $url
  969. ];
  970. break;
  971. case "images":
  972. /*
  973. We found an image
  974. */
  975. $imagedata =
  976. $this->fuckhtml
  977. ->getElementsByClassName(
  978. $this->findstyles(
  979. [
  980. "display" => "block",
  981. "background-color" => "#fff",
  982. "border-radius" => "8px",
  983. "-webkit-box-shadow" => "0 1px 6px rgba(32, 33, 36, 0.28)",
  984. "overflow" => "hidden"
  985. ],
  986. self::is_class
  987. ),
  988. "a"
  989. );
  990. if(count($imagedata) === 0){
  991. break;
  992. }
  993. $imagedata = $imagedata[0];
  994. // https://www.google.com/imgres?imgurl=https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Joe_Biden_presidential_portrait_%2528cropped%2529.jpg/220px-Joe_Biden_presidential_portrait_%2528cropped%2529.jpg&imgrefurl=https://en.wikipedia.org/wiki/President_of_the_United_States&h=293&w=220&tbnid=kkQHBIAMuTitdM&q=who+is+the+president+of+the+united+states&tbnh=115&tbnw=86&usg=AI4_-kQVKi-K2zTGmVkS75_Fo6VldpPxsg&vet=1&docid=d2vgvyYSkU0hiM&sa=X&ved=2ahUKEwjKrMT17KyAAxV1j4kEHRAVCoYQ9QF6BAgFEAQ
  995. parse_str(
  996. parse_url(
  997. $this->fuckhtml
  998. ->getTextContent(
  999. $imagedata["attributes"]["href"]
  1000. ),
  1001. PHP_URL_QUERY
  1002. ),
  1003. $params
  1004. );
  1005. $image =
  1006. $this->fuckhtml
  1007. ->getElementsByTagName("img")[0];
  1008. if(isset($this->js_image[$image["attributes"]["id"]])){
  1009. $thumbimg = $this->getimage($image["attributes"]["id"]);
  1010. }else{
  1011. $thumbimg =
  1012. $this->fuckhtml
  1013. ->getTextContent(
  1014. $image["attributes"]["src"]
  1015. );
  1016. }
  1017. $out["image"][] = [
  1018. "title" =>
  1019. $this->titledots(
  1020. $this->fuckhtml
  1021. ->getTextContent(
  1022. $image["attributes"]["alt"]
  1023. )
  1024. ),
  1025. "source" => [
  1026. [
  1027. "url" => $params["imgurl"],
  1028. "width" => (int)$params["w"],
  1029. "height" => (int)$params["h"]
  1030. ],
  1031. [
  1032. "url" => $thumbimg,
  1033. "width" => (int)$params["tbnw"],
  1034. "height" => (int)$params["tbnh"]
  1035. ]
  1036. ],
  1037. "url" => $params["imgrefurl"]
  1038. ];
  1039. break;
  1040. }
  1041. }else{
  1042. /*
  1043. Is a web node (twitter-like)
  1044. create a link -> sublink structure and
  1045. ignore images
  1046. */
  1047. switch(count($grey_node)){
  1048. case 0:
  1049. continue 2;
  1050. case 1:
  1051. $sublink_title = $grey_node[0];
  1052. $sublink_description = null;
  1053. break;
  1054. case 2:
  1055. $sublink_title = $grey_node[1];
  1056. $sublink_description =
  1057. $this->titledots(
  1058. $this->fuckhtml
  1059. ->getTextContent(
  1060. $grey_node[0]
  1061. )
  1062. );
  1063. break;
  1064. }
  1065. $sublink_url =
  1066. $this->decodeurl(
  1067. $this->fuckhtml
  1068. ->getTextContent(
  1069. $this->fuckhtml
  1070. ->getElementsByTagName(
  1071. "a"
  1072. )[0]
  1073. ["attributes"]
  1074. ["href"]
  1075. )
  1076. );
  1077. if($link == $sublink_url){
  1078. continue;
  1079. }
  1080. $sublink_title =
  1081. explode(
  1082. " • ",
  1083. $this->fuckhtml
  1084. ->getTextContent(
  1085. $sublink_title["innerHTML"]
  1086. )
  1087. );
  1088. if(count($sublink_title) !== 1){
  1089. $date = strtotime($sublink_title[1]);
  1090. }else{
  1091. $date = null;
  1092. }
  1093. $sublink_title = $this->titledots($sublink_title[0]);
  1094. $sublink[] = [
  1095. "title" => $sublink_title,
  1096. "date" => $date,
  1097. "description" => $sublink_description,
  1098. "url" => $sublink_url
  1099. ];
  1100. }
  1101. }
  1102. // if it was a web node
  1103. if(count($sublink) !== 0){
  1104. $out["web"][] = [
  1105. "title" =>
  1106. $this->titledots(
  1107. $this->fuckhtml
  1108. ->getTextContent(
  1109. $title[0]
  1110. )
  1111. ),
  1112. "description" => null,
  1113. "url" => $url,
  1114. "date" => null,
  1115. "type" => "web",
  1116. "thumb" => [
  1117. "url" => null,
  1118. "ratio" => null
  1119. ],
  1120. "sublink" => $sublink,
  1121. "table" => []
  1122. ];
  1123. }
  1124. continue;
  1125. }
  1126. $people_title =
  1127. $this->fuckhtml
  1128. ->getElementsByClassName(
  1129. $this->findstyles(
  1130. [
  1131. "font-weight" => "bold",
  1132. "font-size" => "16px",
  1133. "color" => "#000",
  1134. "margin" => "0",
  1135. "padding" => "12px 16px 0 16px"
  1136. ],
  1137. self::is_class
  1138. ),
  1139. "div"
  1140. );
  1141. if(
  1142. count($people_title) !== 0 &&
  1143. strtolower(
  1144. $this->fuckhtml
  1145. ->getTextContent(
  1146. $people_title[0]
  1147. )
  1148. ) == "people also ask"
  1149. ){
  1150. /*
  1151. Parse "people also ask" node
  1152. */
  1153. $div =
  1154. $this->fuckhtml
  1155. ->getElementsByTagName("div");
  1156. // add suggestions
  1157. $suggestions =
  1158. $this->fuckhtml
  1159. ->getElementsByClassName(
  1160. $this->findstyles(
  1161. [
  1162. "display" => "inline-block",
  1163. "padding-right" => "26px"
  1164. ],
  1165. self::is_class
  1166. ),
  1167. $div
  1168. );
  1169. foreach($suggestions as $suggestion){
  1170. $out["related"][] =
  1171. $this->fuckhtml
  1172. ->getTextContent($suggestion);
  1173. }
  1174. // parse websites
  1175. foreach($div as $d){
  1176. if(
  1177. isset($d["attributes"]["id"]) &&
  1178. strpos(
  1179. $d["attributes"]["id"],
  1180. "accdef_"
  1181. ) !== false
  1182. ){
  1183. $this->fuckhtml->load(
  1184. $this->ask[
  1185. $d["attributes"]["id"]
  1186. ]
  1187. );
  1188. $description =
  1189. $this->titledots(
  1190. $this->fuckhtml
  1191. ->getTextContent(
  1192. $this->fuckhtml
  1193. ->getElementsByClassName(
  1194. $this->findstyles(
  1195. [
  1196. "white-space" => "pre-line",
  1197. "word-wrap" => "break-word"
  1198. ],
  1199. self::is_class
  1200. ),
  1201. "div"
  1202. )[0]
  1203. )
  1204. );
  1205. $a =
  1206. $this->fuckhtml
  1207. ->getElementsByTagName("a")
  1208. [0];
  1209. $this->fuckhtml->load($a);
  1210. $out["web"][] = [
  1211. "title" =>
  1212. $this->titledots(
  1213. $this->fuckhtml
  1214. ->getTextContent(
  1215. $this->fuckhtml
  1216. ->getElementsByTagName("span")[0]
  1217. )
  1218. ),
  1219. "description" => $description,
  1220. "url" =>
  1221. $this->decodeurl(
  1222. $this->fuckhtml
  1223. ->getTextContent(
  1224. $a
  1225. ["attributes"]
  1226. ["href"]
  1227. )
  1228. ),
  1229. "date" => null,
  1230. "type" => "web",
  1231. "thumb" => [
  1232. "url" => null,
  1233. "ratio" => null
  1234. ],
  1235. "sublink" => [],
  1236. "table" => []
  1237. ];
  1238. }
  1239. }
  1240. continue;
  1241. }
  1242. if(count($title) !== 0){
  1243. /*
  1244. Get WEB search results
  1245. */
  1246. $thumb =
  1247. $this->fuckhtml
  1248. ->getElementsByTagName("img");
  1249. if(
  1250. count($thumb) !== 0 &&
  1251. isset($this->js_image[$thumb[0]["attributes"]["id"]])
  1252. ){
  1253. $thumb = [
  1254. "url" => $this->getimage($thumb[0]["attributes"]["id"]),
  1255. "ratio" => "1:1"
  1256. ];
  1257. if(parse_url($thumb["url"], PHP_URL_HOST) == "i.ytimg.com"){
  1258. $thumb = [
  1259. "url" =>
  1260. str_replace(
  1261. "default.jpg",
  1262. "maxresdefault.jpg",
  1263. $thumb["url"]
  1264. ),
  1265. "ratio" => "16:9"
  1266. ];
  1267. }
  1268. }else{
  1269. $thumb = [
  1270. "url" => null,
  1271. "ratio" => null
  1272. ];
  1273. }
  1274. // this contains description, sublinks
  1275. $inner_category =
  1276. $this->fuckhtml
  1277. ->getElementsByClassName(
  1278. $this->findstyles(
  1279. [
  1280. "white-space" => "pre-line",
  1281. "word-wrap" => "break-word"
  1282. ],
  1283. self::is_class
  1284. ),
  1285. "div"
  1286. );
  1287. // set empty values
  1288. $description = null;
  1289. $table = [];
  1290. $sublinks = [];
  1291. $date = null;
  1292. foreach($inner_category as $category){
  1293. if($category["level"] !== 6){
  1294. // enterring protocol 6
  1295. // and u dont seem to understaaaaandddddd
  1296. continue;
  1297. }
  1298. $this->fuckhtml->load($category);
  1299. // check if its a table
  1300. preg_match(
  1301. '/^[A-z0-9 ]+: <span/',
  1302. $category["innerHTML"],
  1303. $tablematch
  1304. );
  1305. if(count($tablematch) !== 0){
  1306. $categories = explode("<br>", $category["innerHTML"]);
  1307. foreach($categories as $cat){
  1308. $container["innerHTML"] = str_replace($cat, "", $container["innerHTML"]);
  1309. $cat = explode(":", $cat, 2);
  1310. $name =
  1311. $this->fuckhtml
  1312. ->getTextContent(
  1313. $cat[0]
  1314. );
  1315. if(strtolower($name) != "posted"){
  1316. $table[$name] =
  1317. $this->titledots(
  1318. $this->fuckhtml
  1319. ->getTextContent(
  1320. $cat[1]
  1321. )
  1322. );
  1323. }else{
  1324. $date =
  1325. strtotime(
  1326. $this->titledots(
  1327. $this->fuckhtml
  1328. ->getTextContent(
  1329. $cat[1]
  1330. )
  1331. )
  1332. );
  1333. }
  1334. }
  1335. continue;
  1336. }
  1337. $spans =
  1338. $this->fuckhtml
  1339. ->getElementsByTagName("span");
  1340. $encounter_rating = false;
  1341. foreach($spans as $span){
  1342. // replace element with nothing
  1343. if(empty($description)){
  1344. $category["innerHTML"] =
  1345. str_replace(
  1346. $span["outerHTML"],
  1347. "",
  1348. $category["innerHTML"]
  1349. );
  1350. }
  1351. if($encounter_rating !== false){
  1352. switch($encounter_rating){
  1353. case 3:
  1354. $table["Votes"] =
  1355. number_format(
  1356. str_replace(
  1357. [
  1358. "(",
  1359. ")",
  1360. ","
  1361. ],
  1362. "",
  1363. $this->fuckhtml
  1364. ->getTextContent(
  1365. $span["innerHTML"]
  1366. )
  1367. )
  1368. );
  1369. break;
  1370. case 6:
  1371. $table["Price"] =
  1372. $this->fuckhtml
  1373. ->getTextContent(
  1374. $span["innerHTML"]
  1375. );
  1376. break;
  1377. case 8:
  1378. $table["Support"] =
  1379. $this->fuckhtml
  1380. ->getTextContent(
  1381. $span["innerHTML"]
  1382. );
  1383. break;
  1384. }
  1385. $encounter_rating++;
  1386. }
  1387. // get rating
  1388. if(isset($span["attributes"]["aria-hidden"])){
  1389. $table["Rating"] = $span["innerHTML"];
  1390. $encounter_rating = 0;
  1391. continue;
  1392. }
  1393. }
  1394. if(empty($description)){
  1395. $description =
  1396. $this->titledots(
  1397. $this->fuckhtml
  1398. ->getTextContent(
  1399. $category
  1400. )
  1401. );
  1402. }
  1403. }
  1404. // get sublinks
  1405. $this->fuckhtml->load($container["innerHTML"]);
  1406. $as =
  1407. $this->fuckhtml->getElementsByTagName("a");
  1408. foreach($as as $a){
  1409. $this->fuckhtml->load($a);
  1410. $detect =
  1411. $this->fuckhtml
  1412. ->getElementsByClassName(
  1413. $this->findstyles(
  1414. [
  1415. "color" => "#1967d2",
  1416. "font-size" => "14px",
  1417. "line-height" => "20px"
  1418. ],
  1419. self::is_class
  1420. ),
  1421. "span"
  1422. );
  1423. if(count($detect) !== 0){
  1424. $sublinks[] = [
  1425. "title" =>
  1426. $this->titledots(
  1427. $this->fuckhtml
  1428. ->getTextContent(
  1429. $a
  1430. )
  1431. ),
  1432. "date" => null,
  1433. "description" => null,
  1434. "url" =>
  1435. $this->decodeurl(
  1436. $a["attributes"]["href"]
  1437. )
  1438. ];
  1439. }
  1440. }
  1441. $data = [
  1442. "title" =>
  1443. $this->titledots(
  1444. $this->fuckhtml
  1445. ->getTextContent(
  1446. $title[0]
  1447. )
  1448. ),
  1449. "description" => $description,
  1450. "url" => $link,
  1451. "date" => $date,
  1452. "type" => "web",
  1453. "thumb" => $thumb,
  1454. "sublink" => $sublinks,
  1455. "table" => $table
  1456. ];
  1457. $out["web"][] = $data;
  1458. continue;
  1459. }
  1460. /*
  1461. Check related searches node
  1462. */
  1463. $relateds =
  1464. $this->fuckhtml
  1465. ->getElementsByClassName(
  1466. $this->findstyles(
  1467. [
  1468. "display" => "block",
  1469. "position" => "relative",
  1470. "width" => "100%"
  1471. ],
  1472. self::is_class
  1473. ),
  1474. "a"
  1475. );
  1476. if(count($relateds) !== 0){
  1477. foreach($relateds as $related){
  1478. $out["related"][] =
  1479. $this->fuckhtml
  1480. ->getTextContent(
  1481. $related
  1482. );
  1483. }
  1484. continue;
  1485. }
  1486. /*
  1487. Check for spelling autocorrect
  1488. */
  1489. $spelling =
  1490. $this->fuckhtml
  1491. ->getElementById(
  1492. "scl"
  1493. );
  1494. if($spelling){
  1495. $out["spelling"] = [
  1496. "type" => "including",
  1497. "using" =>
  1498. $this->fuckhtml
  1499. ->getTextContent(
  1500. $spelling
  1501. ),
  1502. "correction" => $search
  1503. ];
  1504. }
  1505. /*
  1506. Get next page
  1507. */
  1508. $nextpage =
  1509. $this->fuckhtml
  1510. ->getElementsByClassName(
  1511. $this->findstyles(
  1512. [
  1513. "-webkit-box-flex" => "1",
  1514. "display" => "block"
  1515. ],
  1516. self::is_class
  1517. ),
  1518. "a"
  1519. );
  1520. if(count($nextpage) !== 0){
  1521. $out["npt"] =
  1522. $this->nextpage
  1523. ->store(
  1524. explode(
  1525. "?",
  1526. $this->fuckhtml
  1527. ->getTextContent(
  1528. $nextpage[0]
  1529. ["attributes"]
  1530. ["href"]
  1531. )
  1532. )[1],
  1533. "web"
  1534. );
  1535. continue;
  1536. }
  1537. /*
  1538. Check for DMCA complaint div
  1539. */
  1540. $dmca_table = false;
  1541. $text =
  1542. $this->fuckhtml
  1543. ->getTextContent($container);
  1544. if(
  1545. stripos(
  1546. $text,
  1547. "In response to a complaint we received under the US Digital Millennium Copyright Act, we have removed"
  1548. ) !== false
  1549. ||
  1550. stripos(
  1551. $text,
  1552. "In response to multiple complaints we received under the US Digital Millennium Copyright Act, we have removed"
  1553. ) !== false
  1554. ){
  1555. $as =
  1556. $this->fuckhtml
  1557. ->getElementsByTagName("a");
  1558. array_shift($as);
  1559. $dmca_table = [
  1560. "title" => "Removed results",
  1561. "description" => [
  1562. [
  1563. "type" => "text",
  1564. "value" => "Google removed results due to DMCA complaints. You can view the removed links by visiting these:\n\n"
  1565. ]
  1566. ],
  1567. "url" => "https://support.google.com/legal/answer/1120734?visit_id=638260070062978894-2242290953",
  1568. "thumb" => null,
  1569. "table" => [],
  1570. "sublink" => []
  1571. ];
  1572. $i = 0;
  1573. $c = count($as);
  1574. foreach($as as $a){
  1575. $i++;
  1576. $u =
  1577. $this->decodeurl(
  1578. $a["attributes"]["href"]
  1579. );
  1580. $dmca_table["description"][] = [
  1581. "type" => "link",
  1582. "url" => $u,
  1583. "value" => $u
  1584. ];
  1585. if($i !== $c){
  1586. $dmca_table["description"][] = [
  1587. "type" => "text",
  1588. "value" => "\n"
  1589. ];
  1590. }
  1591. }
  1592. continue;
  1593. }
  1594. /*
  1595. Parse instant answers with parts
  1596. */
  1597. $parts =
  1598. $this->fuckhtml
  1599. ->getElementsByClassName(
  1600. $this->findstyles(
  1601. [
  1602. "padding" => "12px 16px 12px"
  1603. ],
  1604. self::is_class
  1605. ),
  1606. "div"
  1607. );
  1608. if(count($parts) !== 0){
  1609. $table = [
  1610. "title" => null,
  1611. "description" => [],
  1612. "url" => null,
  1613. "thumb" => null,
  1614. "table" => [],
  1615. "sublink" => []
  1616. ];
  1617. // get thumb
  1618. $thumb =
  1619. $this->fuckhtml
  1620. ->getElementsByClassName(
  1621. $this->findstyles(
  1622. [
  1623. "float" => "right",
  1624. "padding-left" => "16px"
  1625. ],
  1626. self::is_class
  1627. ),
  1628. "div"
  1629. );
  1630. if(count($thumb) !== 0){
  1631. $this->fuckhtml->load($thumb[0]);
  1632. $img =
  1633. $this->fuckhtml
  1634. ->getElementsByTagName("img");
  1635. if(count($img) !== 0){
  1636. $table["thumb"] =
  1637. $this->getimage(
  1638. $img[0]["attributes"]["id"]
  1639. );
  1640. }
  1641. $this->fuckhtml->load($container);
  1642. }
  1643. $h =
  1644. $this->fuckhtml
  1645. ->getElementsByTagName("h3");
  1646. if(count($h) === 0){
  1647. $h =
  1648. $this->fuckhtml
  1649. ->getElementsByTagName("h2");
  1650. }
  1651. if(count($h) !== 0){
  1652. // set title + subtext for when a word definition
  1653. // appears
  1654. $h = $h[0];
  1655. $table["title"] =
  1656. $this->fuckhtml
  1657. ->getTextContent(
  1658. $h
  1659. );
  1660. $parts[0]["innerHTML"] =
  1661. str_replace(
  1662. $h["outerHTML"],
  1663. "",
  1664. $parts[0]["innerHTML"]
  1665. );
  1666. $table["description"][] =
  1667. [
  1668. "type" => "quote",
  1669. "value" =>
  1670. $this->fuckhtml
  1671. ->getTextContent(
  1672. $parts[0]
  1673. )
  1674. ];
  1675. }else{
  1676. // parse it as a wikipedia header
  1677. }
  1678. // get table elements
  1679. $tables =
  1680. $this->fuckhtml
  1681. ->getElementsByClassName(
  1682. $this->findstyles(
  1683. [
  1684. "display" => "table",
  1685. "width" => "100%",
  1686. "padding-right" => "16px",
  1687. "-webkit-box-sizing" => "border-box"
  1688. ],
  1689. self::is_class
  1690. ),
  1691. "div"
  1692. );
  1693. foreach($tables as $tbl){
  1694. $this->fuckhtml->load($tbl);
  1695. $images =
  1696. $this->fuckhtml
  1697. ->getElementsByTagName("img");
  1698. if(count($images) !== 0){
  1699. $image = $this->getimage($images[0]["attributes"]["id"]);
  1700. $text =
  1701. $this->fuckhtml
  1702. ->getTextContent(
  1703. $tbl
  1704. );
  1705. $table["description"][] = [
  1706. "type" => "link",
  1707. "value" => $text,
  1708. "url" => "?s=" . urlencode($text) . "&scraper=google"
  1709. ];
  1710. $table["description"][] = [
  1711. "type" => "image",
  1712. "url" => $image
  1713. ];
  1714. }
  1715. }
  1716. $audio =
  1717. $this->fuckhtml
  1718. ->getElementsByTagName("audio");
  1719. if(count($audio) !== 0){
  1720. $table["description"][] = [
  1721. "type" => "audio",
  1722. "url" =>
  1723. str_replace(
  1724. "http://",
  1725. "https://",
  1726. $this->fuckhtml
  1727. ->getTextContent(
  1728. $audio[0]["attributes"]["src"]
  1729. )
  1730. )
  1731. ];
  1732. }
  1733. if(count($parts) >= 2){
  1734. $this->fuckhtml->load($parts[1]);
  1735. $parts =
  1736. $this->fuckhtml
  1737. ->getElementsByClassName(
  1738. $this->findstyles(
  1739. [
  1740. "padding-bottom" => "12px"
  1741. ],
  1742. self::is_class
  1743. ),
  1744. "div"
  1745. );
  1746. foreach($parts as $part){
  1747. $this->fuckhtml->load($part);
  1748. $lists =
  1749. $this->fuckhtml
  1750. ->getElementsByTagName("ol");
  1751. if(count($lists) !== 0){
  1752. foreach($lists as $list){
  1753. $this->fuckhtml->load($list);
  1754. $list_items =
  1755. $this->fuckhtml
  1756. ->getElementsByTagName("li");
  1757. $index = 0;
  1758. if(count($list_items) !== 0){
  1759. foreach($list_items as $list_item){
  1760. $index++;
  1761. $this->fuckhtml->load($list_item);
  1762. $list_subitems =
  1763. $this->fuckhtml
  1764. ->getElementsByTagName("div");
  1765. foreach($list_subitems as $subitem){
  1766. if($subitem["level"] !== 1){ continue; }
  1767. $this->fuckhtml->load($subitem);
  1768. $spans =
  1769. $this->fuckhtml
  1770. ->getElementsByTagName("span");
  1771. if(count($spans) !== 0){
  1772. $type = "quote";
  1773. }else{
  1774. $type = "text";
  1775. }
  1776. $value =
  1777. $this->fuckhtml
  1778. ->getTextContent(
  1779. $subitem
  1780. );
  1781. if($type == "text"){
  1782. $value = $index . ". " . $value;
  1783. }
  1784. $table["description"][] = [
  1785. "type" => $type,
  1786. "value" => $value
  1787. ];
  1788. }
  1789. }
  1790. }
  1791. }
  1792. continue;
  1793. }
  1794. // get title
  1795. $spans =
  1796. $this->fuckhtml
  1797. ->getElementsByTagName("span");
  1798. if(count($spans) !== 0){
  1799. foreach($spans as $span){
  1800. $part["innerHTML"] =
  1801. str_replace(
  1802. $span["outerHTML"],
  1803. "",
  1804. $part["innerHTML"]
  1805. );
  1806. }
  1807. if(
  1808. $this->fuckhtml
  1809. ->getTextContent(
  1810. $part
  1811. )
  1812. == ""
  1813. ){
  1814. $table["description"][] = [
  1815. "type" => "title",
  1816. "value" =>
  1817. $this->fuckhtml
  1818. ->getTextContent(
  1819. $spans[0]
  1820. )
  1821. ];
  1822. continue;
  1823. }
  1824. }
  1825. // fallback to getting non-numbered list
  1826. $nlist =
  1827. $this->fuckhtml
  1828. ->getElementsByClassName(
  1829. $this->findstyles(
  1830. [
  1831. "white-space" => "pre-line",
  1832. "word-wrap" => "break-word"
  1833. ],
  1834. self::is_class
  1835. ),
  1836. "div"
  1837. );
  1838. if(count($nlist) !== 0){
  1839. foreach($nlist as $nlist_item){
  1840. $text =
  1841. $this->fuckhtml
  1842. ->getTextContent($nlist_item);
  1843. if($text == ""){
  1844. continue;
  1845. }
  1846. $this->fuckhtml->load($nlist_item);
  1847. $spans =
  1848. $this->fuckhtml
  1849. ->getElementsByTagName("span");
  1850. if(count($spans) !== 0){
  1851. // is a quote node
  1852. $type = "quote";
  1853. }else{
  1854. $type = "text";
  1855. }
  1856. $table["description"][] = [
  1857. "type" => $type,
  1858. "value" => $text
  1859. ];
  1860. }
  1861. }
  1862. }
  1863. }
  1864. $out["answer"][] = $table;
  1865. }
  1866. }
  1867. if($dmca_table){
  1868. $out["answer"][] = $dmca_table;
  1869. }
  1870. return $out;
  1871. }
  1872. public function image($get){
  1873. $search = $get["s"];
  1874. $country = $get["country"];
  1875. $nsfw = $get["nsfw"];
  1876. $lang = $get["lang"];
  1877. $size = $get["size"];
  1878. $colortype = $get["colortype"];
  1879. $color = $get["color"];
  1880. $type = $get["type"];
  1881. $rights = $get["rights"];
  1882. $older = $get["older"];
  1883. $newer = $get["newer"];
  1884. $params = [];
  1885. // country
  1886. if($country != "any"){
  1887. $params["gl"] = $country;
  1888. }
  1889. // nsfw
  1890. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  1891. // language
  1892. if($lang != "any"){
  1893. $params["lr"] = "lang_" . $lang;
  1894. }
  1895. // &sort=review-date:r:20090301:20090430
  1896. $older = $older === false ? false : date("Ymd", $older);
  1897. $newer = $newer === false ? false : date("Ymd", $newer);
  1898. if(
  1899. $older !== false &&
  1900. $newer === false
  1901. ){
  1902. $newer = date("Ymd", time());
  1903. }
  1904. if(
  1905. $older !== false ||
  1906. $newer !== false
  1907. ){
  1908. $params["sort"] = "review-date:r:" . $older . ":" . $newer;
  1909. }
  1910. $handle = fopen("scraper/google-img.html", "r");
  1911. $html = fread($handle, filesize("scraper/google-img.html"));
  1912. fclose($handle);
  1913. $this->fuckhtml->load($html);
  1914. $out = [
  1915. "status" => "ok",
  1916. "npt" => null,
  1917. "image" => []
  1918. ];
  1919. $images =
  1920. $this->fuckhtml
  1921. ->getElementsByClassName(
  1922. "islrtb isv-r",
  1923. "div"
  1924. );
  1925. // get next page
  1926. // https://www.google.com/search
  1927. // ?q=higurashi
  1928. // &tbm=isch
  1929. // &async=_id%3Aislrg_c%2C_fmt%3Ahtml
  1930. // &asearch=ichunklite
  1931. // &ved=0ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA
  1932. $ved =
  1933. $this->fuckhtml
  1934. ->getElementById("islrg", "div");
  1935. if($ved){
  1936. $ved =
  1937. $this->fuckhtml
  1938. ->getTextContent(
  1939. $ved["attributes"]["data-ved"]
  1940. );
  1941. // &vet=1{$ved}..i (10ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA..i)
  1942. /*
  1943. These 2 are handled by us
  1944. start = start + number of results
  1945. ijn = current page number
  1946. */
  1947. // &start=100
  1948. // &ijn=1
  1949. // &imgvl=CAEY7gQgBSj3Aji8VTjXVUC4AUC3AUgAYNdV
  1950. preg_match(
  1951. '/var e=\'([A-z0-9]+)\';/',
  1952. $html,
  1953. $imgvl
  1954. );
  1955. $imgvl = $imgvl[1];
  1956. $out["npt"] =
  1957. $this->nextpage->store(
  1958. json_encode(
  1959. [
  1960. "q" => $get["s"],
  1961. "tbm" => "isch",
  1962. "async" => "_id:islrg_c,_fmt:html",
  1963. "asearch" => "ichunklite",
  1964. "ved" => $ved,
  1965. "vet" => "1" . $ved . "..i",
  1966. "start" => 100,
  1967. "ijn" => 1,
  1968. "imgvl" => $imgvl
  1969. ]
  1970. ),
  1971. "images"
  1972. );
  1973. }
  1974. foreach($images as $image){
  1975. $this->fuckhtml->load($image);
  1976. $img =
  1977. $this->fuckhtml
  1978. ->getElementsByTagName("img")[0];
  1979. $og_width = (int)$image["attributes"]["data-ow"];
  1980. $og_height = (int)$image["attributes"]["data-oh"];
  1981. $thumb_width = (int)$image["attributes"]["data-tw"];
  1982. $ratio = $og_width / $og_height;
  1983. if(isset($img["attributes"]["data-src"])){
  1984. $src = &$img["attributes"]["data-src"];
  1985. }else{
  1986. $src = &$img["attributes"]["src"];
  1987. }
  1988. $thumb_height = floor($thumb_width / $ratio);
  1989. $out["image"][] = [
  1990. "title" =>
  1991. $this->titledots(
  1992. $this->fuckhtml
  1993. ->getTextContent(
  1994. $image["attributes"]["data-pt"]
  1995. )
  1996. ),
  1997. "source" => [
  1998. [
  1999. "url" =>
  2000. $this->fuckhtml
  2001. ->getTextContent(
  2002. $image["attributes"]["data-ou"]
  2003. ),
  2004. "width" => $og_width,
  2005. "height" => $og_height
  2006. ],
  2007. [
  2008. "url" =>
  2009. $this->fuckhtml
  2010. ->getTextContent(
  2011. $src
  2012. ),
  2013. "width" => $thumb_width,
  2014. "height" => $thumb_height
  2015. ]
  2016. ],
  2017. "url" =>
  2018. $this->fuckhtml
  2019. ->getTextContent(
  2020. $image["attributes"]["data-ru"]
  2021. )
  2022. ];
  2023. }
  2024. return $out;
  2025. }
  2026. private function findstyles($rules, $is){
  2027. ksort($rules);
  2028. foreach($this->computedstyle as $stylename => $styles){
  2029. if($styles == $rules){
  2030. preg_match(
  2031. '/\\' . $is . '([^ .]+)/',
  2032. $stylename,
  2033. $out
  2034. );
  2035. if(count($out) === 2){
  2036. return $out[1];
  2037. }
  2038. return false;
  2039. }
  2040. }
  2041. return false;
  2042. }
  2043. private function parsestyles($style){
  2044. // get style tags
  2045. preg_match_all(
  2046. '/([^{]+){([^}]+)}/',
  2047. $style,
  2048. $tags_regex
  2049. );
  2050. $tags = [];
  2051. for($i=0; $i<count($tags_regex[0]); $i++){
  2052. $tagnames = explode(",", trim($tags_regex[1][$i]));
  2053. foreach($tagnames as $tagname){
  2054. $tagname = trim($tagname);
  2055. if(!isset($tags[$tagname])){
  2056. $tags[$tagname] = [];
  2057. }
  2058. $values = explode(";", $tags_regex[2][$i]);
  2059. foreach($values as $value){
  2060. $value = explode(":", $value, 2);
  2061. if(count($value) !== 2){
  2062. continue;
  2063. }
  2064. $tags[$tagname][trim($value[0])] =
  2065. trim($value[1]);
  2066. }
  2067. }
  2068. }
  2069. foreach($tags as &$value){
  2070. ksort($value);
  2071. }
  2072. return $tags;
  2073. }
  2074. private function getimage($id){
  2075. if(
  2076. isset($this->js_image[$id]) &&
  2077. $this->js_image[$id] != "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABAUlEQVR4AWMYesChoYElLjkzPj4lY3d8csZjIL4MxPNjUzPcSTYsISFLAqj5NBD/h+LPQPwbiT87NCuLh2gDgRr2QzXuT0jNMoBYksARn5zuHJ+UcR0kB6RXE2VYXHJGOlTDZmzyIJcB5e+D1CSkZDgQNBAaZv+jU1JkcKpJygiGeZ0I76a/Byq8jU9NZFqaCNTA48SE33/iDcw8TIyBt0GKQTFN0Msp6f2EIyUpo57YSIlLSrMhIg0WCIBcCfXSdlzJBsheTHQ6jEnOUgEFOLaEDbMIlhZBOYrorAdJk+nroVnvPsSgdGdoOF7HZyhZ2XPoGQoqjbCpIbt0AiejIQMArVLI7k/DXFkAAAAASUVORK5CYII="
  2078. ){
  2079. if(stripos($this->js_image[$id], "data:image") !== false){
  2080. return
  2081. explode(
  2082. "\\x3d",
  2083. $this->js_image[$id],
  2084. 2
  2085. )[0];
  2086. }
  2087. return $this->js_image[$id];
  2088. }
  2089. return null;
  2090. }
  2091. private function decodeurl($url){
  2092. preg_match(
  2093. '/^\/url\?q=([^&]+)|^\/interstitial\?url=([^&]+)/',
  2094. $this->fuckhtml
  2095. ->getTextContent($url),
  2096. $match
  2097. );
  2098. if(count($match) === 0){
  2099. return null;
  2100. }
  2101. $url = empty($match[1]) ? urldecode($match[2]) : urldecode($match[1]);
  2102. $domain = parse_url($url, PHP_URL_HOST);
  2103. if(
  2104. preg_match(
  2105. '/wikipedia.org$/',
  2106. $domain
  2107. )
  2108. ){
  2109. // rewrite wikipedia mobile URLs to desktop
  2110. $url =
  2111. $this->replacedomain(
  2112. $url,
  2113. preg_replace(
  2114. '/([a-z0-9]+)(\.m\.)/',
  2115. '$1.',
  2116. $domain
  2117. )
  2118. );
  2119. }
  2120. if(
  2121. preg_match(
  2122. '/imdb\.com$|youtube\.[^.]+$/',
  2123. $domain
  2124. )
  2125. ){
  2126. // rewrite imdb and youtube mobile URLs too
  2127. $url =
  2128. $this->replacedomain(
  2129. $url,
  2130. preg_replace(
  2131. '/^m\./',
  2132. "",
  2133. $domain
  2134. )
  2135. );
  2136. }
  2137. return $url;
  2138. }
  2139. private function replacedomain($url, $domain){
  2140. return
  2141. preg_replace(
  2142. '/(https?:\/\/)([^\/]+)/',
  2143. '$1' . $domain,
  2144. $url
  2145. );
  2146. }
  2147. private function titledots($title){
  2148. return rtrim($title, ".… \t\n\r\0\x0B");
  2149. }
  2150. }