google.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155
  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. Fallback to parsing it as an embed
  1405. */
  1406. $table = [
  1407. "title" => null,
  1408. "description" => [],
  1409. "url" => null,
  1410. "thumb" => null,
  1411. "table" => [],
  1412. "sublink" => []
  1413. ];
  1414. $parts =
  1415. $this->fuckhtml
  1416. ->getElementsByClassName(
  1417. $this->findstyles(
  1418. [
  1419. "padding" => "12px 16px 12px"
  1420. ],
  1421. self::is_class
  1422. ),
  1423. "div"
  1424. );
  1425. if(count($parts) === 0){
  1426. continue;
  1427. }
  1428. $head = $parts[0];
  1429. $h3 =
  1430. $this->fuckhtml
  1431. ->getElementsByTagName("h3");
  1432. if(count($h3) !== 0){
  1433. $h3 = $h3[0];
  1434. $table["title"] =
  1435. $this->fuckhtml
  1436. ->getTextContent(
  1437. $h3
  1438. );
  1439. $head["innerHTML"] =
  1440. str_replace(
  1441. $h3["outerHTML"],
  1442. "",
  1443. $head["innerHTML"]
  1444. );
  1445. $table["description"][] =
  1446. [
  1447. "type" => "quote",
  1448. "value" =>
  1449. $this->fuckhtml
  1450. ->getTextContent(
  1451. $head
  1452. )
  1453. ];
  1454. }
  1455. $audio =
  1456. $this->fuckhtml
  1457. ->getElementsByTagName("audio");
  1458. if(count($audio) !== 0){
  1459. $table["description"][] = [
  1460. "type" => "audio",
  1461. "url" =>
  1462. str_replace(
  1463. "http://",
  1464. "https://",
  1465. $this->fuckhtml
  1466. ->getTextContent(
  1467. $audio[0]["attributes"]["src"]
  1468. )
  1469. )
  1470. ];
  1471. }
  1472. if(count($parts) >= 2){
  1473. $this->fuckhtml->load($parts[1]);
  1474. $parts =
  1475. $this->fuckhtml
  1476. ->getElementsByClassName(
  1477. $this->findstyles(
  1478. [
  1479. "padding-bottom" => "12px"
  1480. ],
  1481. self::is_class
  1482. ),
  1483. "div"
  1484. );
  1485. foreach($parts as $part){
  1486. $this->fuckhtml->load($part);
  1487. $lists =
  1488. $this->fuckhtml
  1489. ->getElementsByTagName("ol");
  1490. if(count($lists) !== 0){
  1491. foreach($lists as $list){
  1492. $this->fuckhtml->load($list);
  1493. $list_items =
  1494. $this->fuckhtml
  1495. ->getElementsByTagName("li");
  1496. $index = 0;
  1497. if(count($list_items) !== 0){
  1498. foreach($list_items as $list_item){
  1499. $index++;
  1500. $this->fuckhtml->load($list_item);
  1501. $list_subitems =
  1502. $this->fuckhtml
  1503. ->getElementsByTagName("div");
  1504. foreach($list_subitems as $subitem){
  1505. if($subitem["level"] !== 1){ continue; }
  1506. $this->fuckhtml->load($subitem);
  1507. $spans =
  1508. $this->fuckhtml
  1509. ->getElementsByTagName("span");
  1510. if(count($spans) !== 0){
  1511. $type = "quote";
  1512. }else{
  1513. $type = "text";
  1514. }
  1515. $value =
  1516. $this->fuckhtml
  1517. ->getTextContent(
  1518. $subitem
  1519. );
  1520. if($type == "text"){
  1521. $value = $index . ". " . $value;
  1522. }
  1523. $table["description"][] = [
  1524. "type" => $type,
  1525. "value" => $value
  1526. ];
  1527. }
  1528. }
  1529. }
  1530. }
  1531. continue;
  1532. }
  1533. // get title
  1534. $spans =
  1535. $this->fuckhtml
  1536. ->getElementsByTagName("span");
  1537. if(count($spans) !== 0){
  1538. foreach($spans as $span){
  1539. $part["innerHTML"] =
  1540. str_replace(
  1541. $span["outerHTML"],
  1542. "",
  1543. $part["innerHTML"]
  1544. );
  1545. }
  1546. if(
  1547. $this->fuckhtml
  1548. ->getTextContent(
  1549. $part
  1550. )
  1551. == ""
  1552. ){
  1553. $table["description"][] = [
  1554. "type" => "title",
  1555. "value" =>
  1556. $this->fuckhtml
  1557. ->getTextContent(
  1558. $spans[0]
  1559. )
  1560. ];
  1561. continue;
  1562. }
  1563. }
  1564. // fallback to getting non-numbered list
  1565. $nlist =
  1566. $this->fuckhtml
  1567. ->getElementsByClassName(
  1568. $this->findstyles(
  1569. [
  1570. "white-space" => "pre-line",
  1571. "word-wrap" => "break-word"
  1572. ],
  1573. self::is_class
  1574. ),
  1575. "div"
  1576. );
  1577. if(count($nlist) !== 0){
  1578. foreach($nlist as $nlist_item){
  1579. $text =
  1580. $this->fuckhtml
  1581. ->getTextContent($nlist_item);
  1582. if($text == ""){
  1583. continue;
  1584. }
  1585. $this->fuckhtml->load($nlist_item);
  1586. $spans =
  1587. $this->fuckhtml
  1588. ->getElementsByTagName("span");
  1589. if(count($spans) !== 0){
  1590. // is a quote node
  1591. $type = "quote";
  1592. }else{
  1593. $type = "text";
  1594. }
  1595. $table["description"][] = [
  1596. "type" => $type,
  1597. "value" => $text
  1598. ];
  1599. }
  1600. }
  1601. }
  1602. }
  1603. $out["answer"][] = $table;
  1604. }
  1605. if($dmca_table){
  1606. $out["answer"][] = $dmca_table;
  1607. }
  1608. return $out;
  1609. }
  1610. public function image($get){
  1611. $search = $get["s"];
  1612. $country = $get["country"];
  1613. $nsfw = $get["nsfw"];
  1614. $lang = $get["lang"];
  1615. $size = $get["size"];
  1616. $colortype = $get["colortype"];
  1617. $color = $get["color"];
  1618. $type = $get["type"];
  1619. $rights = $get["rights"];
  1620. $older = $get["older"];
  1621. $newer = $get["newer"];
  1622. $params = [];
  1623. // country
  1624. if($country != "any"){
  1625. $params["gl"] = $country;
  1626. }
  1627. // nsfw
  1628. $params["safe"] = $nsfw == "yes" ? "off" : "active";
  1629. // language
  1630. if($lang != "any"){
  1631. $params["lr"] = "lang_" . $lang;
  1632. }
  1633. // &sort=review-date:r:20090301:20090430
  1634. $older = $older === false ? false : date("Ymd", $older);
  1635. $newer = $newer === false ? false : date("Ymd", $newer);
  1636. if(
  1637. $older !== false &&
  1638. $newer === false
  1639. ){
  1640. $newer = date("Ymd", time());
  1641. }
  1642. if(
  1643. $older !== false ||
  1644. $newer !== false
  1645. ){
  1646. $params["sort"] = "review-date:r:" . $older . ":" . $newer;
  1647. }
  1648. $handle = fopen("scraper/google-img.html", "r");
  1649. $html = fread($handle, filesize("scraper/google-img.html"));
  1650. fclose($handle);
  1651. $this->fuckhtml->load($html);
  1652. $out = [
  1653. "status" => "ok",
  1654. "npt" => null,
  1655. "image" => []
  1656. ];
  1657. $images =
  1658. $this->fuckhtml
  1659. ->getElementsByClassName(
  1660. "islrtb isv-r",
  1661. "div"
  1662. );
  1663. // get next page
  1664. // https://www.google.com/search
  1665. // ?q=higurashi
  1666. // &tbm=isch
  1667. // &async=_id%3Aislrg_c%2C_fmt%3Ahtml
  1668. // &asearch=ichunklite
  1669. // &ved=0ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA
  1670. $ved =
  1671. $this->fuckhtml
  1672. ->getElementById("islrg", "div");
  1673. if($ved){
  1674. $ved =
  1675. $this->fuckhtml
  1676. ->getTextContent(
  1677. $ved["attributes"]["data-ved"]
  1678. );
  1679. // &vet=1{$ved}..i (10ahUKEwidjYXJqJSAAxWrElkFHZ07CDwQtDIIQygA..i)
  1680. /*
  1681. These 2 are handled by us
  1682. start = start + number of results
  1683. ijn = current page number
  1684. */
  1685. // &start=100
  1686. // &ijn=1
  1687. // &imgvl=CAEY7gQgBSj3Aji8VTjXVUC4AUC3AUgAYNdV
  1688. preg_match(
  1689. '/var e=\'([A-z0-9]+)\';/',
  1690. $html,
  1691. $imgvl
  1692. );
  1693. $imgvl = $imgvl[1];
  1694. $out["npt"] =
  1695. $this->nextpage->store(
  1696. json_encode(
  1697. [
  1698. "q" => $get["s"],
  1699. "tbm" => "isch",
  1700. "async" => "_id:islrg_c,_fmt:html",
  1701. "asearch" => "ichunklite",
  1702. "ved" => $ved,
  1703. "vet" => "1" . $ved . "..i",
  1704. "start" => 100,
  1705. "ijn" => 1,
  1706. "imgvl" => $imgvl
  1707. ]
  1708. ),
  1709. "images"
  1710. );
  1711. }
  1712. foreach($images as $image){
  1713. $this->fuckhtml->load($image);
  1714. $img =
  1715. $this->fuckhtml
  1716. ->getElementsByTagName("img")[0];
  1717. $og_width = (int)$image["attributes"]["data-ow"];
  1718. $og_height = (int)$image["attributes"]["data-oh"];
  1719. $thumb_width = (int)$image["attributes"]["data-tw"];
  1720. $ratio = $og_width / $og_height;
  1721. if(isset($img["attributes"]["data-src"])){
  1722. $src = &$img["attributes"]["data-src"];
  1723. }else{
  1724. $src = &$img["attributes"]["src"];
  1725. }
  1726. $thumb_height = floor($thumb_width / $ratio);
  1727. $out["image"][] = [
  1728. "title" =>
  1729. $this->titledots(
  1730. $this->fuckhtml
  1731. ->getTextContent(
  1732. $image["attributes"]["data-pt"]
  1733. )
  1734. ),
  1735. "source" => [
  1736. [
  1737. "url" =>
  1738. $this->fuckhtml
  1739. ->getTextContent(
  1740. $image["attributes"]["data-ou"]
  1741. ),
  1742. "width" => $og_width,
  1743. "height" => $og_height
  1744. ],
  1745. [
  1746. "url" =>
  1747. $this->fuckhtml
  1748. ->getTextContent(
  1749. $src
  1750. ),
  1751. "width" => $thumb_width,
  1752. "height" => $thumb_height
  1753. ]
  1754. ],
  1755. "url" =>
  1756. $this->fuckhtml
  1757. ->getTextContent(
  1758. $image["attributes"]["data-ru"]
  1759. )
  1760. ];
  1761. }
  1762. return $out;
  1763. }
  1764. private function findstyles($rules, $is){
  1765. ksort($rules);
  1766. foreach($this->computedstyle as $stylename => $styles){
  1767. if($styles == $rules){
  1768. preg_match(
  1769. '/\\' . $is . '([^ .]+)/',
  1770. $stylename,
  1771. $out
  1772. );
  1773. if(count($out) === 2){
  1774. return $out[1];
  1775. }
  1776. return false;
  1777. }
  1778. }
  1779. return false;
  1780. }
  1781. private function parsestyles($style){
  1782. // get style tags
  1783. preg_match_all(
  1784. '/([^{]+){([^}]+)}/',
  1785. $style,
  1786. $tags_regex
  1787. );
  1788. $tags = [];
  1789. for($i=0; $i<count($tags_regex[0]); $i++){
  1790. $tagnames = explode(",", trim($tags_regex[1][$i]));
  1791. foreach($tagnames as $tagname){
  1792. $tagname = trim($tagname);
  1793. if(!isset($tags[$tagname])){
  1794. $tags[$tagname] = [];
  1795. }
  1796. $values = explode(";", $tags_regex[2][$i]);
  1797. foreach($values as $value){
  1798. $value = explode(":", $value, 2);
  1799. if(count($value) !== 2){
  1800. continue;
  1801. }
  1802. $tags[$tagname][trim($value[0])] =
  1803. trim($value[1]);
  1804. }
  1805. }
  1806. }
  1807. foreach($tags as &$value){
  1808. ksort($value);
  1809. }
  1810. return $tags;
  1811. }
  1812. private function getimage($id){
  1813. if(
  1814. isset($this->js_image[$id]) &&
  1815. $this->js_image[$id] != "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABAUlEQVR4AWMYesChoYElLjkzPj4lY3d8csZjIL4MxPNjUzPcSTYsISFLAqj5NBD/h+LPQPwbiT87NCuLh2gDgRr2QzXuT0jNMoBYksARn5zuHJ+UcR0kB6RXE2VYXHJGOlTDZmzyIJcB5e+D1CSkZDgQNBAaZv+jU1JkcKpJygiGeZ0I76a/Byq8jU9NZFqaCNTA48SE33/iDcw8TIyBt0GKQTFN0Msp6f2EIyUpo57YSIlLSrMhIg0WCIBcCfXSdlzJBsheTHQ6jEnOUgEFOLaEDbMIlhZBOYrorAdJk+nroVnvPsSgdGdoOF7HZyhZ2XPoGQoqjbCpIbt0AiejIQMArVLI7k/DXFkAAAAASUVORK5CYII="
  1816. ){
  1817. if(stripos($this->js_image[$id], "data:image") !== false){
  1818. return
  1819. explode(
  1820. "\\x3d",
  1821. $this->js_image[$id],
  1822. 2
  1823. )[0];
  1824. }
  1825. return $this->js_image[$id];
  1826. }
  1827. return null;
  1828. }
  1829. private function decodeurl($url){
  1830. preg_match(
  1831. '/^\/url\?q=([^&]+)|^\/interstitial\?url=([^&]+)/',
  1832. $this->fuckhtml
  1833. ->getTextContent($url),
  1834. $match
  1835. );
  1836. if(count($match) !== 0){
  1837. if(!empty($match[1])){
  1838. return urldecode($match[1]);
  1839. }
  1840. if(!empty($match[2])){
  1841. return urldecode($match[2]);
  1842. }
  1843. }
  1844. return null;
  1845. }
  1846. private function titledots($title){
  1847. return rtrim($title, ".… \t\n\r\0\x0B");
  1848. }
  1849. }