\\ $escaped = str_replace('"', '\"', $escaped); // escaping quotes: " => \" $escaped = str_replace("\n", '\n', $escaped); // changing LF to '\n' string $escaped = str_replace('\'', '\\\'', $escaped); // escaping single quotes: ' => \' $escaped = str_replace('/', '\/', $escaped); // escaping forward slash: / => \/ if ($addQuotes) { $escaped = "'".$escaped."'"; } return $escaped; } elseif (is_null($value)) { return 'null'; } elseif (is_bool($value)) { return ($value) ? 'true' : 'false'; } else { return strval($value); } } elseif (count($value) == 0) { return $as_object ? '{}' : '[]'; } $is_object = $as_object; foreach ($value as $key => &$v) { if (is_string($key)) { $is_object = true; } $escaped_key = $is_object ? '"'.zbx_jsvalue($key, false, false).'":' : ''; $v = $escaped_key.zbx_jsvalue($v, $as_object, $addQuotes); } unset($v); return $is_object ? '{'.implode(',', $value).'}' : '['.implode(',', $value).']'; } function insert_js($script, $jQueryDocumentReady = false) { echo get_js($script, $jQueryDocumentReady); } function get_js($script, $jQueryDocumentReady = false) { return $jQueryDocumentReady ? '' : ''; } // add JavaScript for calling after page loading function zbx_add_post_js($script) { global $ZBX_PAGE_POST_JS; if ($ZBX_PAGE_POST_JS === null) { $ZBX_PAGE_POST_JS = []; } if (!in_array($script, $ZBX_PAGE_POST_JS)) { $ZBX_PAGE_POST_JS[] = $script; } } function insertPagePostJs($jQueryDocumentReady = false) { global $ZBX_PAGE_POST_JS; if ($ZBX_PAGE_POST_JS) { echo get_js(implode("\n", $ZBX_PAGE_POST_JS), $jQueryDocumentReady); } } function getPagePostJs() { global $ZBX_PAGE_POST_JS; if ($ZBX_PAGE_POST_JS) { return implode("\n", $ZBX_PAGE_POST_JS); } return ''; }