diff --git a/images.php b/images.php index 67a50e8..2c0799e 100644 --- a/images.php +++ b/images.php @@ -58,32 +58,15 @@ if(count($results["image"]) === 0){ foreach($results["image"] as $image){ - $domain = htmlspecialchars(parse_url($image["url"], PHP_URL_HOST)); - - $c = count($image["source"]) - 1; - - if( - preg_match( - '/^data:/', - $image["source"][$c]["url"] - ) - ){ - - $src = htmlspecialchars($image["source"][$c]["url"]); - }else{ - - $src = "/proxy?i=" . urlencode($image["source"][$c]["url"]) . "&s=thumb"; - } - $payload["images"] .= '
' . '
' . '' . - 'thumbnail' . + 'thumbnail' . '
' . $image["source"][0]["width"] . 'x' . $image["source"][0]["height"] . '
' . '
' . '' . - '
' . htmlspecialchars($domain) . '
' . + '
' . htmlspecialchars(parse_url($image["url"], PHP_URL_HOST)) . '
' . '
' . $frontend->highlighttext($get["s"], $image["title"]) . '
' . '
' . '
' . diff --git a/lib/frontend.php b/lib/frontend.php index 3be912b..e03eb1d 100644 --- a/lib/frontend.php +++ b/lib/frontend.php @@ -143,7 +143,7 @@ class frontend{ $payload .= '">' . - 'thumb'; + 'thumb'; if($duration !== null){ @@ -1273,6 +1273,21 @@ class frontend{ return http_build_query($out); } + public function htmlimage($image, $format){ + + if( + preg_match( + '/^data:/', + $image + ) + ){ + + return htmlspecialchars($image); + } + + return "/proxy.php?i=" . urlencode($image) . "&s=" . $format; + } + public function htmlnextpage($gets, $npt, $page){ $query = $this->buildquery($gets); diff --git a/scraper/ddg.php b/scraper/ddg.php index c9c28af..1ce8e18 100644 --- a/scraper/ddg.php +++ b/scraper/ddg.php @@ -679,7 +679,7 @@ class ddg{ Check for worknik results */ preg_match( - '/nrj\(\'\/js\/spice\/dictionary\/definition\/([^\']+)\'\)/', + '/nrj\(\'\/js\/spice\/dictionary\/definition\/([^\'\)]+)/', $js, $wordnik ); diff --git a/scraper/google.php b/scraper/google.php index 6a746f7..df10754 100644 --- a/scraper/google.php +++ b/scraper/google.php @@ -18,280 +18,7 @@ class google{ switch($page){ - case "web": return [];/* - return [ - "country" => [ - "display" => "Country", - "option" => [ - "zz" => "Instance region", - "af" => "Afghanistan", - "al" => "Albania", - "dz" => "Algeria", - "as" => "American Samoa", - "ad" => "Andorra", - "ao" => "Angola", - "ag" => "Antigua & Barbuda", - "ar" => "Argentina", - "am" => "Armenia", - "au" => "Australia", - "at" => "Austria", - "az" => "Azerbaijan", - "bs" => "Bahamas", - "bh" => "Bahrain", - "bd" => "Bangladesh", - "by" => "Belarus", - "be" => "Belgium", - "bz" => "Belize", - "bj" => "Benin", - "bt" => "Bhutan", - "bo" => "Bolivia", - "ba" => "Bosnia & Herzegovina", - "bw" => "Botswana", - "br" => "Brazil", - "bn" => "Brunei", - "bg" => "Bulgaria", - "bf" => "Burkina Faso", - "bi" => "Burundi", - "kh" => "Cambodia", - "cm" => "Cameroon", - "ca" => "Canada", - "cv" => "Cape Verde", - "cf" => "Central African Republic", - "td" => "Chad", - "cl" => "Chile", - "co" => "Colombia", - "cg" => "Congo - Brazzaville", - "cd" => "Congo - Kinshasa", - "ck" => "Cook Islands", - "cr" => "Costa Rica", - "ci" => "Côte d’Ivoire", - "hr" => "Croatia", - "cu" => "Cuba", - "cy" => "Cyprus", - "cz" => "Czechia", - "dk" => "Denmark", - "dj" => "Djibouti", - "dm" => "Dominica", - "do" => "Dominican Republic", - "ec" => "Ecuador", - "eg" => "Egypt", - "sv" => "El Salvador", - "ee" => "Estonia", - "et" => "Ethiopia", - "fj" => "Fiji", - "fi" => "Finland", - "fr" => "France", - "ga" => "Gabon", - "gm" => "Gambia", - "ge" => "Georgia", - "de" => "Germany", - "gh" => "Ghana", - "gi" => "Gibraltar", - "gr" => "Greece", - "gl" => "Greenland", - "gt" => "Guatemala", - "gg" => "Guernsey", - "gy" => "Guyana", - "ht" => "Haiti", - "hn" => "Honduras", - "hk" => "Hong Kong", - "hu" => "Hungary", - "is" => "Iceland", - "in" => "India", - "id" => "Indonesia", - "iq" => "Iraq", - "ie" => "Ireland", - "im" => "Isle of Man", - "il" => "Israel", - "it" => "Italy", - "jm" => "Jamaica", - "jp" => "Japan", - "je" => "Jersey", - "jo" => "Jordan", - "kz" => "Kazakhstan", - "ke" => "Kenya", - "ki" => "Kiribati", - "kw" => "Kuwait", - "kg" => "Kyrgyzstan", - "la" => "Laos", - "lv" => "Latvia", - "lb" => "Lebanon", - "ls" => "Lesotho", - "ly" => "Libya", - "li" => "Liechtenstein", - "lt" => "Lithuania", - "lu" => "Luxembourg", - "mg" => "Madagascar", - "mw" => "Malawi", - "my" => "Malaysia", - "mv" => "Maldives", - "ml" => "Mali", - "mt" => "Malta", - "mu" => "Mauritius", - "mx" => "Mexico", - "fm" => "Micronesia", - "md" => "Moldova", - "mn" => "Mongolia", - "me" => "Montenegro", - "ma" => "Morocco", - "mz" => "Mozambique", - "mm" => "Myanmar (Burma)", - "na" => "Namibia", - "nr" => "Nauru", - "np" => "Nepal", - "nl" => "Netherlands", - "nz" => "New Zealand", - "ni" => "Nicaragua", - "ne" => "Niger", - "ng" => "Nigeria", - "nu" => "Niue", - "mk" => "North Macedonia", - "no" => "Norway", - "om" => "Oman", - "pk" => "Pakistan", - "ps" => "Palestine", - "pa" => "Panama", - "pg" => "Papua New Guinea", - "py" => "Paraguay", - "pe" => "Peru", - "ph" => "Philippines", - "pn" => "Pitcairn Islands", - "pl" => "Poland", - "pt" => "Portugal", - "pr" => "Puerto Rico", - "qa" => "Qatar", - "ro" => "Romania", - "ru" => "Russia", - "rw" => "Rwanda", - "ws" => "Samoa", - "sm" => "San Marino", - "st" => "São Tomé & Príncipe", - "sa" => "Saudi Arabia", - "sn" => "Senegal", - "rs" => "Serbia", - "sc" => "Seychelles", - "sl" => "Sierra Leone", - "sg" => "Singapore", - "sk" => "Slovakia", - "si" => "Slovenia", - "sb" => "Solomon Islands", - "so" => "Somalia", - "za" => "South Africa", - "kr" => "South Korea", - "es" => "Spain", - "lk" => "Sri Lanka", - "sh" => "St. Helena", - "vc" => "St. Vincent & Grenadines", - "sr" => "Suriname", - "se" => "Sweden", - "ch" => "Switzerland", - "tw" => "Taiwan", - "tj" => "Tajikistan", - "tz" => "Tanzania", - "th" => "Thailand", - "tl" => "Timor-Leste", - "tg" => "Togo", - "to" => "Tonga", - "tt" => "Trinidad & Tobago", - "tn" => "Tunisia", - "tr" => "Türkiye", - "tm" => "Turkmenistan", - "vi" => "U.S. Virgin Islands", - "ug" => "Uganda", - "ua" => "Ukraine", - "ae" => "United Arab Emirates", - "gb" => "United Kingdom", - "us" => "United States", - "uy" => "Uruguay", - "uz" => "Uzbekistan", - "vu" => "Vanuatu", - "ve" => "Venezuela", - "vn" => "Vietnam", - "zm" => "Zambia", - "zw" => "Zimbabwe" - ] - ], - "nsfw" => [ - "display" => "NSFW", - "option" => [ - "yes" => "Yes", - "no" => "No" - ] - ], - "lang" => [ // prefix with lang_ - "display" => "Language", - "option" => [ - "any" => "Any language", - "af" => "Afrikaans", - "ca" => "català", - "cs" => "čeština", - "da" => "dansk", - "de" => "Deutsch", - "et" => "eesti", - "en" => "English", - "es" => "español", - "eo" => "esperanto", - "tl" => "Filipino", - "fr" => "français", - "hr" => "hrvatski", - "id" => "Indonesia", - "is" => "íslenska", - "it" => "italiano", - "sw" => "Kiswahili", - "lv" => "latviešu", - "lt" => "lietuvių", - "hu" => "magyar", - "nl" => "Nederlands", - "no" => "norsk", - "pl" => "polski", - "pt" => "português", - "ro" => "română", - "sk" => "slovenčina", - "sl" => "slovenščina", - "fi" => "suomi", - "sv" => "svenska", - "vi" => "Tiếng Việt", - "tr" => "Türkçe", - "el" => "Ελληνικά", - "be" => "беларуская", - "bg" => "български", - "ru" => "русский", - "sr" => "српски", - "uk" => "українська", - "hy" => "հայերեն", - "iw" => "עברית", - "ar" => "العربية", - "fa" => "فارسی", - "hi" => "हिन्दी", - "th" => "ไทย", - "ko" => "한국어", - "zh-CN" => "中文 (简体)", - "zh-TW" => "中文 (繁體)", - "ja" => "日本語" - ] - ], - "time" => [ - "display" => "Time posted", - "option" => [ - "any" => "Any time", - "h" => "Last hour", - "d" => "Last 24 hours", - "w" => "Last week", - "m" => "Last month", - "y" => "Last year" - ] - ], - "verbatim" => [ - "display" => "Verbatim", - "option" => [ - "no" => "No", - "yes" => "Yes" - ] - ] - ];*/ - break; - - case "images": + case "web": return [ "country" => [ // gl= "display" => "Country", @@ -346,7 +73,7 @@ class google{ "co" => "Colombia", "km" => "Comoros", "cg" => "Congo", - "cd" => "Congo, the Democratic Republic of the", + "cd" => "Congo, the Democratic Republic", "ck" => "Cook Islands", "cr" => "Costa Rica", "ci" => "Cote D'ivoire", @@ -397,7 +124,7 @@ class google{ "is" => "Iceland", "in" => "India", "id" => "Indonesia", - "ir" => "Iran, Islamic Republic of", + "ir" => "Iran, Islamic Republic", "iq" => "Iraq", "ie" => "Ireland", "il" => "Israel", @@ -408,8 +135,8 @@ class google{ "kz" => "Kazakhstan", "ke" => "Kenya", "ki" => "Kiribati", - "kp" => "Korea, Democratic People's Republic of", - "kr" => "Korea, Republic of", + "kp" => "Korea, Democratic People's Republic", + "kr" => "Korea, Republic", "kw" => "Kuwait", "kg" => "Kyrgyzstan", "la" => "Lao People's Democratic Republic", @@ -422,7 +149,7 @@ class google{ "lt" => "Lithuania", "lu" => "Luxembourg", "mo" => "Macao", - "mk" => "Macedonia, the Former Yugosalv Republic of", + "mk" => "Macedonia, the Former Yugosalv Republic", "mg" => "Madagascar", "mw" => "Malawi", "my" => "Malaysia", @@ -435,8 +162,8 @@ class google{ "mu" => "Mauritius", "yt" => "Mayotte", "mx" => "Mexico", - "fm" => "Micronesia, Federated States of", - "md" => "Moldova, Republic of", + "fm" => "Micronesia, Federated States", + "md" => "Moldova, Republic", "mc" => "Monaco", "mn" => "Mongolia", "ms" => "Montserrat", @@ -506,7 +233,313 @@ class google{ "sy" => "Syrian Arab Republic", "tw" => "Taiwan, Province of China", "tj" => "Tajikistan", - "tz" => "Tanzania, United Republic of", + "tz" => "Tanzania, United Republic", + "th" => "Thailand", + "tl" => "Timor-Leste", + "tg" => "Togo", + "tk" => "Tokelau", + "to" => "Tonga", + "tt" => "Trinidad and Tobago", + "tn" => "Tunisia", + "tr" => "Turkey", + "tm" => "Turkmenistan", + "tc" => "Turks and Caicos Islands", + "tv" => "Tuvalu", + "ug" => "Uganda", + "ua" => "Ukraine", + "ae" => "United Arab Emirates", + "uk" => "United Kingdom", + "us" => "United States", + "um" => "United States Minor Outlying Islands", + "uy" => "Uruguay", + "uz" => "Uzbekistan", + "vu" => "Vanuatu", + "ve" => "Venezuela", + "vn" => "Viet Nam", + "vg" => "Virgin Islands, British", + "vi" => "Virgin Islands, U.S.", + "wf" => "Wallis and Futuna", + "eh" => "Western Sahara", + "ye" => "Yemen", + "zm" => "Zambia", + "zw" => "Zimbabwe" + ] + ], + "nsfw" => [ + "display" => "NSFW", + "option" => [ + "yes" => "Yes", // safe=active + "no" => "No" // safe=off + ] + ], + "lang" => [ // lr= (prefix lang with "lang_") + "display" => "Language", + "option" => [ + "any" => "Any language", + "ar" => "Arabic", + "bg" => "Bulgarian", + "ca" => "Catalan", + "cs" => "Czech", + "da" => "Danish", + "de" => "German", + "el" => "Greek", + "en" => "English", + "es" => "Spanish", + "et" => "Estonian", + "fi" => "Finnish", + "fr" => "French", + "hr" => "Croatian", + "hu" => "Hungarian", + "id" => "Indonesian", + "is" => "Icelandic", + "it" => "Italian", + "iw" => "Hebrew", + "ja" => "Japanese", + "ko" => "Korean", + "lt" => "Lithuanian", + "lv" => "Latvian", + "nl" => "Dutch", + "no" => "Norwegian", + "pl" => "Polish", + "pt" => "Portuguese", + "ro" => "Romanian", + "ru" => "Russian", + "sk" => "Slovak", + "sl" => "Slovenian", + "sr" => "Serbian", + "sv" => "Swedish", + "tr" => "Turkish", + "zh-CN" => "Chinese (Simplified)", + "zh-TW" => "Chinese (Traditional)" + ] + ], + "newer" => [ // &sort=review-date:r:20090301:20090430 + "display" => "Newer than", + "option" => "_DATE" + ], + "older" => [ + "display" => "Older than", + "option" => "_DATE" + ] + ]; + break; + + case "images": + return [ + "country" => [ // gl= + "display" => "Country", + "option" => [ + "any" => "Instance's country", + "af" => "Afghanistan", + "al" => "Albania", + "dz" => "Algeria", + "as" => "American Samoa", + "ad" => "Andorra", + "ao" => "Angola", + "ai" => "Anguilla", + "aq" => "Antarctica", + "ag" => "Antigua and Barbuda", + "ar" => "Argentina", + "am" => "Armenia", + "aw" => "Aruba", + "au" => "Australia", + "at" => "Austria", + "az" => "Azerbaijan", + "bs" => "Bahamas", + "bh" => "Bahrain", + "bd" => "Bangladesh", + "bb" => "Barbados", + "by" => "Belarus", + "be" => "Belgium", + "bz" => "Belize", + "bj" => "Benin", + "bm" => "Bermuda", + "bt" => "Bhutan", + "bo" => "Bolivia", + "ba" => "Bosnia and Herzegovina", + "bw" => "Botswana", + "bv" => "Bouvet Island", + "br" => "Brazil", + "io" => "British Indian Ocean Territory", + "bn" => "Brunei Darussalam", + "bg" => "Bulgaria", + "bf" => "Burkina Faso", + "bi" => "Burundi", + "kh" => "Cambodia", + "cm" => "Cameroon", + "ca" => "Canada", + "cv" => "Cape Verde", + "ky" => "Cayman Islands", + "cf" => "Central African Republic", + "td" => "Chad", + "cl" => "Chile", + "cn" => "China", + "cx" => "Christmas Island", + "cc" => "Cocos (Keeling) Islands", + "co" => "Colombia", + "km" => "Comoros", + "cg" => "Congo", + "cd" => "Congo, the Democratic Republic", + "ck" => "Cook Islands", + "cr" => "Costa Rica", + "ci" => "Cote D'ivoire", + "hr" => "Croatia", + "cu" => "Cuba", + "cy" => "Cyprus", + "cz" => "Czech Republic", + "dk" => "Denmark", + "dj" => "Djibouti", + "dm" => "Dominica", + "do" => "Dominican Republic", + "ec" => "Ecuador", + "eg" => "Egypt", + "sv" => "El Salvador", + "gq" => "Equatorial Guinea", + "er" => "Eritrea", + "ee" => "Estonia", + "et" => "Ethiopia", + "fk" => "Falkland Islands (Malvinas)", + "fo" => "Faroe Islands", + "fj" => "Fiji", + "fi" => "Finland", + "fr" => "France", + "gf" => "French Guiana", + "pf" => "French Polynesia", + "tf" => "French Southern Territories", + "ga" => "Gabon", + "gm" => "Gambia", + "ge" => "Georgia", + "de" => "Germany", + "gh" => "Ghana", + "gi" => "Gibraltar", + "gr" => "Greece", + "gl" => "Greenland", + "gd" => "Grenada", + "gp" => "Guadeloupe", + "gu" => "Guam", + "gt" => "Guatemala", + "gn" => "Guinea", + "gw" => "Guinea-Bissau", + "gy" => "Guyana", + "ht" => "Haiti", + "hm" => "Heard Island and Mcdonald Islands", + "va" => "Holy See (Vatican City State)", + "hn" => "Honduras", + "hk" => "Hong Kong", + "hu" => "Hungary", + "is" => "Iceland", + "in" => "India", + "id" => "Indonesia", + "ir" => "Iran, Islamic Republic", + "iq" => "Iraq", + "ie" => "Ireland", + "il" => "Israel", + "it" => "Italy", + "jm" => "Jamaica", + "jp" => "Japan", + "jo" => "Jordan", + "kz" => "Kazakhstan", + "ke" => "Kenya", + "ki" => "Kiribati", + "kp" => "Korea, Democratic People's Republic", + "kr" => "Korea, Republic", + "kw" => "Kuwait", + "kg" => "Kyrgyzstan", + "la" => "Lao People's Democratic Republic", + "lv" => "Latvia", + "lb" => "Lebanon", + "ls" => "Lesotho", + "lr" => "Liberia", + "ly" => "Libyan Arab Jamahiriya", + "li" => "Liechtenstein", + "lt" => "Lithuania", + "lu" => "Luxembourg", + "mo" => "Macao", + "mk" => "Macedonia, the Former Yugosalv Republic", + "mg" => "Madagascar", + "mw" => "Malawi", + "my" => "Malaysia", + "mv" => "Maldives", + "ml" => "Mali", + "mt" => "Malta", + "mh" => "Marshall Islands", + "mq" => "Martinique", + "mr" => "Mauritania", + "mu" => "Mauritius", + "yt" => "Mayotte", + "mx" => "Mexico", + "fm" => "Micronesia, Federated States", + "md" => "Moldova, Republic", + "mc" => "Monaco", + "mn" => "Mongolia", + "ms" => "Montserrat", + "ma" => "Morocco", + "mz" => "Mozambique", + "mm" => "Myanmar", + "na" => "Namibia", + "nr" => "Nauru", + "np" => "Nepal", + "nl" => "Netherlands", + "an" => "Netherlands Antilles", + "nc" => "New Caledonia", + "nz" => "New Zealand", + "ni" => "Nicaragua", + "ne" => "Niger", + "ng" => "Nigeria", + "nu" => "Niue", + "nf" => "Norfolk Island", + "mp" => "Northern Mariana Islands", + "no" => "Norway", + "om" => "Oman", + "pk" => "Pakistan", + "pw" => "Palau", + "ps" => "Palestinian Territory, Occupied", + "pa" => "Panama", + "pg" => "Papua New Guinea", + "py" => "Paraguay", + "pe" => "Peru", + "ph" => "Philippines", + "pn" => "Pitcairn", + "pl" => "Poland", + "pt" => "Portugal", + "pr" => "Puerto Rico", + "qa" => "Qatar", + "re" => "Reunion", + "ro" => "Romania", + "ru" => "Russian Federation", + "rw" => "Rwanda", + "sh" => "Saint Helena", + "kn" => "Saint Kitts and Nevis", + "lc" => "Saint Lucia", + "pm" => "Saint Pierre and Miquelon", + "vc" => "Saint Vincent and the Grenadines", + "ws" => "Samoa", + "sm" => "San Marino", + "st" => "Sao Tome and Principe", + "sa" => "Saudi Arabia", + "sn" => "Senegal", + "cs" => "Serbia and Montenegro", + "sc" => "Seychelles", + "sl" => "Sierra Leone", + "sg" => "Singapore", + "sk" => "Slovakia", + "si" => "Slovenia", + "sb" => "Solomon Islands", + "so" => "Somalia", + "za" => "South Africa", + "gs" => "South Georgia and the South Sandwich Islands", + "es" => "Spain", + "lk" => "Sri Lanka", + "sd" => "Sudan", + "sr" => "Suriname", + "sj" => "Svalbard and Jan Mayen", + "sz" => "Swaziland", + "se" => "Sweden", + "ch" => "Switzerland", + "sy" => "Syrian Arab Republic", + "tw" => "Taiwan, Province of China", + "tj" => "Tajikistan", + "tz" => "Tanzania, United Republic", "th" => "Thailand", "tl" => "Timor-Leste", "tg" => "Togo", @@ -603,14 +636,20 @@ class google{ "i" => "Icon" ] ], - "color" => [ // tbs=ic: + "colortype" => [ // imgColorType= + "display" => "Color type", + "option" => [ + "any" => "Any color type", + "color" => "Colored", + "gray" => "Gray", + "mono" => "Black & white", + "trans" => "Transparent" + ] + ], + "color" => [ // imgDominantColor= "display" => "Color", "option" => [ "any" => "Any color", - "gray" => "Black and white", - "trans" => "Transparent", - // from here, format is - // tbs=specific,isc: "red" => "Red", "orange" => "Orange", "yellow" => "Yellow", @@ -625,13 +664,15 @@ class google{ "brown" => "Brown" ] ], - "type" => [ // tbs=itp: + "type" => [ // imgType= "display" => "Type", "option" => [ "any" => "Any type", + "face" => "Faces", "clipart" => "Clip Art", "lineart" => "Line Drawing", - "animated" => "GIF" + "stock" => "Stock", + "animated" => "Animated" ] ], "rights" => [ // tbs=il: @@ -694,6 +735,52 @@ class google{ public function web($get){ + $search = $get["s"]; + $country = $get["country"]; + $nsfw = $get["nsfw"]; + $lang = $get["lang"]; + $older = $get["older"]; + $newer = $get["newer"]; + + $params = [ + "num" => 20 // get 20 results + ]; + + // country + if($country != "any"){ + + $params["gl"] = $country; + } + + // nsfw + $params["safe"] = $nsfw == "yes" ? "off" : "active"; + + // language + if($lang != "any"){ + + $params["lr"] = "lang_" . $lang; + } + + // &sort=review-date:r:20090301:20090430 + $older = $older === false ? false : date("Ymd", $older); + $newer = $newer === false ? false : date("Ymd", $newer); + + if( + $older !== false && + $newer === false + ){ + + $newer = date("Ymd", time()); + } + + if( + $older !== false || + $newer !== false + ){ + + $params["sort"] = "review-date:r:" . $older . ":" . $newer; + } + $handle = fopen("scraper/google.html", "r"); $html = fread($handle, filesize("scraper/google.html")); fclose($handle); @@ -735,15 +822,44 @@ class google{ preg_match( '/google\.ldi=({[^}]+})/', $html, - $js_image + $this->js_image ); - if(count($js_image) !== 0){ + if(count($this->js_image) !== 0){ - $js_image = json_decode($js_image[1], true); + $this->js_image = json_decode($this->js_image[1], true); }else{ - $js_image = []; + $this->js_image = []; + } + + // additional js_images present in