summaryrefslogtreecommitdiff
path: root/lib/fuckhtml.php
diff options
context:
space:
mode:
authorlolcat <will@lolcat.ca>2023-08-08 03:09:47 -0400
committerlolcat <will@lolcat.ca>2023-08-08 03:09:47 -0400
commit4559857380317d768ff8394db711eb5c894aa1f8 (patch)
tree2ed555b5ba104297642893ef5511d1d28f282842 /lib/fuckhtml.php
parent7c771c82c8e03b337f9f03ae2d4afc25d3f0faca (diff)
added brave image+video support
Diffstat (limited to 'lib/fuckhtml.php')
-rw-r--r--lib/fuckhtml.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/fuckhtml.php b/lib/fuckhtml.php
index 8802511..5c65417 100644
--- a/lib/fuckhtml.php
+++ b/lib/fuckhtml.php
@@ -356,6 +356,91 @@ class fuckhtml{
return $out;
}
+
+ public function parseJsObject(string $json){
+
+ $bracket = false;
+ $is_close_bracket = false;
+ $escape = false;
+ $json_out = null;
+ $last_char = null;
+
+ for($i=0; $i<strlen($json); $i++){
+
+ switch($json[$i]){
+
+ case "\"":
+ case "'":
+ if($escape === true){
+
+ break;
+ }
+
+ if($json[$i] == $bracket){
+
+ $bracket = false;
+ $is_close_bracket = true;
+ }else{
+
+ if($bracket === false){
+
+ $bracket = $json[$i];
+ }
+ }
+ break;
+
+ default:
+ $is_close_bracket = false;
+ break;
+ }
+
+ $escape = $json[$i] == "\\" ? true : false;
+
+ if(
+ $bracket === false &&
+ $is_close_bracket === false
+ ){
+
+ // here we know we're not iterating over a quoted string
+ switch($json[$i]){
+
+ case "[":
+ case "{":
+ // dont execute whats in "default"
+ $json_out .= $json[$i];
+ break;
+
+ case "]":
+ case "}":
+ case ",":
+ case ":":
+ if(!in_array($last_char, ["[", "{", "}", "]", "\""])){
+
+ $json_out .= "\"";
+ }
+
+ $json_out .= $json[$i];
+ break;
+
+ default:
+ if(in_array($last_char, ["{", "[", ",", ":"])){
+
+ $json_out .= "\"";
+ }
+
+ $json_out .= $json[$i];
+ break;
+ }
+ }else{
+
+ $json_out .= $json[$i];
+ }
+
+ $last_char = $json[$i];
+ }
+
+ return json_decode($json_out, true);
+ }
}
?>