| 1 |
<?php |
|---|
| 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 |
function tag($name, $options = array(), $open = false) |
|---|
| 31 |
{ |
|---|
| 32 |
if (!$name) |
|---|
| 33 |
{ |
|---|
| 34 |
return ''; |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
return '<'.$name._tag_options($options).(($open) ? '>' : ' />'); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
function content_tag($name, $content = '', $options = array()) |
|---|
| 41 |
{ |
|---|
| 42 |
if (!$name) |
|---|
| 43 |
{ |
|---|
| 44 |
return ''; |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
return '<'.$name._tag_options($options).'>'.$content.'</'.$name.'>'; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
function cdata_section($content) |
|---|
| 51 |
{ |
|---|
| 52 |
return "<![CDATA[$content]]>"; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
function escape_javascript($javascript = '') |
|---|
| 59 |
{ |
|---|
| 60 |
$javascript = preg_replace('/\r\n|\n|\r/', "\\n", $javascript); |
|---|
| 61 |
$javascript = preg_replace('/(["\'])/', '\\\\\1', $javascript); |
|---|
| 62 |
|
|---|
| 63 |
return $javascript; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
function escape_once($html) |
|---|
| 73 |
{ |
|---|
| 74 |
return fix_double_escape(htmlspecialchars($html, ENT_COMPAT, sfConfig::get('sf_charset'))); |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
function fix_double_escape($escaped) |
|---|
| 84 |
{ |
|---|
| 85 |
return preg_replace('/&([a-z]+|(#\d+)|(#x[\da-f]+));/i', '&$1;', $escaped); |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
function _tag_options($options = array()) |
|---|
| 89 |
{ |
|---|
| 90 |
$options = _parse_attributes($options); |
|---|
| 91 |
|
|---|
| 92 |
$html = ''; |
|---|
| 93 |
foreach ($options as $key => $value) |
|---|
| 94 |
{ |
|---|
| 95 |
$html .= ' '.$key.'="'.escape_once($value).'"'; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
return $html; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
function _parse_attributes($string) |
|---|
| 102 |
{ |
|---|
| 103 |
return is_array($string) ? $string : sfToolkit::stringToArray($string); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
function _get_option(&$options, $name, $default = null) |
|---|
| 107 |
{ |
|---|
| 108 |
if (array_key_exists($name, $options)) |
|---|
| 109 |
{ |
|---|
| 110 |
$value = $options[$name]; |
|---|
| 111 |
unset($options[$name]); |
|---|
| 112 |
} |
|---|
| 113 |
else |
|---|
| 114 |
{ |
|---|
| 115 |
$value = $default; |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
return $value; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|