From 1258f18a7597709cc2395c402a18917900a5ba46 Mon Sep 17 00:00:00 2001 From: lumiru Date: Sat, 17 Dec 2016 17:10:15 +0100 Subject: [PATCH 1/2] Fix encoding problems caused by camo Loading HTML in DomDocument create encoding issues. Additionally, regex are faster than loading a document tree. --- helpers/ViewHelper.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/helpers/ViewHelper.php b/helpers/ViewHelper.php index ad880b3735..67b4aec97f 100644 --- a/helpers/ViewHelper.php +++ b/helpers/ViewHelper.php @@ -83,16 +83,9 @@ public function camoflauge($content) } $camo = new \WillWashburn\Phpamo\Phpamo(\F3::get('camo_key'), \F3::get('camo_domain')); - $dom = new \DOMDocument(); - $dom->loadHTML($content); - foreach ($dom->getElementsByTagName('img') as $item) { - if ($item->hasAttribute('src')) { - $src = $item->getAttribute('src'); - $item->setAttribute('src', $camo->camoHttpOnly($src)); - } - } - - return $dom->saveHTML(); + return preg_replace_callback("//i", function($matches) use ($camo) { + return ''; + }, $content); } } From 9440626176d101b7ae5ea3c68b4cfc56757c22d6 Mon Sep 17 00:00:00 2001 From: lumiru Date: Sat, 17 Dec 2016 20:52:15 +0100 Subject: [PATCH 2/2] [Camo] Stupid mistake in regex replacement --- helpers/ViewHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/ViewHelper.php b/helpers/ViewHelper.php index 67b4aec97f..10e166aa5e 100644 --- a/helpers/ViewHelper.php +++ b/helpers/ViewHelper.php @@ -85,7 +85,7 @@ public function camoflauge($content) $camo = new \WillWashburn\Phpamo\Phpamo(\F3::get('camo_key'), \F3::get('camo_domain')); return preg_replace_callback("//i", function($matches) use ($camo) { - return ''; + return ''; }, $content); } }