mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Refactor atom support to share code. Fixes #5181 props rubys
git-svn-id: https://develop.svn.wordpress.org/trunk@6273 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -250,4 +250,46 @@ function atom_enclosure() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prep_atom_text_construct() - determine if given string of data is
|
||||
* type text, html, or xhtml, per RFC 4287 section 3.1.
|
||||
*
|
||||
* In the case of WordPress, text is defined as containing no markup,
|
||||
* xhtml is defined as "well formed", and html as tag soup (i.e., the rest).
|
||||
*
|
||||
* Container div tags are added to xhtml values, per section 3.1.1.3.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Feed
|
||||
*
|
||||
* @param string $data input string
|
||||
* @return array $result array(type, value)
|
||||
* @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
|
||||
*/
|
||||
function prep_atom_text_construct($data) {
|
||||
if (strpos($data, '<') === false && strpos($data, '&') === false) {
|
||||
return array('text', $data);
|
||||
}
|
||||
|
||||
$parser = xml_parser_create();
|
||||
xml_parse($parser, '<div>' . $data . '</div>', true);
|
||||
$code = xml_get_error_code($parser);
|
||||
xml_parser_free($parser);
|
||||
|
||||
if (!$code) {
|
||||
if (strpos($data, '<') === false) {
|
||||
return array('text', $data);
|
||||
} else {
|
||||
$data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
|
||||
return array('xhtml', $data);
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($data, ']]>') == false) {
|
||||
return array('html', "<![CDATA[$data]]>");
|
||||
} else {
|
||||
return array('html', htmlspecialchars($data));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user