Fix escaping strings for JavaScript

The correct way to pass strings from PHP to JavaScript is json_encode.

Using addslashes or htmlspecialchars(..., ENT_QUOTES) may lead to unexpected issues.