Horde::escapeJson PHP Méthode

escapeJson() public static méthode

Do necessary escaping to output JSON.
public static escapeJson ( mixed $data, array $options = [] ) : string
$data mixed The data to JSON-ify.
$options array Additional options: - nodelimit: (boolean) Don't add security delimiters? DEFAULT: false - urlencode: (boolean) URL encode the json string DEFAULT: false
Résultat string The escaped string.
    public static function escapeJson($data, array $options = array())
    {
        $json = Horde_Serialize::serialize($data, Horde_Serialize::JSON);
        if (empty($options['nodelimit'])) {
            $json = '/*-secure-' . $json . '*/';
        }
        return empty($options['urlencode']) ? $json : '\'' . rawurlencode($json) . '\'';
    }

Usage Example

Exemple #1
0
 /**
  */
 protected function _attach($init)
 {
     global $page_output;
     if ($init) {
         $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
         $page_output->addScriptFile('passphrase.js', 'imp');
     }
     $params = isset($this->_params['params']) ? $this->_params['params'] : array();
     if (isset($params['reload'])) {
         $params['reload'] = strval($params['reload']);
     }
     switch ($this->_params['type']) {
         case 'pgpPersonal':
             $text = _("Enter your personal PGP passphrase.");
             break;
         case 'pgpSymmetric':
             $text = _("Enter the passphrase used to encrypt this message.");
             break;
         case 'smimePersonal':
             $text = _("Enter your personal S/MIME passphrase.");
             break;
     }
     $js_params = array('hidden' => array_merge($params, array('type' => $this->_params['type'])), 'text' => $text);
     $js = 'ImpPassphraseDialog.display(' . Horde::escapeJson($js_params, array('nodelimit' => true)) . ')';
     if (!empty($this->_params['onload'])) {
         $page_output->addInlineScript(array($js), true);
         return false;
     }
     return $js;
 }
All Usage Examples Of Horde::escapeJson