Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 111 lines (90 sloc) 3.434 kb
43e4a8a The great renaming.
saxmatt authored
1 <?php
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
2 /**
3 * Handle Trackbacks and Pingbacks sent to WordPress
4 *
5 * @package WordPress
6 */
75d9746 Trackback fix ups.
rboren authored
7
1baf503 Break blog header up into functional chunks. Stick it all in a WP class...
ryan authored
8 if (empty($wp)) {
5b81135 Allow wp-config.php to exist one level up from WordPress root directory....
ryan authored
9 require_once('./wp-load.php');
1baf503 Break blog header up into functional chunks. Stick it all in a WP class...
ryan authored
10 wp('tb=1');
75d9746 Trackback fix ups.
rboren authored
11 }
12
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
13 /**
14 * trackback_response() - Respond with error or success XML message
15 *
16 * @param int|bool $error Whether there was an error or not
17 * @param string $error_message Error message if an error occurred
18 */
b650b07 Move trackbacks to new comment function.
saxmatt authored
19 function trackback_response($error = 0, $error_message = '') {
20 header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
21 if ($error) {
22 echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
23 echo "<response>\n";
24 echo "<error>1</error>\n";
25 echo "<message>$error_message</message>\n";
26 echo "</response>";
ee856b3 moved die() command, fixes bug #309
michelvaldrighi authored
27 die();
b650b07 Move trackbacks to new comment function.
saxmatt authored
28 } else {
29 echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
30 echo "<response>\n";
31 echo "<error>0</error>\n";
32 echo "</response>";
33 }
34 }
08709cf Non-trackback requests to wp-trackback.php now redirect to the post.
saxmatt authored
35
36 // trackback is done by a POST
37 $request_array = 'HTTP_POST_VARS';
65bbec7 Comments refactoring and cleanup
saxmatt authored
38
68b4b3c Line ending fixes and commenting cleanups from Scott Reilly
matt authored
39 if ( !$_GET['tb_id'] ) {
b650b07 Move trackbacks to new comment function.
saxmatt authored
40 $tb_id = explode('/', $_SERVER['REQUEST_URI']);
68b4b3c Line ending fixes and commenting cleanups from Scott Reilly
matt authored
41 $tb_id = intval( $tb_id[ count($tb_id) - 1 ] );
b650b07 Move trackbacks to new comment function.
saxmatt authored
42 }
65bbec7 Comments refactoring and cleanup
saxmatt authored
43
b737139 Delay Trackback data escaping until after mb_convert_encoding(). Props ...
markjaquith authored
44 $tb_url = $_POST['url'];
45 $charset = $_POST['charset'];
46
47 // These three are stripslashed here so that they can be properly escaped after mb_convert_encoding()
48 $title = stripslashes($_POST['title']);
49 $excerpt = stripslashes($_POST['excerpt']);
50 $blog_name = stripslashes($_POST['blog_name']);
551e52f Code cleanup and some fixes from the WP Japan folks.
saxmatt authored
51
52 if ($charset)
53 $charset = strtoupper( trim($charset) );
54 else
d877c39 Better charset audo-detection - http://mosquito.wordpress.org/view.php?i...
matt authored
55 $charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
551e52f Code cleanup and some fixes from the WP Japan folks.
saxmatt authored
56
121fca1 Drop trackbacks that request UTF-7
ryan authored
57 // No valid uses for UTF-7
58 if ( false !== strpos($charset, 'UTF-7') )
59 die;
60
65bbec7 Comments refactoring and cleanup
saxmatt authored
61 if ( function_exists('mb_convert_encoding') ) { // For international trackbacks
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
62 $title = mb_convert_encoding($title, get_option('blog_charset'), $charset);
63 $excerpt = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset);
64 $blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset);
551e52f Code cleanup and some fixes from the WP Japan folks.
saxmatt authored
65 }
08709cf Non-trackback requests to wp-trackback.php now redirect to the post.
saxmatt authored
66
b737139 Delay Trackback data escaping until after mb_convert_encoding(). Props ...
markjaquith authored
67 // Now that mb_convert_encoding() has been given a swing, we need to escape these three
68 $title = $wpdb->escape($title);
69 $excerpt = $wpdb->escape($excerpt);
70 $blog_name = $wpdb->escape($blog_name);
71
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
72 if ( is_single() || is_page() )
73 $tb_id = $posts[0]->ID;
b650b07 Move trackbacks to new comment function.
saxmatt authored
74
68b4b3c Line ending fixes and commenting cleanups from Scott Reilly
matt authored
75 if ( !intval( $tb_id ) )
b650b07 Move trackbacks to new comment function.
saxmatt authored
76 trackback_response(1, 'I really need an ID for this to work.');
08709cf Non-trackback requests to wp-trackback.php now redirect to the post.
saxmatt authored
77
78 if (empty($title) && empty($tb_url) && empty($blog_name)) {
79 // If it doesn't look like a trackback at all...
ff19f4b Use wp_redirect().
ryan authored
80 wp_redirect(get_permalink($tb_id));
b650b07 Move trackbacks to new comment function.
saxmatt authored
81 exit;
43e4a8a The great renaming.
saxmatt authored
82 }
83
858ba5e Remove redundant check. Props Mittineague. fixes #3665
ryan authored
84 if ( !empty($tb_url) && !empty($title) ) {
b650b07 Move trackbacks to new comment function.
saxmatt authored
85 header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
43e4a8a The great renaming.
saxmatt authored
86
25788ba Add filters to comments_open() and pings_open(). Props tellyworth. fix...
ryan authored
87 if ( !pings_open($tb_id) )
43e4a8a The great renaming.
saxmatt authored
88 trackback_response(1, 'Sorry, trackbacks are closed for this item.');
89
6e181bb Multi-byte character safe excerpting from nbachiyski. fixes #6077
ryan authored
90 $title = wp_html_excerpt( $title, 250 ).'...';
91 $excerpt = wp_html_excerpt( $excerpt, 252 ).'...';
43e4a8a The great renaming.
saxmatt authored
92
7602d17 (int)er the dragon.
matt authored
93 $comment_post_ID = (int) $tb_id;
00d3d3f fixes for bug #311, by bronski
michelvaldrighi authored
94 $comment_author = $blog_name;
b650b07 Move trackbacks to new comment function.
saxmatt authored
95 $comment_author_email = '';
43e4a8a The great renaming.
saxmatt authored
96 $comment_author_url = $tb_url;
b650b07 Move trackbacks to new comment function.
saxmatt authored
97 $comment_content = "<strong>$title</strong>\n\n$excerpt";
98 $comment_type = 'trackback';
43e4a8a The great renaming.
saxmatt authored
99
248a0c0 Prepare DB queries in more places. Props filosofo. see #6644
ryan authored
100 $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) );
3c34012 Don't accept duplicate pings
saxmatt authored
101 if ( $dupe )
efcb63a s/URI/URL/. Props Nazgul. fixes #2666
ryan authored
102 trackback_response(1, 'We already have a ping from that URL for this post.');
3c34012 Don't accept duplicate pings
saxmatt authored
103
00d3d3f fixes for bug #311, by bronski
michelvaldrighi authored
104 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
43e4a8a The great renaming.
saxmatt authored
105
b650b07 Move trackbacks to new comment function.
saxmatt authored
106 wp_new_comment($commentdata);
43e4a8a The great renaming.
saxmatt authored
107
b650b07 Move trackbacks to new comment function.
saxmatt authored
108 do_action('trackback_post', $wpdb->insert_id);
31066f3 Don't die before action
saxmatt authored
109 trackback_response(0);
43e4a8a The great renaming.
saxmatt authored
110 }
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
111 ?>
Something went wrong with that request. Please try again.