Image proxying for esoTalk with camo

At The Chunk, we recently enabled SSL (thanks CloudFlare!) However, there were a few issues with mixed content, and the most prevalent of these are the forums, which run a heavily customized version of esoTalk.

Documentation for camo was not easy to come by, but we eventually managed to get it working. Here's how we did it:

  • Clone and configure camo. This part should not be especially difficult.
  • Proxy camo behind nginx. This too is pretty trivial.
  • Now we can modify esoTalk. Images are handled by the BBCode plugin, so we will need to modify its parser. Open BBCode's plugin.php file and look for ETPlugin_BBCode::handler_format_format(). Replace $sender->content = preg_replace("/\[img\](.*?)\[\/img\]/i", $replacement, $sender->content); with this:
        $sender->content = preg_replace_callback("/\[img\](.*?)\[\/img\]/i", function($uri) use ($sender) {
            $camo = "https://camo.example.com/" . hash_hmac('sha1', $uri[1], 'MY_CAMO_SECRET_KEY') . "?url=" . urlencode($uri[1]);
            return $sender->inline ? "[image]" : "<img src="$camo" alt="-image-" />";
        }, $sender->content);
    
    Replace camo.example.com with the location of your camo instance and MY_CAMO_SECRET_KEY with your camo secret key.
  • camo support is now available on your forums.