Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/feed.php

    r42260 r42343  
    2424 * @return string
    2525 */
    26 function get_bloginfo_rss($show = '') {
    27     $info = strip_tags(get_bloginfo($show));
     26function get_bloginfo_rss( $show = '' ) {
     27    $info = strip_tags( get_bloginfo( $show ) );
    2828    /**
    2929     * Filters the bloginfo for use in RSS feeds.
     
    5252 * @param string $show See get_bloginfo() for possible values.
    5353 */
    54 function bloginfo_rss($show = '') {
     54function bloginfo_rss( $show = '' ) {
    5555    /**
    5656     * Filters the bloginfo for display in RSS feeds.
     
    183183 * @return string The filtered content.
    184184 */
    185 function get_the_content_feed($feed_type = null) {
    186     if ( !$feed_type )
     185function get_the_content_feed( $feed_type = null ) {
     186    if ( ! $feed_type ) {
    187187        $feed_type = get_default_feed();
     188    }
    188189
    189190    /** This filter is documented in wp-includes/post-template.php */
    190191    $content = apply_filters( 'the_content', get_the_content() );
    191     $content = str_replace(']]>', ']]>', $content);
     192    $content = str_replace( ']]>', ']]>', $content );
    192193    /**
    193194     * Filters the post content for use in feeds.
     
    209210 * @param string $feed_type The type of feed. rss2 | atom | rss | rdf
    210211 */
    211 function the_content_feed($feed_type = null) {
    212     echo get_the_content_feed($feed_type);
     212function the_content_feed( $feed_type = null ) {
     213    echo get_the_content_feed( $feed_type );
    213214}
    214215
     
    271272 * @param int|WP_Comment $comment_id Optional comment object or id. Defaults to global comment object.
    272273 */
    273 function comment_guid($comment_id = null) {
    274     echo esc_url( get_comment_guid($comment_id) );
     274function comment_guid( $comment_id = null ) {
     275    echo esc_url( get_comment_guid( $comment_id ) );
    275276}
    276277
     
    283284 * @return false|string false on failure or guid for comment on success.
    284285 */
    285 function get_comment_guid($comment_id = null) {
    286     $comment = get_comment($comment_id);
    287 
    288     if ( !is_object($comment) )
     286function get_comment_guid( $comment_id = null ) {
     287    $comment = get_comment( $comment_id );
     288
     289    if ( ! is_object( $comment ) ) {
    289290        return false;
    290 
    291     return get_the_guid($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
     291    }
     292
     293    return get_the_guid( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
    292294}
    293295
     
    372374 * @return string All of the post categories for displaying in the feed.
    373375 */
    374 function get_the_category_rss($type = null) {
    375     if ( empty($type) )
     376function get_the_category_rss( $type = null ) {
     377    if ( empty( $type ) ) {
    376378        $type = get_default_feed();
     379    }
    377380    $categories = get_the_category();
    378     $tags = get_the_tags();
    379     $the_list = '';
    380     $cat_names = array();
     381    $tags       = get_the_tags();
     382    $the_list   = '';
     383    $cat_names  = array();
    381384
    382385    $filter = 'rss';
    383     if ( 'atom' == $type )
     386    if ( 'atom' == $type ) {
    384387        $filter = 'raw';
    385 
    386     if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
    387         $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
    388     }
    389 
    390     if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
    391         $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
    392     }
    393 
    394     $cat_names = array_unique($cat_names);
     388    }
     389
     390    if ( ! empty( $categories ) ) {
     391        foreach ( (array) $categories as $category ) {
     392            $cat_names[] = sanitize_term_field( 'name', $category->name, $category->term_id, 'category', $filter );
     393        }
     394    }
     395
     396    if ( ! empty( $tags ) ) {
     397        foreach ( (array) $tags as $tag ) {
     398            $cat_names[] = sanitize_term_field( 'name', $tag->name, $tag->term_id, 'post_tag', $filter );
     399        }
     400    }
     401
     402    $cat_names = array_unique( $cat_names );
    395403
    396404    foreach ( $cat_names as $cat_name ) {
    397         if ( 'rdf' == $type )
     405        if ( 'rdf' == $type ) {
    398406            $the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
    399         elseif ( 'atom' == $type )
     407        } elseif ( 'atom' == $type ) {
    400408            $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) );
    401         else
    402             $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n";
     409        } else {
     410            $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option( 'blog_charset' ) ) . "]]></category>\n";
     411        }
    403412    }
    404413
     
    423432 * @param string $type Optional, default is the type returned by get_default_feed().
    424433 */
    425 function the_category_rss($type = null) {
    426     echo get_the_category_rss($type);
     434function the_category_rss( $type = null ) {
     435    echo get_the_category_rss( $type );
    427436}
    428437
     
    435444 */
    436445function html_type_rss() {
    437     $type = get_bloginfo('html_type');
    438     if (strpos($type, 'xhtml') !== false)
     446    $type = get_bloginfo( 'html_type' );
     447    if ( strpos( $type, 'xhtml' ) !== false ) {
    439448        $type = 'xhtml';
    440     else
     449    } else {
    441450        $type = 'html';
     451    }
    442452    echo $type;
    443453}
     
    458468 */
    459469function rss_enclosure() {
    460     if ( post_password_required() )
     470    if ( post_password_required() ) {
    461471        return;
    462 
    463     foreach ( (array) get_post_custom() as $key => $val) {
    464         if ($key == 'enclosure') {
     472    }
     473
     474    foreach ( (array) get_post_custom() as $key => $val ) {
     475        if ( $key == 'enclosure' ) {
    465476            foreach ( (array) $val as $enc ) {
    466                 $enclosure = explode("\n", $enc);
     477                $enclosure = explode( "\n", $enc );
    467478
    468479                // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3'
    469                 $t = preg_split('/[ \t]/', trim($enclosure[2]) );
     480                $t    = preg_split( '/[ \t]/', trim( $enclosure[2] ) );
    470481                $type = $t[0];
    471482
     
    497508 */
    498509function atom_enclosure() {
    499     if ( post_password_required() )
     510    if ( post_password_required() ) {
    500511        return;
     512    }
    501513
    502514    foreach ( (array) get_post_custom() as $key => $val ) {
    503         if ($key == 'enclosure') {
     515        if ( $key == 'enclosure' ) {
    504516            foreach ( (array) $val as $enc ) {
    505                 $enclosure = explode("\n", $enc);
     517                $enclosure = explode( "\n", $enc );
    506518                /**
    507519                 * Filters the atom enclosure HTML link tag for the current post.
     
    534546 * @return array array(type, value)
    535547 */
    536 function prep_atom_text_construct($data) {
    537     if (strpos($data, '<') === false && strpos($data, '&') === false) {
    538         return array('text', $data);
     548function prep_atom_text_construct( $data ) {
     549    if ( strpos( $data, '<' ) === false && strpos( $data, '&' ) === false ) {
     550        return array( 'text', $data );
    539551    }
    540552
     
    546558
    547559    $parser = xml_parser_create();
    548     xml_parse($parser, '<div>' . $data . '</div>', true);
    549     $code = xml_get_error_code($parser);
    550     xml_parser_free($parser);
    551 
    552     if (!$code) {
    553         if (strpos($data, '<') === false) {
    554             return array('text', $data);
     560    xml_parse( $parser, '<div>' . $data . '</div>', true );
     561    $code = xml_get_error_code( $parser );
     562    xml_parser_free( $parser );
     563
     564    if ( ! $code ) {
     565        if ( strpos( $data, '<' ) === false ) {
     566            return array( 'text', $data );
    555567        } else {
    556568            $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
    557             return array('xhtml', $data);
     569            return array( 'xhtml', $data );
    558570        }
    559571    }
    560572
    561     if (strpos($data, ']]>') === false) {
    562         return array('html', "<![CDATA[$data]]>");
     573    if ( strpos( $data, ']]>' ) === false ) {
     574        return array( 'html', "<![CDATA[$data]]>" );
    563575    } else {
    564         return array('html', htmlspecialchars($data));
     576        return array( 'html', htmlspecialchars( $data ) );
    565577    }
    566578}
     
    612624 */
    613625function self_link() {
    614     $host = @parse_url(home_url());
     626    $host = @parse_url( home_url() );
    615627    /**
    616628     * Filters the current feed URL.
     
    634646 */
    635647function feed_content_type( $type = '' ) {
    636     if ( empty($type) )
     648    if ( empty( $type ) ) {
    637649        $type = get_default_feed();
     650    }
    638651
    639652    $types = array(
     
    642655        'rss-http' => 'text/xml',
    643656        'atom'     => 'application/atom+xml',
    644         'rdf'      => 'application/rdf+xml'
     657        'rdf'      => 'application/rdf+xml',
    645658    );
    646659
    647     $content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream';
     660    $content_type = ( ! empty( $types[ $type ] ) ) ? $types[ $type ] : 'application/octet-stream';
    648661
    649662    /**
     
    704717    $feed->set_output_encoding( get_option( 'blog_charset' ) );
    705718
    706     if ( $feed->error() )
     719    if ( $feed->error() ) {
    707720        return new WP_Error( 'simplepie-error', $feed->error() );
     721    }
    708722
    709723    return $feed;
Note: See TracChangeset for help on using the changeset viewer.