5 function comments_template( $file = '/comments.php' ) {
6 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
8 if ( is_single() || is_page() || $withcomments ) :
9 $req = get_settings('require_name_email');
11 if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) {
12 $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]);
13 $comment_author = stripslashes($comment_author);
14 $comment_author = wp_specialchars($comment_author, true);
16 $comment_author_email = '';
17 if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) {
18 $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]);
19 $comment_author_email = stripslashes($comment_author_email);
20 $comment_author_email = wp_specialchars($comment_author_email, true);
22 $comment_author_url = '';
23 if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) {
24 $comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]);
25 $comment_author_url = stripslashes($comment_author_url);
26 $comment_author_url = wp_specialchars($comment_author_url, true);
29 if ( empty($comment_author) ) {
30 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date");
32 $author_db = $wpdb->escape($comment_author);
33 $email_db = $wpdb->escape($comment_author_email);
34 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date");
37 get_currentuserinfo();
39 define('COMMENTS_TEMPLATE', true);
40 $include = apply_filters('comments_template', TEMPLATEPATH . $file );
41 if ( file_exists( $include ) )
44 require( ABSPATH . 'wp-content/themes/default/comments.php');
49 function wp_new_comment( $commentdata ) {
50 $commentdata = apply_filters('preprocess_comment', $commentdata);
52 $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
53 $commentdata['user_ID'] = (int) $commentdata['user_ID'];
55 $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
56 $commentdata['comment_agent'] = $_SERVER['HTTP_USER_AGENT'];
58 $commentdata['comment_date'] = current_time('mysql');
59 $commentdata['comment_date_gmt'] = current_time('mysql', 1);
62 $commentdata = wp_filter_comment($commentdata);
64 $commentdata['comment_approved'] = wp_allow_comment($commentdata);
66 $comment_ID = wp_insert_comment($commentdata);
68 do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
70 if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching
71 if ( '0' == $commentdata['comment_approved'] )
72 wp_notify_moderator($comment_ID);
74 $post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment
76 if ( get_settings('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID'] )
77 wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
83 function wp_insert_comment($commentdata) {
85 extract($commentdata);
87 if ( ! isset($comment_author_IP) )
88 $comment_author_IP = $_SERVER['REMOTE_ADDR'];
89 if ( ! isset($comment_date) )
90 $comment_date = current_time('mysql');
91 if ( ! isset($comment_date_gmt) )
92 $comment_date_gmt = gmdate('Y-m-d H:i:s', strtotime($comment_date) );
93 if ( ! isset($comment_parent) )
95 if ( ! isset($comment_approved) )
96 $comment_approved = 1;
98 $result = $wpdb->query("INSERT INTO $wpdb->comments
99 (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved, comment_agent, comment_type, comment_parent, user_id)
101 ('$comment_post_ID', '$comment_author', '$comment_author_email', '$comment_author_url', '$comment_author_IP', '$comment_date', '$comment_date_gmt', '$comment_content', '$comment_approved', '$comment_agent', '$comment_type', '$comment_parent', '$user_id')
104 $id = $wpdb->insert_id;
106 if ( $comment_approved == 1) {
107 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'");
108 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$comment_post_ID'" );
113 function wp_filter_comment($commentdata) {
114 $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
115 $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']);
116 $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
117 $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);
118 $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);
119 $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);
120 $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);
121 $commentdata['filtered'] = true;
125 function wp_allow_comment($commentdata) {
127 extract($commentdata);
129 $comment_user_domain = apply_filters('pre_comment_user_domain', gethostbyaddr($comment_author_IP) );
131 // Simple duplicate check
132 $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' ";
133 if ( $comment_author_email )
134 $dupe .= "OR comment_author_email = '$comment_author_email' ";
135 $dupe .= ") AND comment_content = '$comment_content' LIMIT 1";
136 if ( $wpdb->get_var($dupe) )
137 die( __('Duplicate comment detected; it looks as though you\'ve already said that!') );
139 // Simple flood-protection
140 if ( $lasttime = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_author_IP = '$comment_author_IP' OR comment_author_email = '$comment_author_email' ORDER BY comment_date DESC LIMIT 1") ) {
141 $time_lastcomment = mysql2date('U', $lasttime);
142 $time_newcomment = mysql2date('U', $comment_date_gmt);
143 if ( ($time_newcomment - $time_lastcomment) < 15 ) {
144 do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
145 die( __('Sorry, you can only post a new comment once every 15 seconds. Slow down cowboy.') );
150 $userdata = get_userdata($user_id);
151 $user = new WP_User($user_id);
152 $post_author = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = '$comment_post_ID' LIMIT 1");
155 // The author and the admins get respect.
156 if ( $userdata && ( $user_id == $post_author || $user->has_cap('level_9') ) ) {
160 // Everyone else's comments will be checked.
162 if ( check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type) )
166 if ( wp_blacklist_check($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent) )
170 $approved = apply_filters('pre_comment_approved', $approved);
175 function wp_update_comment($commentarr) {
178 // First, get all of the original fields
179 $comment = get_comment($commentarr['comment_ID'], ARRAY_A);
181 // Escape data pulled from DB.
182 foreach ($comment as $key => $value)
183 $comment[$key] = $wpdb->escape($value);
185 // Merge old and new fields with new fields overwriting old ones.
186 $commentarr = array_merge($comment, $commentarr);
188 // Now extract the merged array.
189 extract($commentarr);
191 $comment_content = apply_filters('comment_save_pre', $comment_content);
193 $result = $wpdb->query(
194 "UPDATE $wpdb->comments SET
195 comment_content = '$comment_content',
196 comment_author = '$comment_author',
197 comment_author_email = '$comment_author_email',
198 comment_approved = '$comment_approved',
199 comment_author_url = '$comment_author_url',
200 comment_date = '$comment_date'
201 WHERE comment_ID = $comment_ID" );
203 $rval = $wpdb->rows_affected;
205 $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'" );
206 if( is_object( $c ) )
207 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" );
209 do_action('edit_comment', $comment_ID);
214 function wp_delete_comment($comment_id) {
216 do_action('delete_comment', $comment_id);
218 $comment = get_comment($comment_id);
220 if ( ! $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1") )
223 $post_id = $comment->comment_post_ID;
224 if ( $post_id && $comment->comment_approved == 1 )
225 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = comment_count - 1 WHERE ID = '$post_id'" );
227 do_action('wp_set_comment_status', $comment_id, 'delete');
231 function clean_url( $url ) {
232 if ('' == $url) return $url;
233 $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url);
234 $url = str_replace(';//', '://', $url);
235 $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
236 $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url);
240 function get_comments_number( $post_id = 0 ) {
241 global $wpdb, $comment_count_cache, $id;
242 $post_id = (int) $post_id;
247 if ( !isset($comment_count_cache[$post_id]) )
248 $comment_count_cache[$id] = $wpdb->get_var("SELECT comment_count FROM $wpdb->posts WHERE ID = '$post_id'");
250 return apply_filters('get_comments_number', $comment_count_cache[$post_id]);
253 function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) {
254 global $id, $comment;
255 $number = get_comments_number( $id );
258 } elseif ($number == 1) {
260 } elseif ($number > 1) {
261 $blah = str_replace('%', $number, $more);
263 echo apply_filters('comments_number', $blah);
266 function get_comments_link() {
267 return get_permalink() . '#comments';
270 function get_comment_link() {
272 return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
275 function comments_link( $file = '', $echo = true ) {
276 echo get_comments_link();
279 function comments_popup_script($width=400, $height=400, $file='') {
280 global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript;
283 $wpcommentspopupfile = ''; // Use the index.
285 $wpcommentspopupfile = $file;
288 $wpcommentsjavascript = 1;
289 $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n";
293 function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
294 global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb;
295 global $comment_count_cache;
297 if (! is_single() && ! is_page()) {
298 if ( !isset($comment_count_cache[$id]) )
299 $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");
301 $number = $comment_count_cache[$id];
303 if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) {
307 if (!empty($post->post_password)) { // if there's a password
308 if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
309 echo(__('Enter your password to view comments'));
314 if ($wpcommentsjavascript) {
315 if ( empty($wpcommentspopupfile) )
316 $home = get_settings('home');
318 $home = get_settings('siteurl');
319 echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id;
320 echo '" onclick="wpopen(this.href); return false"';
321 } else { // if comments_popup_script() is not in the template, display simple comment link
323 echo get_permalink() . '#respond';
328 if (!empty($CSSclass)) {
329 echo ' class="'.$CSSclass.'"';
331 echo ' title="' . sprintf( __('Comment on %s'), $post->post_title ) .'">';
332 comments_number($zero, $one, $more, $number);
338 function get_comment_ID() {
340 return apply_filters('get_comment_ID', $comment->comment_ID);
343 function comment_ID() {
344 echo get_comment_ID();
347 function get_comment_author() {
349 if ( empty($comment->comment_author) )
350 $author = __('Anonymous');
352 $author = $comment->comment_author;
353 return apply_filters('get_comment_author', $author);
356 function comment_author() {
357 $author = apply_filters('comment_author', get_comment_author() );
361 function get_comment_author_email() {
363 return apply_filters('get_comment_author_email', $comment->comment_author_email);
366 function comment_author_email() {
367 echo apply_filters('author_email', get_comment_author_email() );
370 function get_comment_author_link() {
372 $url = get_comment_author_url();
373 $author = get_comment_author();
375 if ( empty( $url ) || 'http://' == $url )
378 $return = "<a href='$url' rel='external nofollow'>$author</a>";
379 return apply_filters('get_comment_author_link', $return);
382 function comment_author_link() {
383 echo get_comment_author_link();
386 function get_comment_type() {
389 if ( '' == $comment->comment_type )
390 $comment->comment_type = 'comment';
392 return apply_filters('get_comment_type', $comment->comment_type);
395 function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
396 $type = get_comment_type();
409 function get_comment_author_url() {
411 return apply_filters('get_comment_author_url', $comment->comment_author_url);
414 function comment_author_url() {
415 echo apply_filters('comment_url', get_comment_author_url());
418 function comment_author_email_link($linktext='', $before='', $after='') {
420 $email = apply_filters('comment_email', $comment->comment_author_email);
421 if ((!empty($email)) && ($email != '@')) {
422 $display = ($linktext != '') ? $linktext : $email;
424 echo "<a href='mailto:$email'>$display</a>";
429 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
431 $url = get_comment_author_url();
432 $display = ($linktext != '') ? $linktext : $url;
433 $return = "$before<a href='$url' rel='external'>$display</a>$after";
434 return apply_filters('get_comment_author_url_link', $return);
437 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
438 echo get_comment_author_url_link( $linktext, $before, $after );
441 function get_comment_author_IP() {
443 return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
446 function comment_author_IP() {
447 echo get_comment_author_IP();
450 function get_comment_text() {
452 return apply_filters('get_comment_text', $comment->comment_content);
455 function comment_text() {
456 echo apply_filters('comment_text', get_comment_text() );
459 function get_comment_excerpt() {
461 $comment_text = strip_tags($comment->comment_content);
462 $blah = explode(' ', $comment_text);
463 if (count($blah) > 20) {
471 for ($i=0; $i<$k; $i++) {
472 $excerpt .= $blah[$i] . ' ';
474 $excerpt .= ($use_dotdotdot) ? '...' : '';
475 return apply_filters('get_comment_excerpt', $excerpt);
478 function comment_excerpt() {
479 echo apply_filters('comment_excerpt', get_comment_excerpt() );
482 function get_comment_date( $d = '' ) {
485 $date = mysql2date( get_settings('date_format'), $comment->comment_date);
487 $date = mysql2date($d, $comment->comment_date);
488 return apply_filters('get_comment_date', $date);
491 function comment_date( $d = '' ) {
492 echo get_comment_date( $d );
495 function get_comment_time( $d = '', $gmt = false ) {
497 $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date;
499 $date = mysql2date(get_settings('time_format'), $comment_date);
501 $date = mysql2date($d, $comment_date);
502 return apply_filters('get_comment_time', $date);
505 function comment_time( $d = '' ) {
506 echo get_comment_time($d);
509 function get_trackback_url() {
511 $tb_url = get_settings('siteurl') . '/wp-trackback.php?p=' . $id;
513 if ( '' != get_settings('permalink_structure') )
514 $tb_url = trailingslashit(get_permalink()) . 'trackback/';
518 function trackback_url( $display = true ) {
520 echo get_trackback_url();
522 return get_trackback_url();
525 function trackback_rdf($timezone = 0) {
527 if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) {
528 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
529 xmlns:dc="http://purl.org/dc/elements/1.1/"
530 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
531 <rdf:Description rdf:about="';
534 echo ' dc:identifier="';
537 echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n";
538 echo ' trackback:ping="'.trackback_url(0).'"'." />\n";
543 function comments_open() {
545 if ( 'open' == $post->comment_status )
551 function pings_open() {
553 if ( 'open' == $post->ping_status )
559 // Non-template functions
561 function get_lastcommentmodified($timezone = 'server') {
562 global $cache_lastcommentmodified, $pagenow, $wpdb;
563 $add_seconds_blog = get_settings('gmt_offset') * 3600;
564 $add_seconds_server = date('Z');
565 $now = current_time('mysql', 1);
566 if ( !isset($cache_lastcommentmodified[$timezone]) ) {
567 switch(strtolower($timezone)) {
569 $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1");
572 $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1");
575 $lastcommentmodified = $wpdb->get_var("SELECT DATE_ADD(comment_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1");
578 $cache_lastcommentmodified[$timezone] = $lastcommentmodified;
580 $lastcommentmodified = $cache_lastcommentmodified[$timezone];
582 return $lastcommentmodified;
585 function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries
586 global $postc, $id, $commentdata, $wpdb;
588 $query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'";
589 if (false == $include_unapproved) {
590 $query .= " AND comment_approved = '1'";
592 $myrow = $wpdb->get_row($query, ARRAY_A);
594 $myrow['comment_ID'] = $postc->comment_ID;
595 $myrow['comment_post_ID'] = $postc->comment_post_ID;
596 $myrow['comment_author'] = $postc->comment_author;
597 $myrow['comment_author_email'] = $postc->comment_author_email;
598 $myrow['comment_author_url'] = $postc->comment_author_url;
599 $myrow['comment_author_IP'] = $postc->comment_author_IP;
600 $myrow['comment_date'] = $postc->comment_date;
601 $myrow['comment_content'] = $postc->comment_content;
602 $myrow['comment_karma'] = $postc->comment_karma;
603 $myrow['comment_approved'] = $postc->comment_approved;
604 $myrow['comment_type'] = $postc->comment_type;
609 function pingback($content, $post_ID) {
610 global $wp_version, $wpdb;
611 include_once (ABSPATH . WPINC . '/class-IXR.php');
613 // original code by Mort (http://mort.mine.nu:8080)
614 $log = debug_fopen(ABSPATH . '/pingback.log', 'a');
615 $post_links = array();
616 debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
618 $pung = get_pung($post_ID);
622 $gunk = '/#~:.?+=&%@!\-';
624 $any = $ltrs . $gunk . $punc;
627 // Parsing the post, external links (if any) are stored in the $post_links array
628 // This regexp comes straight from phpfreaks.com
629 // http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php
630 preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
633 debug_fwrite($log, 'Post contents:');
634 debug_fwrite($log, $content."\n");
637 // Walking thru the links array
638 // first we get rid of links pointing to sites, not to specific files
640 // http://dummy-weblog.org
641 // http://dummy-weblog.org/
642 // http://dummy-weblog.org/post.php
643 // We don't wanna ping first and second types, even if they have a valid <link/>
645 foreach($post_links_temp[0] as $link_test) :
646 if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself
647 && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
648 $test = parse_url($link_test);
649 if (isset($test['query']))
650 $post_links[] = $link_test;
651 elseif(($test['path'] != '/') && ($test['path'] != ''))
652 $post_links[] = $link_test;
656 do_action('pre_ping', array(&$post_links, &$pung));
658 foreach ($post_links as $pagelinkedto){
659 debug_fwrite($log, "Processing -- $pagelinkedto\n");
660 $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048);
662 if ($pingback_server_url) {
663 @ set_time_limit( 60 );
665 debug_fwrite($log, "Page Linked To: $pagelinkedto \n");
666 debug_fwrite($log, 'Page Linked From: ');
667 $pagelinkedfrom = get_permalink($post_ID);
668 debug_fwrite($log, $pagelinkedfrom."\n");
670 // using a timeout of 3 seconds should be enough to cover slow servers
671 $client = new IXR_Client($pingback_server_url);
672 $client->timeout = 3;
673 $client->useragent .= ' -- WordPress/' . $wp_version;
675 // when set to true, this outputs debug messages by itself
676 $client->debug = false;
678 if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto ) )
679 add_ping( $post_ID, $pagelinkedto );
681 debug_fwrite($log, "Error.\n Fault code: ".$client->getErrorCode()." : ".$client->getErrorMessage()."\n");
685 debug_fwrite($log, "\nEND: ".time()."\n****************************\n");
689 function discover_pingback_server_uri($url, $timeout_bytes = 2048) {
695 $pingback_str_dquote = 'rel="pingback"';
696 $pingback_str_squote = 'rel=\'pingback\'';
697 $x_pingback_str = 'x-pingback: ';
698 $pingback_href_original_pos = 27;
700 extract(parse_url($url));
703 // Not an URL. This should never happen.
707 $path = (!isset($path)) ? '/' : $path;
708 $path .= (isset($query)) ? '?'.$query : '';
709 $port = (isset($port)) ? $port : 80;
711 // Try to connect to the server at $host
712 $fp = @fsockopen($host, $port, $errno, $errstr, 2);
714 // Couldn't open a connection to $host;
718 // Send the GET request
719 $request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: WordPress/$wp_version \r\n\r\n";
721 fputs($fp, $request);
723 // Let's check for an X-Pingback header first
725 $line = fgets($fp, 512);
726 if (trim($line) == '') {
729 $headers .= trim($line)."\n";
730 $x_pingback_header_offset = strpos(strtolower($headers), $x_pingback_str);
731 if ($x_pingback_header_offset) {
733 preg_match('#x-pingback: (.+)#is', $headers, $matches);
734 $pingback_server_url = trim($matches[1]);
735 return $pingback_server_url;
737 if(strpos(strtolower($headers), 'content-type: ')) {
738 preg_match('#content-type: (.+)#is', $headers, $matches);
739 $content_type = trim($matches[1]);
743 if (preg_match('#(image|audio|video|model)/#is', $content_type)) {
744 // Not an (x)html, sgml, or xml page, no use going further
749 $line = fgets($fp, 1024);
750 $contents .= trim($line);
751 $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
752 $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
753 if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
754 $quote = ($pingback_link_offset_dquote) ? '"' : '\'';
755 $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
756 $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);
757 $pingback_href_start = $pingback_href_pos+6;
758 $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
759 $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
760 $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
761 // We may find rel="pingback" but an incomplete pingback URI
762 if ($pingback_server_url_len > 0) {
764 return $pingback_server_url;
767 $byte_count += strlen($line);
768 if ($byte_count > $timeout_bytes) {
769 // It's no use going further, there probably isn't any pingback
770 // server to find in this file. (Prevents loading large files.)
775 // We didn't find anything.
779 function is_local_attachment($url) {
780 if ( !strstr($url, get_bloginfo('home') ) )
782 if ( strstr($url, get_bloginfo('home') . '/?attachment_id=') )
784 if ( $id = url_to_postid($url) ) {
785 $post = & get_post($id);
786 if ( 'attachment' == $post->post_status )
792 function wp_set_comment_status($comment_id, $comment_status) {
795 switch($comment_status) {
797 $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1";
800 $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";
803 $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1";
806 return wp_delete_comment($comment_id);
812 if ($wpdb->query($query)) {
813 do_action('wp_set_comment_status', $comment_id, $comment_status);
815 $comment = get_comment($comment_id);
816 $comment_post_ID = $comment->comment_post_ID;
817 $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'" );
818 if( is_object( $c ) )
819 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" );
826 function wp_get_comment_status($comment_id) {
829 $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
830 if ($result == NULL) {
832 } else if ($result == '1') {
834 } else if ($result == '0') {
836 } else if ($result == 'spam') {
843 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {
846 if (1 == get_settings('comment_moderation')) return false; // If moderation is set to manual
848 if ( (count(explode('http:', $comment)) - 1) >= get_settings('comment_max_links') )
849 return false; // Check # of external links
851 $mod_keys = trim( get_settings('moderation_keys') );
852 if ( !empty($mod_keys) ) {
853 $words = explode("\n", $mod_keys );
855 foreach ($words as $word) {
859 if (empty($word)) { continue; }
861 // Do some escaping magic so that '#' chars in the
862 // spam words don't break things:
863 $word = preg_quote($word, '#');
865 $pattern = "#$word#i";
866 if ( preg_match($pattern, $author) ) return false;
867 if ( preg_match($pattern, $email) ) return false;
868 if ( preg_match($pattern, $url) ) return false;
869 if ( preg_match($pattern, $comment) ) return false;
870 if ( preg_match($pattern, $user_ip) ) return false;
871 if ( preg_match($pattern, $user_agent) ) return false;
875 // Comment whitelisting:
876 if ( 1 == get_settings('comment_whitelist')) {
877 if ( 'trackback' == $comment_type || 'pingback' == $comment_type ) { // check if domain is in blogroll
878 $uri = parse_url($url);
879 $domain = $uri['host'];
880 $uri = parse_url( get_option('home') );
881 $home_domain = $uri['host'];
882 if ( $wpdb->get_var("SELECT link_id FROM $wpdb->links WHERE link_url LIKE ('%$domain%') LIMIT 1") || $domain == $home_domain )
886 } elseif( $author != '' && $email != '' ) {
887 $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1");
888 if ( ( 1 == $ok_to_comment ) &&
889 ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) )
901 function get_approved_comments($post_id) {
903 return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post_id AND comment_approved = '1' ORDER BY comment_date");