| 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 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
function get_id_from_name($name, $value = null) |
|---|
| 144 |
{ |
|---|
| 145 |
|
|---|
| 146 |
if (strstr($name, '[')) |
|---|
| 147 |
{ |
|---|
| 148 |
$name = str_replace(array('[]', '][', '[', ']'), array((($value != null) ? '_'.$value : ''), '_', '_', ''), $name); |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
return $name; |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
function _convert_options($options) |
|---|
| 161 |
{ |
|---|
| 162 |
$options = _parse_attributes($options); |
|---|
| 163 |
|
|---|
| 164 |
foreach (array('disabled', 'readonly', 'multiple') as $attribute) |
|---|
| 165 |
{ |
|---|
| 166 |
if (array_key_exists($attribute, $options)) |
|---|
| 167 |
{ |
|---|
| 168 |
if ($options[$attribute]) |
|---|
| 169 |
{ |
|---|
| 170 |
$options[$attribute] = $attribute; |
|---|
| 171 |
} |
|---|
| 172 |
else |
|---|
| 173 |
{ |
|---|
| 174 |
unset($options[$attribute]); |
|---|
| 175 |
} |
|---|
| 176 |
} |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
return $options; |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|