Ticket #5181: prep_content.2.patch

File prep_content.2.patch, 5.2 kB (added by rubys, 11 months ago)

s/prep_content/prep_atom_text_construct/

  • wp-includes/feed-atom.php

    old new  
    3030                        <uri><?php the_author_url()?></uri> 
    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> 
    3637                <updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated> 
    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(); ?> 
    4447<?php do_action('atom_entry'); ?> 
  • wp-includes/feed.php

    old new  
    250250        } 
    251251} 
    252252 
     253function prep_atom_text_construct($data) { 
     254        if (strpos($data, '<') === false && strpos($data, '&') === false) { 
     255                return array('text', $data); 
     256        } 
     257 
     258        $parser = xml_parser_create(); 
     259        xml_parse($parser, '<div>' . $data . '</div>', true); 
     260        $code = xml_get_error_code($parser); 
     261        xml_parser_free($parser); 
     262 
     263        if (!$code) { 
     264                       if (strpos($data, '<') === false) { 
     265                               return array('text', $data); 
     266                       } else { 
     267                               $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>"; 
     268                               return array('xhtml', $data); 
     269                       } 
     270        } 
     271 
     272        if (strpos($data, ']]>') == false) { 
     273                return array('html', "<![CDATA[$data]]>"); 
     274        } else { 
     275                return array('html', htmlspecialchars($data)); 
     276        } 
     277} 
     278 
    253279?> 
  • wp-app.php

    old new  
    1212require_once('./wp-config.php'); 
    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'] ); 
    1718 
     
    784785<entry xmlns="<?php echo $this->ATOM_NS ?>" 
    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> 
    790791        <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> 
     
    805806<?php } else { ?> 
    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; ?> 
    811812<?php } ?> 
     
    813814<?php foreach(get_the_category() as $category) { ?> 
    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 } 
    820821 
    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         } 
    846  
    847822        function ok() { 
    848823                log_app('Status','200: OK'); 
    849824                header('Content-Type: text/plain');