mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-18 00:25:37 +01:00
cc5ed3a485
The exceptions to this are update_post_meta() and add_post_meta() which are often used by plugins in POST handlers and will continue accepting slashed data for now. Introduce wp_upate_post_meta() and wp_add_post_meta() as unslashed alternatives to update_post_meta() and add_post_meta(). These functions could become methods in WP_Post so don't use them too heavily yet. Remove all escape() calls from wp_xmlrpc_server. Now that core expects unslashed data this is no longer needed. Remove addslashes(), addslashes_gpc(), add_magic_quotes() calls on data being prepared for handoff to core functions that until now expected slashed data. Adding slashes in no longer necessary. Introduce wp_unslash() and use to it remove slashes from GPCS data before using it in core API. Almost every instance of stripslashes() in core should now be wp_unslash(). In the future (a release or three) when GPCS is no longer slashed, wp_unslash() will stop stripping slashes and simply return what is passed. At this point wp_unslash() calls can be removed from core. Introduce wp_slash() for slashing GPCS data. This will also turn into a noop once GPCS is no longer slashed. wp_slash() should almost never be used. It is mainly of use in unit tests. Plugins should use wp_unslash() on data being passed to core API. Plugins should no longer slash data being passed to core. So when you get_post() and then wp_insert_post() the post data from get_post() no longer needs addslashes(). Most plugins were not bothering with this. They will magically start doing the right thing. Unfortunately, those few souls who did it properly will now have to avoid calling addslashes() for 3.6 and newer. Use wp_kses_post() and wp_kses_data(), which expect unslashed data, instead of wp_filter_post_kses() and wp_filter_kses(), which expect slashed data. Filters are no longer passed slashed data. Remove many no longer necessary calls to $wpdb->escape() and esc_sql(). In wp_get_referer() and wp_get_original_referer(), return unslashed data. Remove old stripslashes() calls from WP_Widget::update() handlers. These haven't been necessary since WP_Widget. Switch several queries over to prepare(). Expect something to break. Props alexkingorg see #21767 git-svn-id: http://core.svn.wordpress.org/trunk@23416 1a063a9b-81f0-0310-95a4-ce76da25c4cd
106 lines
3.4 KiB
PHP
106 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* Handle Trackbacks and Pingbacks sent to WordPress
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
if (empty($wp)) {
|
|
require_once('./wp-load.php');
|
|
wp( array( 'tb' => '1' ) );
|
|
}
|
|
|
|
/**
|
|
* trackback_response() - Respond with error or success XML message
|
|
*
|
|
* @param int|bool $error Whether there was an error
|
|
* @param string $error_message Error message if an error occurred
|
|
*/
|
|
function trackback_response($error = 0, $error_message = '') {
|
|
header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
|
|
if ($error) {
|
|
echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
|
|
echo "<response>\n";
|
|
echo "<error>1</error>\n";
|
|
echo "<message>$error_message</message>\n";
|
|
echo "</response>";
|
|
die();
|
|
} else {
|
|
echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
|
|
echo "<response>\n";
|
|
echo "<error>0</error>\n";
|
|
echo "</response>";
|
|
}
|
|
}
|
|
|
|
// trackback is done by a POST
|
|
$request_array = 'HTTP_POST_VARS';
|
|
|
|
if ( !isset($_GET['tb_id']) || !$_GET['tb_id'] ) {
|
|
$tb_id = explode('/', $_SERVER['REQUEST_URI']);
|
|
$tb_id = intval( $tb_id[ count($tb_id) - 1 ] );
|
|
}
|
|
|
|
$tb_url = isset($_POST['url']) ? $_POST['url'] : '';
|
|
$charset = isset($_POST['charset']) ? $_POST['charset'] : '';
|
|
|
|
// These three are stripslashed here so that they can be properly escaped after mb_convert_encoding()
|
|
$title = isset($_POST['title']) ? wp_unslash( $_POST['title'] ) : '';
|
|
$excerpt = isset($_POST['excerpt']) ? wp_unslash( $_POST['excerpt'] ) : '';
|
|
$blog_name = isset($_POST['blog_name']) ? wp_unslash( $_POST['blog_name'] ) : '';
|
|
|
|
if ($charset)
|
|
$charset = str_replace( array(',', ' '), '', strtoupper( trim($charset) ) );
|
|
else
|
|
$charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
|
|
|
|
// No valid uses for UTF-7
|
|
if ( false !== strpos($charset, 'UTF-7') )
|
|
die;
|
|
|
|
if ( function_exists('mb_convert_encoding') ) { // For international trackbacks
|
|
$title = mb_convert_encoding($title, get_option('blog_charset'), $charset);
|
|
$excerpt = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset);
|
|
$blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset);
|
|
}
|
|
|
|
if ( is_single() || is_page() )
|
|
$tb_id = $posts[0]->ID;
|
|
|
|
if ( !isset($tb_id) || !intval( $tb_id ) )
|
|
trackback_response(1, 'I really need an ID for this to work.');
|
|
|
|
if (empty($title) && empty($tb_url) && empty($blog_name)) {
|
|
// If it doesn't look like a trackback at all...
|
|
wp_redirect(get_permalink($tb_id));
|
|
exit;
|
|
}
|
|
|
|
if ( !empty($tb_url) && !empty($title) ) {
|
|
header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
|
|
|
|
if ( !pings_open($tb_id) )
|
|
trackback_response(1, 'Sorry, trackbacks are closed for this item.');
|
|
|
|
$title = wp_html_excerpt( $title, 250 ).'...';
|
|
$excerpt = wp_html_excerpt( $excerpt, 252 ).'...';
|
|
|
|
$comment_post_ID = (int) $tb_id;
|
|
$comment_author = $blog_name;
|
|
$comment_author_email = '';
|
|
$comment_author_url = $tb_url;
|
|
$comment_content = "<strong>$title</strong>\n\n$excerpt";
|
|
$comment_type = 'trackback';
|
|
|
|
$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) );
|
|
if ( $dupe )
|
|
trackback_response(1, 'We already have a ping from that URL for this post.');
|
|
|
|
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
|
|
|
|
wp_new_comment($commentdata);
|
|
|
|
do_action('trackback_post', $wpdb->insert_id);
|
|
trackback_response(0);
|
|
}
|