1
Fork 0
mirror of https://git.lolcat.ca/lolcat/4get.git synced 2024-12-03 23:42:16 -05:00

Compare commits

...

2 commits

Author SHA1 Message Date
lolcat
aaa30c79f5 fix google cse image crash + added word autocorrect 2024-10-31 20:31:23 -04:00
lolcat
070f9d442b brave fix 2024-10-29 21:29:17 -04:00
3 changed files with 95 additions and 11 deletions

View file

@ -381,6 +381,8 @@ class fuckhtml{
$json_out = null; $json_out = null;
$last_char = null; $last_char = null;
$keyword_check = null;
for($i=0; $i<strlen($json); $i++){ for($i=0; $i<strlen($json); $i++){
switch($json[$i]){ switch($json[$i]){
@ -396,6 +398,7 @@ class fuckhtml{
$bracket = false; $bracket = false;
$is_close_bracket = true; $is_close_bracket = true;
}else{ }else{
if($bracket === false){ if($bracket === false){
@ -429,6 +432,31 @@ class fuckhtml{
$is_close_bracket === false $is_close_bracket === false
){ ){
// do keyword check
$keyword_check .= $json[$i];
if(in_array($json[$i], [":", "{"])){
$keyword_check = substr($keyword_check, 0, -1);
if(
preg_match(
'/function|array|return/i',
$keyword_check
)
){
$json_out =
preg_replace(
'/[{"]*' . preg_quote($keyword_check, "/") . '$/',
"",
$json_out
);
}
$keyword_check = null;
}
// here we know we're not iterating over a quoted string // here we know we're not iterating over a quoted string
switch($json[$i]){ switch($json[$i]){

View file

@ -293,8 +293,8 @@ class brave{
/* /*
$handle = fopen("scraper/brave.html", "r"); $handle = fopen("scraper/brave.html", "r");
$html = fread($handle, filesize("scraper/brave.html")); $html = fread($handle, filesize("scraper/brave.html"));
fclose($handle); fclose($handle);*/
*/
try{ try{
$html = $html =
@ -410,10 +410,20 @@ class brave{
throw new Exception("Could not grep JavaScript object"); throw new Exception("Could not grep JavaScript object");
} }
$data =
rtrim(
preg_replace(
'/\(Array\(0\)\)\).*$/',
"",
$grep[1]
),
" ]"
) . "]";
$data = $data =
$this->fuckhtml $this->fuckhtml
->parseJsObject( ->parseJsObject(
$grep[1] $data
); );
unset($grep); unset($grep);

View file

@ -268,6 +268,13 @@ class google_cse{
"yes" => "Yes", // safe=active "yes" => "Yes", // safe=active
"no" => "No" // safe=off "no" => "No" // safe=off
] ]
],
"spellcheck" => [
// display undefined
"option" => [
"yes" => "Yes",
"no" => "No"
]
] ]
]; ];
@ -538,6 +545,11 @@ class google_cse{
"rurl" => "https://cse.google.com/cse?cx=" . config::GOOGLE_CX_ENDPOINT . "#gsc.tab=0&gsc.q=" . $get["s"] . "&gsc.sort=" "rurl" => "https://cse.google.com/cse?cx=" . config::GOOGLE_CX_ENDPOINT . "#gsc.tab=0&gsc.q=" . $get["s"] . "&gsc.sort="
]; ];
if($get["spellcheck"] == "no"){
$req_params["nfpr"] = "1";
}
$json = $json =
$this->get( $this->get(
$proxy, $proxy,
@ -596,6 +608,42 @@ class google_cse{
"related" => [] "related" => []
]; ];
// detect word correction
if(isset($json["spelling"]["type"])){
switch($json["spelling"]["type"]){
case "DYM": // did you mean? @TODO fix wording
$type = "including";
break;
case "SPELL_CORRECTED_RESULTS": // not many results for
$type = "not_many";
break;
default:
$type = "not_many";
}
if(isset($json["spelling"]["originalQuery"])){
$using = $json["spelling"]["originalQuery"];
}
elseif(isset($json["spelling"]["anchor"])){
$using = html_entity_decode(strip_tags($json["spelling"]["anchor"]));
}elseif(isset($json["spelling"]["originalAnchor"])){
$using = html_entity_decode(strip_tags($json["spelling"]["originalAnchor"]));
}
$out["spelling"] = [
"type" => $type,
"using" => $using,
"correction" => $json["spelling"]["correctedQuery"]
];
}
if(!isset($json["results"])){ if(!isset($json["results"])){
return $out; return $out;
@ -729,8 +777,6 @@ class google_cse{
public function image($get){ public function image($get){
if($get["npt"]){ if($get["npt"]){
[$req_params, $proxy] = [$req_params, $proxy] =
@ -858,6 +904,12 @@ class google_cse{
throw new Exception("Google returned an error object"); throw new Exception("Google returned an error object");
} }
$out = [
"status" => "ok",
"npt" => null,
"image" => []
];
// detect next page // detect next page
if( if(
isset($json["cursor"]["isExactTotalResults"]) || // detects last page isset($json["cursor"]["isExactTotalResults"]) || // detects last page
@ -867,12 +919,6 @@ class google_cse{
return $out; return $out;
} }
$out = [
"status" => "ok",
"npt" => null,
"image" => []
];
foreach($json["results"] as $result){ foreach($json["results"] as $result){
$out["image"][] = [ $out["image"][] = [