WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (3 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-trackback.php

    r42201 r42343  
    99 */
    1010
    11 if (empty($wp)) {
     11if ( empty( $wp ) ) {
    1212    require_once( dirname( __FILE__ ) . '/wp-load.php' );
    1313    wp( array( 'tb' => '1' ) );
     
    2525 * @param string $error_message Error message if an error occurred.
    2626 */
    27 function trackback_response($error = 0, $error_message = '') {
    28     header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
    29     if ($error) {
    30         echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
     27function trackback_response( $error = 0, $error_message = '' ) {
     28    header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) );
     29    if ( $error ) {
     30        echo '<?xml version="1.0" encoding="utf-8"?' . ">\n";
    3131        echo "<response>\n";
    3232        echo "<error>1</error>\n";
    3333        echo "<message>$error_message</message>\n";
    34         echo "</response>";
     34        echo '</response>';
    3535        die();
    3636    } else {
    37         echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
     37        echo '<?xml version="1.0" encoding="utf-8"?' . ">\n";
    3838        echo "<response>\n";
    3939        echo "<error>0</error>\n";
    40         echo "</response>";
     40        echo '</response>';
    4141    }
    4242}
     
    4545$request_array = 'HTTP_POST_VARS';
    4646
    47 if ( !isset($_GET['tb_id']) || !$_GET['tb_id'] ) {
    48     $tb_id = explode('/', $_SERVER['REQUEST_URI']);
    49     $tb_id = intval( $tb_id[ count($tb_id) - 1 ] );
     47if ( ! isset( $_GET['tb_id'] ) || ! $_GET['tb_id'] ) {
     48    $tb_id = explode( '/', $_SERVER['REQUEST_URI'] );
     49    $tb_id = intval( $tb_id[ count( $tb_id ) - 1 ] );
    5050}
    5151
    52 $tb_url  = isset($_POST['url'])     ? $_POST['url']    : '';
    53 $charset = isset($_POST['charset']) ? $_POST['charset'] : '';
     52$tb_url  = isset( $_POST['url'] ) ? $_POST['url'] : '';
     53$charset = isset( $_POST['charset'] ) ? $_POST['charset'] : '';
    5454
    5555// These three are stripslashed here so they can be properly escaped after mb_convert_encoding().
    56 $title     = isset($_POST['title'])     ? wp_unslash($_POST['title'])      : '';
    57 $excerpt   = isset($_POST['excerpt'])   ? wp_unslash($_POST['excerpt'])    : '';
    58 $blog_name = isset($_POST['blog_name']) ? wp_unslash($_POST['blog_name']) : '';
     56$title     = isset( $_POST['title'] ) ? wp_unslash( $_POST['title'] ) : '';
     57$excerpt   = isset( $_POST['excerpt'] ) ? wp_unslash( $_POST['excerpt'] ) : '';
     58$blog_name = isset( $_POST['blog_name'] ) ? wp_unslash( $_POST['blog_name'] ) : '';
    5959
    60 if ($charset)
    61     $charset = str_replace( array(',', ' '), '', strtoupper( trim($charset) ) );
    62 else
     60if ( $charset ) {
     61    $charset = str_replace( array( ',', ' ' ), '', strtoupper( trim( $charset ) ) );
     62} else {
    6363    $charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
     64}
    6465
    6566// No valid uses for UTF-7.
    66 if ( false !== strpos($charset, 'UTF-7') )
     67if ( false !== strpos( $charset, 'UTF-7' ) ) {
    6768    die;
     69}
    6870
    6971// For international trackbacks.
    70 if ( function_exists('mb_convert_encoding') ) {
    71     $title     = mb_convert_encoding($title, get_option('blog_charset'), $charset);
    72     $excerpt   = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset);
    73     $blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset);
     72if ( function_exists( 'mb_convert_encoding' ) ) {
     73    $title     = mb_convert_encoding( $title, get_option( 'blog_charset' ), $charset );
     74    $excerpt   = mb_convert_encoding( $excerpt, get_option( 'blog_charset' ), $charset );
     75    $blog_name = mb_convert_encoding( $blog_name, get_option( 'blog_charset' ), $charset );
    7476}
    7577
    7678// Now that mb_convert_encoding() has been given a swing, we need to escape these three.
    77 $title     = wp_slash($title);
    78 $excerpt   = wp_slash($excerpt);
    79 $blog_name = wp_slash($blog_name);
     79$title     = wp_slash( $title );
     80$excerpt   = wp_slash( $excerpt );
     81$blog_name = wp_slash( $blog_name );
    8082
    81 if ( is_single() || is_page() )
     83if ( is_single() || is_page() ) {
    8284    $tb_id = $posts[0]->ID;
     85}
    8386
    84 if ( !isset($tb_id) || !intval( $tb_id ) )
     87if ( ! isset( $tb_id ) || ! intval( $tb_id ) ) {
    8588    trackback_response( 1, __( 'I really need an ID for this to work.' ) );
     89}
    8690
    87 if (empty($title) && empty($tb_url) && empty($blog_name)) {
     91if ( empty( $title ) && empty( $tb_url ) && empty( $blog_name ) ) {
    8892    // If it doesn't look like a trackback at all.
    89     wp_redirect(get_permalink($tb_id));
     93    wp_redirect( get_permalink( $tb_id ) );
    9094    exit;
    9195}
    9296
    93 if ( !empty($tb_url) && !empty($title) ) {
     97if ( ! empty( $tb_url ) && ! empty( $title ) ) {
    9498    /**
    95     * Fires before the trackback is added to a post.
    96     *
    97     * @since 4.7.0
    98     *
    99     * @param int    $tb_id     Post ID related to the trackback.
    100     * @param string $tb_url    Trackback URL.
    101     * @param string $charset   Character Set.
    102     * @param string $title     Trackback Title.
    103     * @param string $excerpt   Trackback Excerpt.
    104     * @param string $blog_name Blog Name.
    105     */
     99     * Fires before the trackback is added to a post.
     100     *
     101     * @since 4.7.0
     102     *
     103     * @param int    $tb_id     Post ID related to the trackback.
     104     * @param string $tb_url    Trackback URL.
     105     * @param string $charset   Character Set.
     106     * @param string $title     Trackback Title.
     107     * @param string $excerpt   Trackback Excerpt.
     108     * @param string $blog_name Blog Name.
     109     */
    106110    do_action( 'pre_trackback_post', $tb_id, $tb_url, $charset, $title, $excerpt, $blog_name );
    107111
    108     header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
     112    header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) );
    109113
    110     if ( !pings_open($tb_id) )
     114    if ( ! pings_open( $tb_id ) ) {
    111115        trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) );
     116    }
    112117
    113     $title = wp_html_excerpt( $title, 250, '&#8230;' );
     118    $title   = wp_html_excerpt( $title, 250, '&#8230;' );
    114119    $excerpt = wp_html_excerpt( $excerpt, 252, '&#8230;' );
    115120
    116     $comment_post_ID = (int) $tb_id;
    117     $comment_author = $blog_name;
     121    $comment_post_ID      = (int) $tb_id;
     122    $comment_author       = $blog_name;
    118123    $comment_author_email = '';
    119     $comment_author_url = $tb_url;
    120     $comment_content = "<strong>$title</strong>\n\n$excerpt";
    121     $comment_type = 'trackback';
     124    $comment_author_url   = $tb_url;
     125    $comment_content      = "<strong>$title</strong>\n\n$excerpt";
     126    $comment_type         = 'trackback';
    122127
    123     $dupe = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) );
    124     if ( $dupe )
     128    $dupe = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url ) );
     129    if ( $dupe ) {
    125130        trackback_response( 1, __( 'We already have a ping from that URL for this post.' ) );
     131    }
    126132
    127     $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
     133    $commentdata = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type' );
    128134
    129135    $result = wp_new_comment( $commentdata );
Note: See TracChangeset for help on using the changeset viewer.