Skip to content

Commit

Permalink
Refactor atom support to share code. Fixes #5181 props rubys
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.automattic.com/wordpress/trunk@6273 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
westi committed Oct 19, 2007
1 parent c5dd16d commit 4c7bfb6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 32 deletions.
33 changes: 4 additions & 29 deletions wp-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require_once('./wp-config.php');
require_once(ABSPATH . WPINC . '/post-template.php');
require_once(ABSPATH . WPINC . '/atomlib.php');
require_once(ABSPATH . WPINC . '/feed.php');

$_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );

Expand Down Expand Up @@ -784,7 +785,7 @@ function echo_entry() { ?>
<entry xmlns="<?php echo $this->ATOM_NS ?>"
xmlns:app="<?php echo $this->ATOMPUB_NS ?>" xml:lang="<?php echo get_option('rss_language'); ?>">
<id><?php the_guid($GLOBALS['post']->ID); ?></id>
<?php list($content_type, $content) = $this->prep_content(get_the_title()); ?>
<?php list($content_type, $content) = prep_atom_text_construct(get_the_title()); ?>
<title type="<?php echo $content_type ?>"><?php echo $content ?></title>
<updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated>
<published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published>
Expand All @@ -805,45 +806,19 @@ function echo_entry() { ?>
<?php } else { ?>
<link href="<?php the_permalink_rss() ?>" />
<?php if ( strlen( $GLOBALS['post']->post_content ) ) :
list($content_type, $content) = $this->prep_content(get_the_content()); ?>
list($content_type, $content) = prep_atom_text_construct(get_the_content()); ?>
<content type="<?php echo $content_type ?>"><?php echo $content ?></content>
<?php endif; ?>
<?php } ?>
<link rel="edit" href="<?php $this->the_entry_url() ?>" />
<?php foreach(get_the_category() as $category) { ?>
<category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->name?>" />
<?php } ?>
<?php list($content_type, $content) = $this->prep_content(get_the_excerpt()); ?>
<?php list($content_type, $content) = prep_atom_text_construct(get_the_excerpt()); ?>
<summary type="<?php echo $content_type ?>"><?php echo $content ?></summary>
</entry>
<?php }

function prep_content($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));
}
}

function ok() {
log_app('Status','200: OK');
header('Content-Type: text/plain');
Expand Down
9 changes: 6 additions & 3 deletions wp-includes/feed-atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@
<uri><?php the_author_url()?></uri>
<?php endif; ?>
</author>
<title type="<?php html_type_rss(); ?>"><![CDATA[<?php the_title_rss() ?>]]></title>
<?php list($content_type, $content) = prep_atom_text_construct(get_the_title()); ?>
<title type="<?php echo $content_type ?>"><?php echo $content ?></title>
<link rel="alternate" type="text/html" href="<?php the_permalink_rss() ?>" />
<id><?php the_guid(); ?></id>
<updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated>
<published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published>
<?php the_category_rss('atom') ?>
<summary type="<?php html_type_rss(); ?>"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary>
<?php list($content_type, $content) = prep_atom_text_construct(get_the_excerpt()); ?>
<summary type="<?php echo $content_type ?>"><?php echo $content ?></summary>
<?php if ( !get_option('rss_use_excerpt') ) : ?>
<content type="<?php html_type_rss(); ?>" xml:base="<?php the_permalink_rss() ?>"><![CDATA[<?php the_content('', 0, '') ?>]]></content>
<?php list($content_type, $content) = prep_atom_text_construct(get_the_content()); ?>
<content type="<?php echo $content_type ?>" xml:base="<?php the_permalink_rss()?>"><?php echo $content ?></content>
<?php endif; ?>
<?php atom_enclosure(); ?>
<?php do_action('atom_entry'); ?>
Expand Down
42 changes: 42 additions & 0 deletions wp-includes/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

?>

0 comments on commit 4c7bfb6

Please sign in to comment.