Make WordPress Core

Changeset 6273


Ignore:
Timestamp:
10/19/2007 03:42:30 PM (18 years ago)
Author:
westi
Message:

Refactor atom support to share code. Fixes #5181 props rubys

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-app.php

    r6229 r6273  
    1313require_once(ABSPATH . WPINC . '/post-template.php');
    1414require_once(ABSPATH . WPINC . '/atomlib.php');
     15require_once(ABSPATH . WPINC . '/feed.php');
    1516
    1617$_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );
     
    785786       xmlns:app="<?php echo $this->ATOMPUB_NS ?>" xml:lang="<?php echo get_option('rss_language'); ?>">
    786787    <id><?php the_guid($GLOBALS['post']->ID); ?></id>
    787 <?php list($content_type, $content) = $this->prep_content(get_the_title()); ?>
     788<?php list($content_type, $content) = prep_atom_text_construct(get_the_title()); ?>
    788789    <title type="<?php echo $content_type ?>"><?php echo $content ?></title>
    789790    <updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated>
     
    806807    <link href="<?php the_permalink_rss() ?>" />
    807808<?php if ( strlen( $GLOBALS['post']->post_content ) ) :
    808 list($content_type, $content) = $this->prep_content(get_the_content()); ?>
     809list($content_type, $content) = prep_atom_text_construct(get_the_content()); ?>
    809810    <content type="<?php echo $content_type ?>"><?php echo $content ?></content>
    810811<?php endif; ?>
     
    814815    <category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->name?>" />
    815816<?php } ?>
    816 <?php list($content_type, $content) = $this->prep_content(get_the_excerpt()); ?>
     817<?php list($content_type, $content) = prep_atom_text_construct(get_the_excerpt()); ?>
    817818    <summary type="<?php echo $content_type ?>"><?php echo $content ?></summary>
    818819</entry>
    819820<?php }
    820 
    821     function prep_content($data) {
    822         if (strpos($data, '<') === false && strpos($data, '&') === false) {
    823             return array('text', $data);
    824         }
    825 
    826         $parser = xml_parser_create();
    827         xml_parse($parser, '<div>' . $data . '</div>', true);
    828         $code = xml_get_error_code($parser);
    829         xml_parser_free($parser);
    830 
    831         if (!$code) {
    832                 if (strpos($data, '<') === false) {
    833                     return array('text', $data);
    834                         } else {
    835                     $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
    836                     return array('xhtml', $data);
    837                         }
    838         }
    839 
    840         if (strpos($data, ']]>') == false) {
    841             return array('html', "<![CDATA[$data]]>");
    842         } else {
    843             return array('html', htmlspecialchars($data));
    844         }
    845     }
    846821
    847822    function ok() {
  • trunk/wp-includes/feed-atom.php

    r6195 r6273  
    3131            <?php endif; ?>
    3232        </author>
    33         <title type="<?php html_type_rss(); ?>"><![CDATA[<?php the_title_rss() ?>]]></title>
     33<?php list($content_type, $content) = prep_atom_text_construct(get_the_title()); ?>
     34            <title type="<?php echo $content_type ?>"><?php echo $content ?></title>
    3435        <link rel="alternate" type="text/html" href="<?php the_permalink_rss() ?>" />
    3536        <id><?php the_guid(); ?></id>
     
    3738        <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published>
    3839        <?php the_category_rss('atom') ?>
    39         <summary type="<?php html_type_rss(); ?>"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary>
     40<?php list($content_type, $content) = prep_atom_text_construct(get_the_excerpt()); ?>
     41            <summary type="<?php echo $content_type ?>"><?php echo $content ?></summary>
    4042<?php if ( !get_option('rss_use_excerpt') ) : ?>
    41         <content type="<?php html_type_rss(); ?>" xml:base="<?php the_permalink_rss() ?>"><![CDATA[<?php the_content('', 0, '') ?>]]></content>
     43<?php list($content_type, $content) = prep_atom_text_construct(get_the_content()); ?>
     44            <content type="<?php echo $content_type ?>" xml:base="<?php the_permalink_rss()?>"><?php echo $content ?></content>
    4245<?php endif; ?>
    4346<?php atom_enclosure(); ?>
  • trunk/wp-includes/feed.php

    r6125 r6273  
    251251}
    252252
     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 */
     269function 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
    253295?>
Note: See TracChangeset for help on using the changeset viewer.