| | 253 | /** |
|---|
| | 254 | * prep_atom_text_construct() - determine if given string of data is |
|---|
| | 255 | * type text, html, or xhtml, per RFC 4287 section 3.1. |
|---|
| | 256 | * |
|---|
| | 257 | * In the case of WordPress, text is defined as containing no markup, |
|---|
| | 258 | * xhtml is defined as "well formed", and html as tag soup (i.e., the rest). |
|---|
| | 259 | * |
|---|
| | 260 | * Container div tags are added to xhtml values, per section 3.1.1.3. |
|---|
| | 261 | * |
|---|
| | 262 | * @package WordPress |
|---|
| | 263 | * @subpackage Feed |
|---|
| | 264 | * |
|---|
| | 265 | * @param string $data input string |
|---|
| | 266 | * @return array $result array(type, value) |
|---|
| | 267 | * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1 |
|---|
| | 268 | */ |
|---|
| | 269 | function prep_atom_text_construct($data) { |
|---|
| | 270 | if (strpos($data, '<') === false && strpos($data, '&') === false) { |
|---|
| | 271 | return array('text', $data); |
|---|
| | 272 | } |
|---|
| | 273 | |
|---|
| | 274 | $parser = xml_parser_create(); |
|---|
| | 275 | xml_parse($parser, '<div>' . $data . '</div>', true); |
|---|
| | 276 | $code = xml_get_error_code($parser); |
|---|
| | 277 | xml_parser_free($parser); |
|---|
| | 278 | |
|---|
| | 279 | if (!$code) { |
|---|
| | 280 | if (strpos($data, '<') === false) { |
|---|
| | 281 | return array('text', $data); |
|---|
| | 282 | } else { |
|---|
| | 283 | $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>"; |
|---|
| | 284 | return array('xhtml', $data); |
|---|
| | 285 | } |
|---|
| | 286 | } |
|---|
| | 287 | |
|---|
| | 288 | if (strpos($data, ']]>') == false) { |
|---|
| | 289 | return array('html', "<![CDATA[$data]]>"); |
|---|
| | 290 | } else { |
|---|
| | 291 | return array('html', htmlspecialchars($data)); |
|---|
| | 292 | } |
|---|
| | 293 | } |
|---|
| | 294 | |
|---|