📄 comment-functions.php
字号:
// Example: // http://dummy-weblog.org // http://dummy-weblog.org/ // http://dummy-weblog.org/post.php // We don't wanna ping first and second types, even if they have a valid <link/> foreach($post_links_temp[0] as $link_test) : 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 && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. $test = parse_url($link_test); if (isset($test['query'])) $post_links[] = $link_test; elseif(($test['path'] != '/') && ($test['path'] != '')) $post_links[] = $link_test; endif; endforeach; do_action('pre_ping', array(&$post_links, &$pung)); foreach ($post_links as $pagelinkedto){ debug_fwrite($log, "Processing -- $pagelinkedto\n"); $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048); if ($pingback_server_url) { @ set_time_limit( 60 ); // Now, the RPC call debug_fwrite($log, "Page Linked To: $pagelinkedto \n"); debug_fwrite($log, 'Page Linked From: '); $pagelinkedfrom = get_permalink($post_ID); debug_fwrite($log, $pagelinkedfrom."\n"); // using a timeout of 3 seconds should be enough to cover slow servers $client = new IXR_Client($pingback_server_url); $client->timeout = 3; $client->useragent .= ' -- WordPress/' . $wp_version; // when set to true, this outputs debug messages by itself $client->debug = false; if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto ) ) add_ping( $post_ID, $pagelinkedto ); else debug_fwrite($log, "Error.\n Fault code: ".$client->getErrorCode()." : ".$client->getErrorMessage()."\n"); } } debug_fwrite($log, "\nEND: ".time()."\n****************************\n"); debug_fclose($log);}function discover_pingback_server_uri($url, $timeout_bytes = 2048) { global $wp_version; $byte_count = 0; $contents = ''; $headers = ''; $pingback_str_dquote = 'rel="pingback"'; $pingback_str_squote = 'rel=\'pingback\''; $x_pingback_str = 'x-pingback: '; $pingback_href_original_pos = 27; extract(parse_url($url)); if (!isset($host)) { // Not an URL. This should never happen. return false; } $path = (!isset($path)) ? '/' : $path; $path .= (isset($query)) ? '?'.$query : ''; $port = (isset($port)) ? $port : 80; // Try to connect to the server at $host $fp = @fsockopen($host, $port, $errno, $errstr, 2); if (!$fp) { // Couldn't open a connection to $host; return false; } // Send the GET request $request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: WordPress/$wp_version \r\n\r\n";// ob_end_flush(); fputs($fp, $request); // Let's check for an X-Pingback header first while (!feof($fp)) { $line = fgets($fp, 512); if (trim($line) == '') { break; } $headers .= trim($line)."\n"; $x_pingback_header_offset = strpos(strtolower($headers), $x_pingback_str); if ($x_pingback_header_offset) { // We got it! preg_match('#x-pingback: (.+)#is', $headers, $matches); $pingback_server_url = trim($matches[1]); return $pingback_server_url; } if(strpos(strtolower($headers), 'content-type: ')) { preg_match('#content-type: (.+)#is', $headers, $matches); $content_type = trim($matches[1]); } } if (preg_match('#(image|audio|video|model)/#is', $content_type)) { // Not an (x)html, sgml, or xml page, no use going further return false; } while (!feof($fp)) { $line = fgets($fp, 1024); $contents .= trim($line); $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote); $pingback_link_offset_squote = strpos($contents, $pingback_str_squote); if ($pingback_link_offset_dquote || $pingback_link_offset_squote) { $quote = ($pingback_link_offset_dquote) ? '"' : '\''; $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote; $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset); $pingback_href_start = $pingback_href_pos+6; $pingback_href_end = @strpos($contents, $quote, $pingback_href_start); $pingback_server_url_len = $pingback_href_end - $pingback_href_start; $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len); // We may find rel="pingback" but an incomplete pingback URI if ($pingback_server_url_len > 0) { // We got it! return $pingback_server_url; } } $byte_count += strlen($line); if ($byte_count > $timeout_bytes) { // It's no use going further, there probably isn't any pingback // server to find in this file. (Prevents loading large files.) return false; } } // We didn't find anything. return false;}function is_local_attachment($url) { if ( !strstr($url, get_bloginfo('home') ) ) return false; if ( strstr($url, get_bloginfo('home') . '/?attachment_id=') ) return true; if ( $id = url_to_postid($url) ) { $post = & get_post($id); if ( 'attachment' == $post->post_status ) return true; } return false;}function wp_set_comment_status($comment_id, $comment_status) { global $wpdb; switch($comment_status) { case 'hold': $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; break; case 'approve': $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; break; case 'spam': $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1"; break; case 'delete': return wp_delete_comment($comment_id); break; default: return false; } if ($wpdb->query($query)) { do_action('wp_set_comment_status', $comment_id, $comment_status); $comment = get_comment($comment_id); $comment_post_ID = $comment->comment_post_ID; $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'" ); if( is_object( $c ) ) $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" ); return true; } else { return false; }}function wp_get_comment_status($comment_id) { global $wpdb; $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); if ($result == NULL) { return 'deleted'; } else if ($result == '1') { return 'approved'; } else if ($result == '0') { return 'unapproved'; } else if ($result == 'spam') { return 'spam'; } else { return false; }}function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) { global $wpdb; if (1 == get_settings('comment_moderation')) return false; // If moderation is set to manual if ( (count(explode('http:', $comment)) - 1) >= get_settings('comment_max_links') ) return false; // Check # of external links $mod_keys = trim( get_settings('moderation_keys') ); if ( !empty($mod_keys) ) { $words = explode("\n", $mod_keys ); foreach ($words as $word) { $word = trim($word); // Skip empty lines if (empty($word)) { continue; } // Do some escaping magic so that '#' chars in the // spam words don't break things: $word = preg_quote($word, '#'); $pattern = "#$word#i"; if ( preg_match($pattern, $author) ) return false; if ( preg_match($pattern, $email) ) return false; if ( preg_match($pattern, $url) ) return false; if ( preg_match($pattern, $comment) ) return false; if ( preg_match($pattern, $user_ip) ) return false; if ( preg_match($pattern, $user_agent) ) return false; } } // Comment whitelisting: if ( 1 == get_settings('comment_whitelist')) { if ( 'trackback' == $comment_type || 'pingback' == $comment_type ) { // check if domain is in blogroll $uri = parse_url($url); $domain = $uri['host']; $uri = parse_url( get_option('home') ); $home_domain = $uri['host']; if ( $wpdb->get_var("SELECT link_id FROM $wpdb->links WHERE link_url LIKE ('%$domain%') LIMIT 1") || $domain == $home_domain ) return true; else return false; } elseif( $author != '' && $email != '' ) { $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"); if ( ( 1 == $ok_to_comment ) && ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) ) return true; else return false; } else { return false; } } return true;}function get_approved_comments($post_id) { global $wpdb; $post_id = (int) $post_id; return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post_id AND comment_approved = '1' ORDER BY comment_date");}function sanitize_comment_cookies() { if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]); $comment_author = stripslashes($comment_author); $comment_author = wp_specialchars($comment_author, true); $_COOKIE['comment_author_'.COOKIEHASH] = $comment_author; } if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); $comment_author_email = stripslashes($comment_author_email); $comment_author_email = wp_specialchars($comment_author_email, true); $_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email; } if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) { $comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]); $comment_author_url = stripslashes($comment_author_url); $comment_author_url = wp_specialchars($comment_author_url, true); $_COOKIE['comment_author_url_'.COOKIEHASH] = $comment_author_url; }}function wp_get_current_commenter() { // Cookies should already be sanitized. $comment_author = ''; if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) $comment_author = $_COOKIE['comment_author_'.COOKIEHASH]; $comment_author_email = ''; if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH]; $comment_author_url = ''; if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH]; return compact('comment_author', 'comment_author_email', 'comment_author_url');}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -