Skip to content

Commit

Permalink
Merge pull request #826 from lumiru/patch-3
Browse files Browse the repository at this point in the history
Fix encoding problems caused by camo
  • Loading branch information
SSilence authored Dec 19, 2016
2 parents bfb2b20 + 9440626 commit 90fdba0
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions helpers/ViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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("/<img([^<]+)src=(['\"])([^\"']*)(['\"])([^<]*)>/i", function($matches) use ($camo) {
return '<img' . $matches[1] . 'src=' . $matches[2] . $camo->camoHttpOnly($matches[3]) . $matches[4] . $matches[5] . '>';
}, $content);
}
}

0 comments on commit 90fdba0

Please sign in to comment.