google.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159
  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. foreach($styles as $style){
  774. $this->computedstyle =
  775. array_merge(
  776. $this->computedstyle,
  777. $this->parsestyles($style["innerHTML"])
  778. );
  779. }
  780. // get images in javascript var
  781. preg_match(
  782. '/google\.ldi=({[^}]+})/',
  783. $html,
  784. $this->js_image
  785. );
  786. if(count($this->js_image) !== 0){
  787. $this->js_image = json_decode($this->js_image[1], true);
  788. }else{
  789. $this->js_image = [];
  790. }
  791. // additional js_images present in <script> tags
  792. // ugh i fucking hate you
  793. $scripts =
  794. $this->fuckhtml
  795. ->getElementsByTagName("script");
  796. foreach($scripts as $script){
  797. if(!isset($script["innerHTML"])){
  798. continue;
  799. }
  800. preg_match_all(
  801. '/var s=\'(data:image[^\']+)\';var i=\[\'([^\']+)\'];/',
  802. $script["innerHTML"],
  803. $image_grep
  804. );
  805. if(count($image_grep[0]) !== 0){
  806. $this->js_image[trim($image_grep[2][0])] =
  807. $this->fuckhtml
  808. ->getTextContent(
  809. $image_grep[1][0]
  810. );
  811. }
  812. }
  813. // get nodes
  814. // fuck you google!!!!!!!!!!!!!!
  815. $containers =
  816. $this->fuckhtml
  817. ->getElementsByClassName(
  818. $this->findstyles(
  819. [
  820. "background-color" => "#fff",
  821. "margin-bottom" => "10px",
  822. "-webkit-box-shadow" => "0 1px 6px rgba(32,33,36,0.28)",
  823. "border-radius" => "8px"
  824. ],
  825. self::is_class
  826. ),
  827. "div"
  828. );
  829. foreach($containers as $container){
  830. $this->fuckhtml->load($container);
  831. // get link at the top
  832. $link =
  833. $this->fuckhtml
  834. ->getElementsByTagName(
  835. "a"
  836. );
  837. if(count($link) !== 0){
  838. $link =
  839. $this->decodeurl(
  840. $link
  841. [0]
  842. ["attributes"]
  843. ["href"]
  844. );
  845. }
  846. /*
  847. Check for carousel presence
  848. */
  849. $carousel =
  850. $this->fuckhtml
  851. ->getElementsByClassName(
  852. "pcitem",
  853. "div"
  854. );
  855. $title =
  856. $this->fuckhtml
  857. ->getElementsByClassName(
  858. $this->findstyles(
  859. [
  860. "color" => "#1967d2",
  861. "font-size" => "20px",
  862. "line-height" => "26px"
  863. ],
  864. self::is_class
  865. ),
  866. "div"
  867. );
  868. $carousel_title =
  869. $this->fuckhtml
  870. ->getElementsByClassName(
  871. $this->findstyles(
  872. [
  873. "font-size" => "16px",
  874. "line-height" => "20px",
  875. "font-weight" => "400"
  876. ],
  877. self::is_class
  878. ),
  879. "div"
  880. );
  881. if(count($carousel) !== 0){
  882. $sublink = []; // twitter carousel sublinks
  883. foreach($carousel as $item){
  884. $this->fuckhtml->load($item);
  885. $url =
  886. $this->decodeurl(
  887. $this->fuckhtml
  888. ->getElementsByTagName(
  889. "a"
  890. )[0]
  891. ["attributes"]
  892. ["href"]
  893. );
  894. // detect if its a twitter carousel or
  895. // a list of news articles
  896. $grey_node =
  897. $this->fuckhtml
  898. ->getElementsByClassName(
  899. $this->findstyles(
  900. [
  901. "white-space" => "pre-line",
  902. "word-wrap" => "break-word"
  903. ],
  904. self::is_class
  905. ),
  906. "div"
  907. );
  908. if(count($carousel_title) !== 0){
  909. switch(
  910. strtolower(
  911. $this->fuckhtml
  912. ->getTextContent(
  913. $carousel_title[0]
  914. )
  915. )
  916. ){
  917. case "top stories":
  918. $img =
  919. $this->fuckhtml
  920. ->getElementsByTagName("img");
  921. if(
  922. count($img) !== 0 &&
  923. isset($img[0]["attributes"]["id"]) &&
  924. isset($this->js_image[$img[0]["attributes"]["id"]])
  925. ){
  926. $img = [
  927. "url" => $this->getimage($img[0]["attributes"]["id"]),
  928. "ratio" => "16:9"
  929. ];
  930. }else{
  931. $img = [
  932. "url" => null,
  933. "ratio" => null
  934. ];
  935. }
  936. /*
  937. Is a news node
  938. */
  939. $out["news"][] = [
  940. "title" =>
  941. $this->fuckhtml
  942. ->getTextContent(
  943. $grey_node[0]
  944. ),
  945. "description" => null,
  946. "date" =>
  947. strtotime(
  948. explode(
  949. "\n",
  950. $grey_node[1]["innerHTML"]
  951. )[1]
  952. ),
  953. "thumb" => $img,
  954. "url" => $url
  955. ];
  956. break;
  957. case "images":
  958. /*
  959. We found an image
  960. */
  961. $imagedata =
  962. $this->fuckhtml
  963. ->getElementsByClassName(
  964. $this->findstyles(
  965. [
  966. "display" => "block",
  967. "background-color" => "#fff",
  968. "border-radius" => "8px",
  969. "-webkit-box-shadow" => "0 1px 6px rgba(32, 33, 36, 0.28)",
  970. "overflow" => "hidden"
  971. ],
  972. self::is_class
  973. ),
  974. "a"
  975. );
  976. if(count($imagedata) === 0){
  977. break;
  978. }
  979. $imagedata = $imagedata[0];
  980. // 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
  981. parse_str(
  982. parse_url(
  983. $this->fuckhtml
  984. ->getTextContent(
  985. $imagedata["attributes"]["href"]
  986. ),
  987. PHP_URL_QUERY
  988. ),
  989. $params
  990. );
  991. $image =
  992. $this->fuckhtml
  993. ->getElementsByTagName("img")[0];
  994. if(isset($this->js_image[$image["attributes"]["id"]])){
  995. $thumbimg = $this->getimage($image["attributes"]["id"]);
  996. }else{
  997. $thumbimg =
  998. $this->fuckhtml
  999. ->getTextContent(
  1000. $image["attributes"]["src"]
  1001. );
  1002. }
  1003. $out["image"][] = [
  1004. "title" =>
  1005. $this->titledots(
  1006. $this->fuckhtml
  1007. ->getTextContent(
  1008. $image["attributes"]["alt"]
  1009. )
  1010. ),
  1011. "source" => [
  1012. [
  1013. "url" => $params["imgurl"],
  1014. "width" => (int)$params["w"],
  1015. "height" => (int)$params["h"]
  1016. ],
  1017. [
  1018. "url" => $thumbimg,
  1019. "width" => (int)$params["tbnw"],
  1020. "height" => (int)$params["tbnh"]
  1021. ]
  1022. ],
  1023. "url" => $params["imgrefurl"]
  1024. ];
  1025. break;
  1026. }
  1027. }else{
  1028. /*
  1029. Is a web node (twitter-like)
  1030. create a link -> sublink structure and
  1031. ignore images
  1032. */
  1033. switch(count($grey_node)){
  1034. case 0:
  1035. continue 2;
  1036. case 1:
  1037. $sublink_title = $grey_node[0];
  1038. $sublink_description = null;
  1039. break;
  1040. case 2:
  1041. $sublink_title = $grey_node[1];
  1042. $sublink_description =
  1043. $this->titledots(
  1044. $this->fuckhtml
  1045. ->getTextContent(
  1046. $grey_node[0]
  1047. )
  1048. );
  1049. break;
  1050. }
  1051. $sublink_url =
  1052. $this->decodeurl(
  1053. $this->fuckhtml
  1054. ->getTextContent(
  1055. $this->fuckhtml
  1056. ->getElementsByTagName(
  1057. "a"
  1058. )[0]
  1059. ["attributes"]
  1060. ["href"]
  1061. )
  1062. );
  1063. if($link == $sublink_url){
  1064. continue;
  1065. }
  1066. $sublink_title =
  1067. explode(
  1068. " • ",
  1069. $this->fuckhtml
  1070. ->getTextContent(
  1071. $sublink_title["innerHTML"]
  1072. )
  1073. );
  1074. if(count($sublink_title) !== 1){
  1075. $date = strtotime($sublink_title[1]);
  1076. }else{
  1077. $date = null;
  1078. }
  1079. $sublink_title = $this->titledots($sublink_title[0]);
  1080. $sublink[] = [
  1081. "title" => $sublink_title,
  1082. "date" => $date,
  1083. "description" => $sublink_description,
  1084. "url" => $sublink_url
  1085. ];
  1086. }
  1087. }
  1088. // if it was a web node
  1089. if(count($sublink) !== 0){
  1090. $out["web"][] = [
  1091. "title" =>
  1092. $this->titledots(
  1093. $this->fuckhtml
  1094. ->getTextContent(
  1095. $title[0]
  1096. )
  1097. ),
  1098. "description" => null,
  1099. "url" => $url,
  1100. "date" => null,
  1101. "type" => "web",
  1102. "thumb" => [
  1103. "url" => null,
  1104. "ratio" => null
  1105. ],
  1106. "sublink" => $sublink,
  1107. "table" => []
  1108. ];
  1109. }
  1110. continue;
  1111. }
  1112. if(count($title) !== 0){
  1113. /*
  1114. Get WEB search results
  1115. */
  1116. $thumb =
  1117. $this->fuckhtml
  1118. ->getElementsByTagName("img");
  1119. if(
  1120. count($thumb) !== 0 &&
  1121. isset($this->js_image[$thumb[0]["attributes"]["id"]])
  1122. ){
  1123. $thumb = [
  1124. "url" => $this->getimage($thumb[0]["attributes"]["id"]),
  1125. "ratio" => "1:1"
  1126. ];
  1127. }else{
  1128. $thumb = [
  1129. "url" => null,
  1130. "ratio" => null
  1131. ];
  1132. }
  1133. // this contains description, sublinks
  1134. $inner_category =
  1135. $this->fuckhtml
  1136. ->getElementsByClassName(
  1137. $this->findstyles(
  1138. [
  1139. "white-space" => "pre-line",
  1140. "word-wrap" => "break-word"
  1141. ],
  1142. self::is_class
  1143. ),
  1144. "div"
  1145. );
  1146. // set empty values
  1147. $description = null;
  1148. $table = [];
  1149. $sublinks = [];
  1150. $date = null;
  1151. foreach($inner_category as $category){
  1152. if($category["level"] !== 6){
  1153. // enterring protocol 6
  1154. // and u dont seem to understaaaaandddddd
  1155. continue;
  1156. }
  1157. $this->fuckhtml->load($category);
  1158. // check if its a table
  1159. preg_match(
  1160. '/^[A-z0-9 ]+: <span/',
  1161. $category["innerHTML"],
  1162. $tablematch
  1163. );
  1164. if(count($tablematch) !== 0){
  1165. $categories = explode("<br>", $category["innerHTML"]);
  1166. foreach($categories as $cat){
  1167. $container["innerHTML"] = str_replace($cat, "", $container["innerHTML"]);
  1168. $cat = explode(":", $cat, 2);
  1169. $table[
  1170. $this->fuckhtml
  1171. ->getTextContent(
  1172. $cat[0]
  1173. )
  1174. ] =
  1175. $this->titledots(
  1176. $this->fuckhtml
  1177. ->getTextContent(
  1178. $cat[1]
  1179. )
  1180. );
  1181. }
  1182. continue;
  1183. }
  1184. $spans =
  1185. $this->fuckhtml
  1186. ->getElementsByTagName("span");
  1187. foreach($spans as $span){
  1188. // replace element with nothing
  1189. if(empty($description)){
  1190. $category["innerHTML"] =
  1191. str_replace(
  1192. $span["outerHTML"],
  1193. "",
  1194. $category["innerHTML"]
  1195. );
  1196. }
  1197. // get rating
  1198. if(isset($span["attributes"]["aria-hidden"])){
  1199. $table["Rating"] = $span["innerHTML"];
  1200. continue;
  1201. }
  1202. }
  1203. if(empty($description)){
  1204. $description =
  1205. $this->titledots(
  1206. $this->fuckhtml
  1207. ->getTextContent(
  1208. $category
  1209. )
  1210. );
  1211. }
  1212. }
  1213. // get sublinks
  1214. $this->fuckhtml->load($container["innerHTML"]);
  1215. $as =
  1216. $this->fuckhtml->getElementsByTagName("a");
  1217. foreach($as as $a){
  1218. $this->fuckhtml->load($a);
  1219. $detect =
  1220. $this->fuckhtml
  1221. ->getElementsByClassName(
  1222. $this->findstyles(
  1223. [
  1224. "color" => "#1967d2",
  1225. "font-size" => "14px",
  1226. "line-height" => "20px"
  1227. ],
  1228. self::is_class
  1229. ),
  1230. "span"
  1231. );
  1232. if(count($detect) !== 0){
  1233. $sublinks[] = [
  1234. "title" =>
  1235. $this->titledots(
  1236. $this->fuckhtml
  1237. ->getTextContent(
  1238. $a
  1239. )
  1240. ),
  1241. "date" => null,
  1242. "description" => null,
  1243. "url" =>
  1244. $this->decodeurl(
  1245. $a["attributes"]["href"]
  1246. )
  1247. ];
  1248. }
  1249. }
  1250. $data = [
  1251. "title" =>
  1252. $this->titledots(
  1253. $this->fuckhtml
  1254. ->getTextContent(
  1255. $title[0]
  1256. )
  1257. ),
  1258. "description" => $description,
  1259. "url" => $link,
  1260. "date" => $date,
  1261. "type" => "web",
  1262. "thumb" => $thumb,
  1263. "sublink" => $sublinks,
  1264. "table" => $table
  1265. ];
  1266. $out["web"][] = $data;
  1267. continue;
  1268. }
  1269. /*
  1270. Check related searches node
  1271. */
  1272. $relateds =
  1273. $this->fuckhtml
  1274. ->getElementsByClassName(
  1275. $this->findstyles(
  1276. [
  1277. "display" => "block",
  1278. "position" => "relative",
  1279. "width" => "100%"
  1280. ],
  1281. self::is_class
  1282. ),
  1283. "a"
  1284. );
  1285. if(count($relateds) !== 0){
  1286. foreach($relateds as $related){
  1287. $out["related"][] =
  1288. $this->fuckhtml
  1289. ->getTextContent(
  1290. $related
  1291. );
  1292. }
  1293. continue;
  1294. }
  1295. /*
  1296. Check for spelling autocorrect
  1297. */
  1298. $spelling =
  1299. $this->fuckhtml
  1300. ->getElementById(
  1301. "scl"
  1302. );
  1303. if($spelling){
  1304. $out["spelling"] = [
  1305. "type" => "including",
  1306. "using" =>
  1307. $this->fuckhtml
  1308. ->getTextContent(
  1309. $spelling
  1310. ),
  1311. "correction" => $search
  1312. ];
  1313. }
  1314. /*
  1315. Get next page
  1316. */
  1317. $nextpage =
  1318. $this->fuckhtml
  1319. ->getElementsByClassName(
  1320. $this->findstyles(
  1321. [
  1322. "-webkit-box-flex" => "1",
  1323. "display" => "block"
  1324. ],
  1325. self::is_class
  1326. ),
  1327. "a"
  1328. );
  1329. if(count($nextpage) !== 0){
  1330. $out["npt"] =
  1331. $this->nextpage
  1332. ->store(
  1333. explode(
  1334. "?",
  1335. $this->fuckhtml
  1336. ->getTextContent(
  1337. $nextpage[0]
  1338. ["attributes"]
  1339. ["href"]
  1340. )
  1341. )[1],
  1342. "web"
  1343. );
  1344. continue;
  1345. }
  1346. /*
  1347. Check for DMCA complaint div
  1348. */
  1349. $dmca_table = false;
  1350. $text =
  1351. $this->fuckhtml
  1352. ->getTextContent($container);
  1353. if(
  1354. stripos(
  1355. $text,
  1356. "In response to a complaint we received under the US Digital Millennium Copyright Act, we have removed"
  1357. ) !== false
  1358. ||
  1359. stripos(
  1360. $text,
  1361. "In response to multiple complaints we received under the US Digital Millennium Copyright Act, we have removed"
  1362. ) !== false
  1363. ){
  1364. $as =
  1365. $this->fuckhtml
  1366. ->getElementsByTagName("a");
  1367. array_shift($as);
  1368. $dmca_table = [
  1369. "title" => "Removed results",
  1370. "description" => [
  1371. [
  1372. "type" => "text",
  1373. "value" => "Google removed results due to DMCA complaints. You can view the removed links by visiting these:\n\n"
  1374. ]
  1375. ],
  1376. "url" => "https://support.google.com/legal/answer/1120734?visit_id=638260070062978894-2242290953",
  1377. "thumb" => null,
  1378. "table" => [],
  1379. "sublink" => []
  1380. ];
  1381. $i = 0;
  1382. $c = count($as);
  1383. foreach($as as $a){
  1384. $i++;
  1385. $u =
  1386. $this->decodeurl(
  1387. $a["attributes"]["href"]
  1388. );
  1389. $dmca_table["description"][] = [
  1390. "type" => "link",
  1391. "url" => $u,
  1392. "value" => $u
  1393. ];
  1394. if($i !== $c){
  1395. $dmca_table["description"][] = [
  1396. "type" => "text",
  1397. "value" => "\n"
  1398. ];
  1399. }
  1400. }
  1401. continue;
  1402. }
  1403. /*
  1404. Detect if its a wikipedia thing
  1405. */
  1406. $h3 =
  1407. $this->fuckhtml
  1408. ->getElementsByTagName("h3");
  1409. /*
  1410. Fallback to parsing the word definitions
  1411. */
  1412. $parts =
  1413. $this->fuckhtml
  1414. ->getElementsByClassName(
  1415. $this->findstyles(
  1416. [
  1417. "padding" => "12px 16px 12px"
  1418. ],
  1419. self::is_class
  1420. ),
  1421. "div"
  1422. );
  1423. if(count($parts) === 0){
  1424. continue;
  1425. }
  1426. $head = $parts[0];
  1427. if(count($h3) !== 0){
  1428. $table = [
  1429. "title" => null,
  1430. "description" => [],
  1431. "url" => null,
  1432. "thumb" => null,
  1433. "table" => [],
  1434. "sublink" => []
  1435. ];
  1436. $h3 = $h3[0];
  1437. $table["title"] =
  1438. $this->fuckhtml
  1439. ->getTextContent(
  1440. $h3
  1441. );
  1442. $head["innerHTML"] =
  1443. str_replace(
  1444. $h3["outerHTML"],
  1445. "",
  1446. $head["innerHTML"]
  1447. );
  1448. $table["description"][] =
  1449. [
  1450. "type" => "quote",
  1451. "value" =>
  1452. $this->fuckhtml
  1453. ->getTextContent(
  1454. $head
  1455. )
  1456. ];
  1457. $audio =
  1458. $this->fuckhtml
  1459. ->getElementsByTagName("audio");
  1460. if(count($audio) !== 0){
  1461. $table["description"][] = [
  1462. "type" => "audio",
  1463. "url" =>
  1464. str_replace(
  1465. "http://",
  1466. "https://",
  1467. $this->fuckhtml
  1468. ->getTextContent(
  1469. $audio[0]["attributes"]["src"]
  1470. )
  1471. )
  1472. ];
  1473. }
  1474. if(count($parts) >= 2){
  1475. $this->fuckhtml->load($parts[1]);
  1476. $parts =
  1477. $this->fuckhtml
  1478. ->getElementsByClassName(
  1479. $this->findstyles(
  1480. [
  1481. "padding-bottom" => "12px"
  1482. ],
  1483. self::is_class
  1484. ),
  1485. "div"
  1486. );
  1487. foreach($parts as $part){
  1488. $this->fuckhtml->load($part);
  1489. $lists =
  1490. $this->fuckhtml
  1491. ->getElementsByTagName("ol");
  1492. if(count($lists) !== 0){
  1493. foreach($lists as $list){
  1494. $this->fuckhtml->load($list);
  1495. $list_items =
  1496. $this->fuckhtml
  1497. ->getElementsByTagName("li");
  1498. $index = 0;
  1499. if(count($list_items) !== 0){
  1500. foreach($list_items as $list_item){
  1501. $index++;
  1502. $this->fuckhtml->load($list_item);
  1503. $list_subitems =
  1504. $this->fuckhtml
  1505. ->getElementsByTagName("div");
  1506. foreach($list_subitems as $subitem){
  1507. if($subitem["level"] !== 1){ continue; }
  1508. $this->fuckhtml->load($subitem);
  1509. $spans =
  1510. $this->fuckhtml
  1511. ->getElementsByTagName("span");
  1512. if(count($spans) !== 0){
  1513. $type = "quote";
  1514. }else{
  1515. $type = "text";
  1516. }
  1517. $value =
  1518. $this->fuckhtml
  1519. ->getTextContent(
  1520. $subitem
  1521. );
  1522. if($type == "text"){
  1523. $value = $index . ". " . $value;
  1524. }
  1525. $table["description"][] = [
  1526. "type" => $type,
  1527. "value" => $value
  1528. ];
  1529. }
  1530. }
  1531. }
  1532. }
  1533. continue;
  1534. }
  1535. // get title
  1536. $spans =
  1537. $this->fuckhtml
  1538. ->getElementsByTagName("span");
  1539. if(count($spans) !== 0){
  1540. foreach($spans as $span){
  1541. $part["innerHTML"] =
  1542. str_replace(
  1543. $span["outerHTML"],
  1544. "",
  1545. $part["innerHTML"]
  1546. );
  1547. }
  1548. if(
  1549. $this->fuckhtml
  1550. ->getTextContent(
  1551. $part
  1552. )
  1553. == ""
  1554. ){
  1555. $table["description"][] = [
  1556. "type" => "title",
  1557. "value" =>
  1558. $this->fuckhtml
  1559. ->getTextContent(
  1560. $spans[0]
  1561. )
  1562. ];
  1563. continue;
  1564. }
  1565. }
  1566. // fallback to getting non-numbered list
  1567. $nlist =
  1568. $this->fuckhtml
  1569. ->getElementsByClassName(
  1570. $this->findstyles(
  1571. [
  1572. "white-space" => "pre-line",
  1573. "word-wrap" => "break-word"
  1574. ],
  1575. self::is_class
  1576. ),
  1577. "div"
  1578. );
  1579. if(count($nlist) !== 0){
  1580. foreach($nlist as $nlist_item){
  1581. $text =
  1582. $this->fuckhtml
  1583. ->getTextContent($nlist_item);
  1584. if($text == ""){
  1585. continue;
  1586. }
  1587. $this->fuckhtml->load($nlist_item);
  1588. $spans =
  1589. $this->fuckhtml
  1590. ->getElementsByTagName("span");
  1591. if(count($spans) !== 0){
  1592. // is a quote node
  1593. $type = "quote";
  1594. }else{
  1595. $type = "text";
  1596. }
  1597. $table["description"][] = [
  1598. "type" => $type,
  1599. "value" => $text
  1600. ];
  1601. }
  1602. }
  1603. }
  1604. }
  1605. }
  1606. $out["answer"][] = $table;
  1607. }
  1608. if($dmca_table){
  1609. $out["answer"][] = $dmca_table;
  1610. }
  1611. return $out;
  1612. }
  1613. public function image($get){
  1614. $search = $get["s"];
  1615. $country = $get["country"];
  1616. $nsfw = $get["nsfw"];
  1617. $lang = $get["lang"];
  1618. $size = $get["size"];
  1619. $colortype = $get["colortype"];
  1620. $color = $get["color"];
  1621. $type = $get["type"];
  1622. $rights = $get["rights"];
  1623. $older = $get["older"];
  1624. $newer = $get["newer"];
  1625. $params = [];
  1626. // country
  1627. if($country != "any"){
  1628. $params["gl"] = $country;
  1629. }
  1630. // nsfw
  1631. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  1632. // language
  1633. if($lang != "any"){
  1634. $params["lr"] = "lang_" . $lang;
  1635. }
  1636. // &sort=review-date:r:20090301:20090430
  1637. $older = $older === false ? false : date("Ymd", $older);
  1638. $newer = $newer === false ? false : date("Ymd", $newer);
  1639. if(
  1640. $older !== false &&
  1641. $newer === false
  1642. ){
  1643. $newer = date("Ymd", time());
  1644. }
  1645. if(
  1646. $older !== false ||
  1647. $newer !== false
  1648. ){
  1649. $params["sort"] = "review-date:r:" . $older . ":" . $newer;
  1650. }
  1651. $handle = fopen("scraper/google-img.html", "r");
  1652. $html = fread($handle, filesize("scraper/google-img.html"));
  1653. fclose($handle);
  1654. $this->fuckhtml->load($html);
  1655. $out = [
  1656. "status" => "ok",
  1657. "npt" => null,
  1658. "image" => []
  1659. ];
  1660. $images =
  1661. $this->fuckhtml
  1662. ->getElementsByClassName(
  1663. "islrtb isv-r",
  1664. "div"
  1665. );
  1666. // get next page
  1667. // https://www.google.com/search
  1668. // ?q=higurashi
  1669. // &tbm=isch
  1670. // &async=_id%3Aislrg_c%2C_fmt%3Ahtml
  1671. // &asearch=ichunklite
  1672. // &ved=0ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA
  1673. $ved =
  1674. $this->fuckhtml
  1675. ->getElementById("islrg", "div");
  1676. if($ved){
  1677. $ved =
  1678. $this->fuckhtml
  1679. ->getTextContent(
  1680. $ved["attributes"]["data-ved"]
  1681. );
  1682. // &vet=1{$ved}..i (10ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA..i)
  1683. /*
  1684. These 2 are handled by us
  1685. start = start + number of results
  1686. ijn = current page number
  1687. */
  1688. // &start=100
  1689. // &ijn=1
  1690. // &imgvl=CAEY7gQgBSj3Aji8VTjXVUC4AUC3AUgAYNdV
  1691. preg_match(
  1692. '/var e=\'([A-z0-9]+)\';/',
  1693. $html,
  1694. $imgvl
  1695. );
  1696. $imgvl = $imgvl[1];
  1697. $out["npt"] =
  1698. $this->nextpage->store(
  1699. json_encode(
  1700. [
  1701. "q" => $get["s"],
  1702. "tbm" => "isch",
  1703. "async" => "_id:islrg_c,_fmt:html",
  1704. "asearch" => "ichunklite",
  1705. "ved" => $ved,
  1706. "vet" => "1" . $ved . "..i",
  1707. "start" => 100,
  1708. "ijn" => 1,
  1709. "imgvl" => $imgvl
  1710. ]
  1711. ),
  1712. "images"
  1713. );
  1714. }
  1715. foreach($images as $image){
  1716. $this->fuckhtml->load($image);
  1717. $img =
  1718. $this->fuckhtml
  1719. ->getElementsByTagName("img")[0];
  1720. $og_width = (int)$image["attributes"]["data-ow"];
  1721. $og_height = (int)$image["attributes"]["data-oh"];
  1722. $thumb_width = (int)$image["attributes"]["data-tw"];
  1723. $ratio = $og_width / $og_height;
  1724. if(isset($img["attributes"]["data-src"])){
  1725. $src = &$img["attributes"]["data-src"];
  1726. }else{
  1727. $src = &$img["attributes"]["src"];
  1728. }
  1729. $thumb_height = floor($thumb_width / $ratio);
  1730. $out["image"][] = [
  1731. "title" =>
  1732. $this->titledots(
  1733. $this->fuckhtml
  1734. ->getTextContent(
  1735. $image["attributes"]["data-pt"]
  1736. )
  1737. ),
  1738. "source" => [
  1739. [
  1740. "url" =>
  1741. $this->fuckhtml
  1742. ->getTextContent(
  1743. $image["attributes"]["data-ou"]
  1744. ),
  1745. "width" => $og_width,
  1746. "height" => $og_height
  1747. ],
  1748. [
  1749. "url" =>
  1750. $this->fuckhtml
  1751. ->getTextContent(
  1752. $src
  1753. ),
  1754. "width" => $thumb_width,
  1755. "height" => $thumb_height
  1756. ]
  1757. ],
  1758. "url" =>
  1759. $this->fuckhtml
  1760. ->getTextContent(
  1761. $image["attributes"]["data-ru"]
  1762. )
  1763. ];
  1764. }
  1765. return $out;
  1766. }
  1767. private function findstyles($rules, $is){
  1768. ksort($rules);
  1769. foreach($this->computedstyle as $stylename => $styles){
  1770. if($styles == $rules){
  1771. preg_match(
  1772. '/\\' . $is . '([^ .]+)/',
  1773. $stylename,
  1774. $out
  1775. );
  1776. if(count($out) === 2){
  1777. return $out[1];
  1778. }
  1779. return false;
  1780. }
  1781. }
  1782. return false;
  1783. }
  1784. private function parsestyles($style){
  1785. // get style tags
  1786. preg_match_all(
  1787. '/([^{]+){([^}]+)}/',
  1788. $style,
  1789. $tags_regex
  1790. );
  1791. $tags = [];
  1792. for($i=0; $i<count($tags_regex[0]); $i++){
  1793. $tagnames = explode(",", trim($tags_regex[1][$i]));
  1794. foreach($tagnames as $tagname){
  1795. $tagname = trim($tagname);
  1796. if(!isset($tags[$tagname])){
  1797. $tags[$tagname] = [];
  1798. }
  1799. $values = explode(";", $tags_regex[2][$i]);
  1800. foreach($values as $value){
  1801. $value = explode(":", $value, 2);
  1802. if(count($value) !== 2){
  1803. continue;
  1804. }
  1805. $tags[$tagname][trim($value[0])] =
  1806. trim($value[1]);
  1807. }
  1808. }
  1809. }
  1810. foreach($tags as &$value){
  1811. ksort($value);
  1812. }
  1813. return $tags;
  1814. }
  1815. private function getimage($id){
  1816. if(
  1817. isset($this->js_image[$id]) &&
  1818. $this->js_image[$id] != "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABAUlEQVR4AWMYesChoYElLjkzPj4lY3d8csZjIL4MxPNjUzPcSTYsISFLAqj5NBD/h+LPQPwbiT87NCuLh2gDgRr2QzXuT0jNMoBYksARn5zuHJ+UcR0kB6RXE2VYXHJGOlTDZmzyIJcB5e+D1CSkZDgQNBAaZv+jU1JkcKpJygiGeZ0I76a/Byq8jU9NZFqaCNTA48SE33/iDcw8TIyBt0GKQTFN0Msp6f2EIyUpo57YSIlLSrMhIg0WCIBcCfXSdlzJBsheTHQ6jEnOUgEFOLaEDbMIlhZBOYrorAdJk+nroVnvPsSgdGdoOF7HZyhZ2XPoGQoqjbCpIbt0AiejIQMArVLI7k/DXFkAAAAASUVORK5CYII="
  1819. ){
  1820. if(stripos($this->js_image[$id], "data:image") !== false){
  1821. return
  1822. explode(
  1823. "\\x3d",
  1824. $this->js_image[$id],
  1825. 2
  1826. )[0];
  1827. }
  1828. return $this->js_image[$id];
  1829. }
  1830. return null;
  1831. }
  1832. private function decodeurl($url){
  1833. preg_match(
  1834. '/^\/url\?q=([^&]+)|^\/interstitial\?url=([^&]+)/',
  1835. $this->fuckhtml
  1836. ->getTextContent($url),
  1837. $match
  1838. );
  1839. if(count($match) !== 0){
  1840. if(!empty($match[1])){
  1841. return urldecode($match[1]);
  1842. }
  1843. if(!empty($match[2])){
  1844. return urldecode($match[2]);
  1845. }
  1846. }
  1847. return null;
  1848. }
  1849. private function titledots($title){
  1850. return rtrim($title, ".… \t\n\r\0\x0B");
  1851. }
  1852. }