-
Notifications
You must be signed in to change notification settings - Fork 5
/
block.jstring.php
41 lines (40 loc) · 1015 Bytes
/
block.jstring.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Smarty block plugin
*
* @package Atk14\Helpers
*/
/**
* Smarty block plugin
*
* Escapes string for use in javascript.
* Output string is surrounded with quotes.
*
* ```
* <script type="text/javascript">
* var message={jstring}Zprava pro tebe: {render partial="message"}{/jstring};
* </script>
* ```
*
* @param array $params parameters
* - escape string escaping mode
* - html escape some html code
* @param string $content string to be escaped
* @param Smarty_Internal_Template $template
* @param boolean &$repeat repeat flag
*
* @return string escaped string
*/
function smarty_block_jstring($params,$content,$template,&$repeat){
if($repeat){ return; }
$params = array_merge(array(
"escape" => ""
),$params);
$content = Atk14Utils::EscapeForJavascript($content);
if($params["escape"] == "html"){
$content = str_replace("<","<",$content);
$content = str_replace(">",">",$content);
$content = str_replace("&","&",$content);
}
return '"'.$content.'"';
}