-
+ B0975B8D1221ADB69A7508048202FB49DFEBE768A93B1CB3BF82253A6B97654F58AF9A3413E628103DC21B4E2F68EC226BB30B826568BBDF8798E8940672A290
mp-wp/wp-includes/comment.php
(0 . 0)(1 . 1626)
84919 <?php^M
84920 /**^M
84921 * Manages WordPress comments^M
84922 *^M
84923 * @package WordPress^M
84924 * @subpackage Comment^M
84925 */^M
84926 ^M
84927 /**^M
84928 * Checks whether a comment passes internal checks to be allowed to add.^M
84929 *^M
84930 * If comment moderation is set in the administration, then all comments,^M
84931 * regardless of their type and whitelist will be set to false. If the number of^M
84932 * links exceeds the amount in the administration, then the check fails. If any^M
84933 * of the parameter contents match the blacklist of words, then the check fails.^M
84934 *^M
84935 * If the number of links exceeds the amount in the administration, then the^M
84936 * check fails. If any of the parameter contents match the blacklist of words,^M
84937 * then the check fails.^M
84938 *^M
84939 * If the comment is a trackback and part of the blogroll, then the trackback is^M
84940 * automatically whitelisted. If the comment author was approved before, then^M
84941 * the comment is automatically whitelisted.^M
84942 *^M
84943 * If none of the checks fail, then the failback is to set the check to pass^M
84944 * (return true).^M
84945 *^M
84946 * @since 1.2.0^M
84947 * @uses $wpdb^M
84948 *^M
84949 * @param string $author Comment Author's name^M
84950 * @param string $email Comment Author's email^M
84951 * @param string $url Comment Author's URL^M
84952 * @param string $comment Comment contents^M
84953 * @param string $user_ip Comment Author's IP address^M
84954 * @param string $user_agent Comment Author's User Agent^M
84955 * @param string $comment_type Comment type, either user submitted comment,^M
84956 * trackback, or pingback^M
84957 * @return bool Whether the checks passed (true) and the comments should be^M
84958 * displayed or set to moderated^M
84959 */^M
84960 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {^M
84961 global $wpdb;^M
84962 ^M
84963 if ( 1 == get_option('comment_moderation') ) return 0; // If moderation is set to manual^M
84964 ^M
84965 $textchk = apply_filters('comment_text', $comment);^M
84966 $linkcount = preg_match_all("|(href\t*?=\t*?['\"]?)?(https?:)?//|i", $textchk, $out);^M
84967 $plinkcount = preg_match_all("|(href\t*?=\t*?['\"]?)?(https?:)?//trilema\.com/|i",$textchk , $out);^M
84968 $linkcount_result = $linkcount - $plinkcount;^M
84969 ^M
84970 $mod_keys = trim(get_option('moderation_keys'));^M
84971 if ( !empty($mod_keys) ) {^M
84972 $words = explode("\n", $mod_keys );^M
84973 ^M
84974 foreach ( (array) $words as $word) {^M
84975 $word = trim($word);^M
84976 ^M
84977 // Skip empty lines^M
84978 if ( empty($word) )^M
84979 continue;^M
84980 ^M
84981 // Do some escaping magic so that '#' chars in the^M
84982 // spam words don't break things:^M
84983 $word = preg_quote($word, '#');^M
84984 ^M
84985 $pattern = "#$word#i";^M
84986 if ( preg_match($pattern, $author) ) return 0;^M
84987 if ( preg_match($pattern, $email) ) return 0;^M
84988 if ( preg_match($pattern, $url) ) return 0;^M
84989 if ( preg_match($pattern, $comment) ) return 0;^M
84990 if ( preg_match($pattern, $user_ip) ) return 0;^M
84991 if ( preg_match($pattern, $user_agent) ) return 0;^M
84992 }^M
84993 }^M
84994 ^M
84995 // Comment whitelisting:^M
84996 if ( 1 == get_option('comment_whitelist')) {^M
84997 if ( 'trackback' == $comment_type || 'pingback' == $comment_type ) { // check if domain is in blogroll^M
84998 $uri = parse_url($url);^M
84999 $domain = $uri['host'];^M
85000 $uri = parse_url( get_option('home') );^M
85001 $home_domain = $uri['host'];^M
85002 if ( $wpdb->get_var($wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_url LIKE (%s) LIMIT 1", '%'.$domain.'%')) || $domain == $home_domain )^M
85003 return 1;^M
85004 else^M
85005 return 0;^M
85006 } elseif ( $author != '' && $email != '' ) {^M
85007 // expected_slashed ($author, $email)^M
85008 $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");^M
85009 if ( ( 1 == $ok_to_comment ) &&^M
85010 ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) ) ^M
85011 if ($linkcount_result == 0) return 1; else return 0;^M
85012 else if ($linkcount_result > 1) return "spam"; else return 0;^M
85013 } else return 0;^M
85014 }^M
85015 return 1;^M
85016 }^M
85017 ^M
85018 /**^M
85019 * Retrieve the approved comments for post $post_id.^M
85020 *^M
85021 * @since 2.0.0^M
85022 * @uses $wpdb^M
85023 *^M
85024 * @param int $post_id The ID of the post^M
85025 * @return array $comments The approved comments^M
85026 */^M
85027 function get_approved_comments($post_id) {^M
85028 global $wpdb;^M
85029 return $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post_id));^M
85030 }^M
85031 ^M
85032 /**^M
85033 * Retrieves comment data given a comment ID or comment object.^M
85034 *^M
85035 * If an object is passed then the comment data will be cached and then returned^M
85036 * after being passed through a filter. If the comment is empty, then the global^M
85037 * comment variable will be used, if it is set.^M
85038 *^M
85039 * If the comment is empty, then the global comment variable will be used, if it^M
85040 * is set.^M
85041 *^M
85042 * @since 2.0.0^M
85043 * @uses $wpdb^M
85044 *^M
85045 * @param object|string|int $comment Comment to retrieve.^M
85046 * @param string $output Optional. OBJECT or ARRAY_A or ARRAY_N constants.^M
85047 * @return object|array|null Depends on $output value.^M
85048 */^M
85049 function &get_comment(&$comment, $output = OBJECT) {^M
85050 global $wpdb;^M
85051 ^M
85052 if ( empty($comment) ) {^M
85053 if ( isset($GLOBALS['comment']) )^M
85054 $_comment = & $GLOBALS['comment'];^M
85055 else^M
85056 $_comment = null;^M
85057 } elseif ( is_object($comment) ) {^M
85058 wp_cache_add($comment->comment_ID, $comment, 'comment');^M
85059 $_comment = $comment;^M
85060 } else {^M
85061 if ( isset($GLOBALS['comment']) && ($GLOBALS['comment']->comment_ID == $comment) ) {^M
85062 $_comment = & $GLOBALS['comment'];^M
85063 } elseif ( ! $_comment = wp_cache_get($comment, 'comment') ) {^M
85064 $_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment));^M
85065 wp_cache_add($_comment->comment_ID, $_comment, 'comment');^M
85066 }^M
85067 }^M
85068 ^M
85069 $_comment = apply_filters('get_comment', $_comment);^M
85070 ^M
85071 if ( $output == OBJECT ) {^M
85072 return $_comment;^M
85073 } elseif ( $output == ARRAY_A ) {^M
85074 $__comment = get_object_vars($_comment);^M
85075 return $__comment;^M
85076 } elseif ( $output == ARRAY_N ) {^M
85077 $__comment = array_values(get_object_vars($_comment));^M
85078 return $__comment;^M
85079 } else {^M
85080 return $_comment;^M
85081 }^M
85082 }^M
85083 ^M
85084 /**^M
85085 * Retrieve a list of comments.^M
85086 *^M
85087 * The list of comment arguments are 'status', 'orderby', 'comment_date_gmt',^M
85088 * 'order', 'number', 'offset', and 'post_id'.^M
85089 *^M
85090 * @since 2.7.0^M
85091 * @uses $wpdb^M
85092 *^M
85093 * @param mixed $args Optional. Array or string of options to override defaults.^M
85094 * @return array List of comments.^M
85095 */^M
85096 function get_comments( $args = '' ) {^M
85097 global $wpdb;^M
85098 ^M
85099 $defaults = array('status' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0);^M
85100 ^M
85101 $args = wp_parse_args( $args, $defaults );^M
85102 extract( $args, EXTR_SKIP );^M
85103 ^M
85104 // $args can be whatever, only use the args defined in defaults to compute the key^M
85105 $key = md5( serialize( compact(array_keys($defaults)) ) );^M
85106 $last_changed = wp_cache_get('last_changed', 'comment');^M
85107 if ( !$last_changed ) {^M
85108 $last_changed = time();^M
85109 wp_cache_set('last_changed', $last_changed, 'comment');^M
85110 }^M
85111 $cache_key = "get_comments:$key:$last_changed";^M
85112 ^M
85113 if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {^M
85114 return $cache;^M
85115 }^M
85116 ^M
85117 $post_id = absint($post_id);^M
85118 ^M
85119 if ( 'hold' == $status )^M
85120 $approved = "comment_approved = '0'";^M
85121 elseif ( 'approve' == $status )^M
85122 $approved = "comment_approved = '1'";^M
85123 elseif ( 'spam' == $status )^M
85124 $approved = "comment_approved = 'spam'";^M
85125 else^M
85126 $approved = "( comment_approved = '0' OR comment_approved = '1' )";^M
85127 ^M
85128 $order = ( 'ASC' == $order ) ? 'ASC' : 'DESC';^M
85129 ^M
85130 $orderby = 'comment_date_gmt'; // Hard code for now^M
85131 ^M
85132 $number = absint($number);^M
85133 $offset = absint($offset);^M
85134 ^M
85135 if ( !empty($number) ) {^M
85136 if ( $offset )^M
85137 $number = 'LIMIT ' . $offset . ',' . $number;^M
85138 else^M
85139 $number = 'LIMIT ' . $number;^M
85140 ^M
85141 } else {^M
85142 $number = '';^M
85143 }^M
85144 ^M
85145 if ( ! empty($post_id) )^M
85146 $post_where = $wpdb->prepare( 'comment_post_ID = %d AND', $post_id );^M
85147 else^M
85148 $post_where = '';^M
85149 ^M
85150 $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE $post_where $approved ORDER BY $orderby $order $number" );^M
85151 wp_cache_add( $cache_key, $comments, 'comment' );^M
85152 ^M
85153 return $comments;^M
85154 }^M
85155 ^M
85156 /**^M
85157 * Retrieve all of the WordPress supported comment statuses.^M
85158 *^M
85159 * Comments have a limited set of valid status values, this provides the comment^M
85160 * status values and descriptions.^M
85161 *^M
85162 * @package WordPress^M
85163 * @subpackage Post^M
85164 * @since 2.7.0^M
85165 *^M
85166 * @return array List of comment statuses.^M
85167 */^M
85168 function get_comment_statuses( ) {^M
85169 $status = array(^M
85170 'hold' => __('Unapproved'),^M
85171 'approve' => __('Approved'),^M
85172 'spam' => _c('Spam|adjective'),^M
85173 );^M
85174 ^M
85175 return $status;^M
85176 }^M
85177 ^M
85178 ^M
85179 /**^M
85180 * The date the last comment was modified.^M
85181 *^M
85182 * @since 1.5.0^M
85183 * @uses $wpdb^M
85184 * @global array $cache_lastcommentmodified^M
85185 *^M
85186 * @param string $timezone Which timezone to use in reference to 'gmt', 'blog',^M
85187 * or 'server' locations.^M
85188 * @return string Last comment modified date.^M
85189 */^M
85190 function get_lastcommentmodified($timezone = 'server') {^M
85191 global $cache_lastcommentmodified, $wpdb;^M
85192 ^M
85193 if ( isset($cache_lastcommentmodified[$timezone]) )^M
85194 return $cache_lastcommentmodified[$timezone];^M
85195 ^M
85196 $add_seconds_server = date('Z');^M
85197 ^M
85198 switch ( strtolower($timezone)) {^M
85199 case 'gmt':^M
85200 $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");^M
85201 break;^M
85202 case 'blog':^M
85203 $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");^M
85204 break;^M
85205 case 'server':^M
85206 $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server));^M
85207 break;^M
85208 }^M
85209 ^M
85210 $cache_lastcommentmodified[$timezone] = $lastcommentmodified;^M
85211 ^M
85212 return $lastcommentmodified;^M
85213 }^M
85214 ^M
85215 /**^M
85216 * The amount of comments in a post or total comments.^M
85217 *^M
85218 * A lot like {@link wp_count_comments()}, in that they both return comment^M
85219 * stats (albeit with different types). The {@link wp_count_comments()} actual^M
85220 * caches, but this function does not.^M
85221 *^M
85222 * @since 2.0.0^M
85223 * @uses $wpdb^M
85224 *^M
85225 * @param int $post_id Optional. Comment amount in post if > 0, else total comments blog wide.^M
85226 * @return array The amount of spam, approved, awaiting moderation, and total comments.^M
85227 */^M
85228 function get_comment_count( $post_id = 0 ) {^M
85229 global $wpdb;^M
85230 ^M
85231 $post_id = (int) $post_id;^M
85232 ^M
85233 $where = '';^M
85234 if ( $post_id > 0 ) {^M
85235 $where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id);^M
85236 }^M
85237 ^M
85238 $totals = (array) $wpdb->get_results("^M
85239 SELECT comment_approved, COUNT( * ) AS total^M
85240 FROM {$wpdb->comments}^M
85241 {$where}^M
85242 GROUP BY comment_approved^M
85243 ", ARRAY_A);^M
85244 ^M
85245 $comment_count = array(^M
85246 "approved" => 0,^M
85247 "awaiting_moderation" => 0,^M
85248 "spam" => 0,^M
85249 "total_comments" => 0^M
85250 );^M
85251 ^M
85252 foreach ( $totals as $row ) {^M
85253 switch ( $row['comment_approved'] ) {^M
85254 case 'spam':^M
85255 $comment_count['spam'] = $row['total'];^M
85256 $comment_count["total_comments"] += $row['total'];^M
85257 break;^M
85258 case 1:^M
85259 $comment_count['approved'] = $row['total'];^M
85260 $comment_count['total_comments'] += $row['total'];^M
85261 break;^M
85262 case 0:^M
85263 $comment_count['awaiting_moderation'] = $row['total'];^M
85264 $comment_count['total_comments'] += $row['total'];^M
85265 break;^M
85266 default:^M
85267 break;^M
85268 }^M
85269 }^M
85270 ^M
85271 return $comment_count;^M
85272 }^M
85273 ^M
85274 /**^M
85275 * Sanitizes the cookies sent to the user already.^M
85276 *^M
85277 * Will only do anything if the cookies have already been created for the user.^M
85278 * Mostly used after cookies had been sent to use elsewhere.^M
85279 *^M
85280 * @since 2.0.4^M
85281 */^M
85282 function sanitize_comment_cookies() {^M
85283 if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) {^M
85284 $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]);^M
85285 $comment_author = stripslashes($comment_author);^M
85286 $comment_author = attribute_escape($comment_author);^M
85287 $_COOKIE['comment_author_'.COOKIEHASH] = $comment_author;^M
85288 }^M
85289 ^M
85290 if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) {^M
85291 $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]);^M
85292 $comment_author_email = stripslashes($comment_author_email);^M
85293 $comment_author_email = attribute_escape($comment_author_email);^M
85294 $_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email;^M
85295 }^M
85296 ^M
85297 if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) {^M
85298 $comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]);^M
85299 $comment_author_url = stripslashes($comment_author_url);^M
85300 $_COOKIE['comment_author_url_'.COOKIEHASH] = $comment_author_url;^M
85301 }^M
85302 }^M
85303 ^M
85304 /**^M
85305 * Validates whether this comment is allowed to be made or not.^M
85306 *^M
85307 * @since 2.0.0^M
85308 * @uses $wpdb^M
85309 * @uses apply_filters() Calls 'pre_comment_approved' hook on the type of comment^M
85310 * @uses do_action() Calls 'check_comment_flood' hook on $comment_author_IP, $comment_author_email, and $comment_date_gmt^M
85311 *^M
85312 * @param array $commentdata Contains information on the comment^M
85313 * @return mixed Signifies the approval status (0|1|'spam')^M
85314 */^M
85315 function wp_allow_comment($commentdata) {^M
85316 global $wpdb;^M
85317 extract($commentdata, EXTR_SKIP);^M
85318 ^M
85319 // Simple duplicate check^M
85320 // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)^M
85321 $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' ";^M
85322 if ( $comment_author_email )^M
85323 $dupe .= "OR comment_author_email = '$comment_author_email' ";^M
85324 $dupe .= ") AND comment_content = '$comment_content' LIMIT 1";^M
85325 if ( $wpdb->get_var($dupe) ) {^M
85326 if ( defined('DOING_AJAX') )^M
85327 die( __('Duplicate comment detected; it looks as though you\'ve already said that!') );^M
85328 ^M
85329 wp_die( __('Duplicate comment detected; it looks as though you\'ve already said that!') );^M
85330 }^M
85331 ^M
85332 do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );^M
85333 ^M
85334 if ( $user_id ) {^M
85335 $userdata = get_userdata($user_id);^M
85336 $user = new WP_User($user_id);^M
85337 $post_author = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", $comment_post_ID));^M
85338 }^M
85339 ^M
85340 if ( isset($userdata) && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {^M
85341 // The author and the admins get respect.^M
85342 $approved = 1;^M
85343 } else {^M
85344 // Everyone else's comments will be checked.^M
85345 ^M
85346 // Rewritten nov 2013 to make linky spam go straight to spam.^M
85347 ^M
85348 $approved = check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type);^M
85349 ^M
85350 if ( wp_blacklist_check($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent) ) $approved = 'spam';^M
85351 ^M
85352 }^M
85353 ^M
85354 $approved = apply_filters('pre_comment_approved', $approved);^M
85355 return $approved;^M
85356 }^M
85357 ^M
85358 /**^M
85359 * Check whether comment flooding is occurring.^M
85360 *^M
85361 * Won't run, if current user can manage options, so to not block^M
85362 * administrators.^M
85363 *^M
85364 * @since 2.3.0^M
85365 * @uses $wpdb^M
85366 * @uses apply_filters() Calls 'comment_flood_filter' filter with first^M
85367 * parameter false, last comment timestamp, new comment timestamp.^M
85368 * @uses do_action() Calls 'comment_flood_trigger' action with parameters with^M
85369 * last comment timestamp and new comment timestamp.^M
85370 *^M
85371 * @param string $ip Comment IP.^M
85372 * @param string $email Comment author email address.^M
85373 * @param string $date MySQL time string.^M
85374 */^M
85375 function check_comment_flood_db( $ip, $email, $date ) {^M
85376 global $wpdb;^M
85377 if ( current_user_can( 'manage_options' ) )^M
85378 return; // don't throttle admins^M
85379 if ( $lasttime = $wpdb->get_var( $wpdb->prepare("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_author_IP = %s OR comment_author_email = %s ORDER BY comment_date DESC LIMIT 1", $ip, $email) ) ) {^M
85380 $time_lastcomment = mysql2date('U', $lasttime);^M
85381 $time_newcomment = mysql2date('U', $date);^M
85382 $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);^M
85383 if ( $flood_die ) {^M
85384 do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);^M
85385 ^M
85386 if ( defined('DOING_AJAX') )^M
85387 die( __('You are posting comments too quickly. Slow down.') );^M
85388 ^M
85389 wp_die( __('You are posting comments too quickly. Slow down.'), '', array('response' => 403) );^M
85390 }^M
85391 }^M
85392 }^M
85393 ^M
85394 /**^M
85395 * Separates an array of comments into an array keyed by comment_type.^M
85396 *^M
85397 * @since 2.7.0^M
85398 *^M
85399 * @param array $comments Array of comments^M
85400 * @return array Array of comments keyed by comment_type.^M
85401 */^M
85402 function &separate_comments(&$comments) {^M
85403 $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array());^M
85404 $count = count($comments);^M
85405 for ( $i = 0; $i < $count; $i++ ) {^M
85406 $type = $comments[$i]->comment_type;^M
85407 if ( empty($type) )^M
85408 $type = 'comment';^M
85409 $comments_by_type[$type][] = &$comments[$i];^M
85410 if ( 'trackback' == $type || 'pingback' == $type )^M
85411 $comments_by_type['pings'][] = &$comments[$i];^M
85412 }^M
85413 ^M
85414 return $comments_by_type;^M
85415 }^M
85416 ^M
85417 /**^M
85418 * Calculate the total number of comment pages.^M
85419 *^M
85420 * @since 2.7.0^M
85421 * @uses get_query_var() Used to fill in the default for $per_page parameter.^M
85422 * @uses get_option() Used to fill in defaults for parameters.^M
85423 * @uses Walker_Comment^M
85424 *^M
85425 * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments^M
85426 * @param int $per_page Optional comments per page.^M
85427 * @param boolean $threaded Optional control over flat or threaded comments.^M
85428 * @return int Number of comment pages.^M
85429 */^M
85430 function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {^M
85431 global $wp_query;^M
85432 ^M
85433 if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) )^M
85434 return $wp_query->max_num_comment_pages;^M
85435 ^M
85436 if ( !$comments || !is_array($comments) )^M
85437 $comments = $wp_query->comments;^M
85438 ^M
85439 if ( empty($comments) )^M
85440 return 0;^M
85441 ^M
85442 if ( !isset($per_page) )^M
85443 $per_page = (int) get_query_var('comments_per_page');^M
85444 if ( 0 === $per_page )^M
85445 $per_page = (int) get_option('comments_per_page');^M
85446 if ( 0 === $per_page )^M
85447 return 1;^M
85448 ^M
85449 if ( !isset($threaded) )^M
85450 $threaded = get_option('thread_comments');^M
85451 ^M
85452 if ( $threaded ) {^M
85453 $walker = new Walker_Comment;^M
85454 $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );^M
85455 } else {^M
85456 $count = ceil( count( $comments ) / $per_page );^M
85457 }^M
85458 ^M
85459 return $count;^M
85460 }^M
85461 ^M
85462 /**^M
85463 * Calculate what page number a comment will appear on for comment paging.^M
85464 *^M
85465 * @since 2.7.0^M
85466 * @uses get_comment() Gets the full comment of the $comment_ID parameter.^M
85467 * @uses get_option() Get various settings to control function and defaults.^M
85468 * @uses get_page_of_comment() Used to loop up to top level comment.^M
85469 *^M
85470 * @param int $comment_ID Comment ID.^M
85471 * @param array $args Optional args.^M
85472 * @return int|null Comment page number or null on error.^M
85473 */^M
85474 function get_page_of_comment( $comment_ID, $args = array() ) {^M
85475 global $wpdb;^M
85476 ^M
85477 if ( !$comment = get_comment( $comment_ID ) )^M
85478 return;^M
85479 ^M
85480 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );^M
85481 $args = wp_parse_args( $args, $defaults );^M
85482 ^M
85483 if ( '' === $args['per_page'] && get_option('page_comments') )^M
85484 $args['per_page'] = get_query_var('comments_per_page');^M
85485 if ( empty($args['per_page']) ) {^M
85486 $args['per_page'] = 0;^M
85487 $args['page'] = 0;^M
85488 }^M
85489 if ( $args['per_page'] < 1 )^M
85490 return 1;^M
85491 ^M
85492 if ( '' === $args['max_depth'] ) {^M
85493 if ( get_option('thread_comments') )^M
85494 $args['max_depth'] = get_option('thread_comments_depth');^M
85495 else^M
85496 $args['max_depth'] = -1;^M
85497 }^M
85498 ^M
85499 // Find this comment's top level parent if threading is enabled^M
85500 if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )^M
85501 return get_page_of_comment( $comment->comment_parent, $args );^M
85502 ^M
85503 $allowedtypes = array(^M
85504 'comment' => '',^M
85505 'pingback' => 'pingback',^M
85506 'trackback' => 'trackback',^M
85507 );^M
85508 ^M
85509 $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';^M
85510 ^M
85511 // Count comments older than this one^M
85512 $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );^M
85513 ^M
85514 // No older comments? Then it's page #1.^M
85515 if ( 0 == $oldercoms )^M
85516 return 1;^M
85517 ^M
85518 // Divide comments older than this one by comments per page to get this comment's page number^M
85519 return ceil( ( $oldercoms + 1 ) / $args['per_page'] );^M
85520 }^M
85521 ^M
85522 /**^M
85523 * Does comment contain blacklisted characters or words.^M
85524 *^M
85525 * @since 1.5.0^M
85526 * @uses do_action() Calls 'wp_blacklist_check' hook for all parameters.^M
85527 *^M
85528 * @param string $author The author of the comment^M
85529 * @param string $email The email of the comment^M
85530 * @param string $url The url used in the comment^M
85531 * @param string $comment The comment content^M
85532 * @param string $user_ip The comment author IP address^M
85533 * @param string $user_agent The author's browser user agent^M
85534 * @return bool True if comment contains blacklisted content, false if comment does not^M
85535 */^M
85536 function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {^M
85537 do_action('wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent);^M
85538 ^M
85539 if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) {^M
85540 foreach ( (array) $chars[1] as $char ) {^M
85541 // If it's an encoded char in the normal ASCII set, reject^M
85542 if ( 38 == $char )^M
85543 continue; // Unless it's &^M
85544 if ( $char < 128 )^M
85545 return true;^M
85546 }^M
85547 }^M
85548 ^M
85549 $mod_keys = trim( get_option('blacklist_keys') );^M
85550 if ( '' == $mod_keys )^M
85551 return false; // If moderation keys are empty^M
85552 $words = explode("\n", $mod_keys );^M
85553 ^M
85554 foreach ( (array) $words as $word ) {^M
85555 $word = trim($word);^M
85556 ^M
85557 // Skip empty lines^M
85558 if ( empty($word) ) { continue; }^M
85559 ^M
85560 // Do some escaping magic so that '#' chars in the^M
85561 // spam words don't break things:^M
85562 $word = preg_quote($word, '#');^M
85563 ^M
85564 $pattern = "#$word#i";^M
85565 if (^M
85566 preg_match($pattern, $author)^M
85567 || preg_match($pattern, $email)^M
85568 || preg_match($pattern, $url)^M
85569 || preg_match($pattern, $comment)^M
85570 || preg_match($pattern, $user_ip)^M
85571 || preg_match($pattern, $user_agent)^M
85572 )^M
85573 return true;^M
85574 }^M
85575 return false;^M
85576 }^M
85577 ^M
85578 /**^M
85579 * Retrieve total comments for blog or single post.^M
85580 *^M
85581 * The properties of the returned object contain the 'moderated', 'approved',^M
85582 * and spam comments for either the entire blog or single post. Those properties^M
85583 * contain the amount of comments that match the status. The 'total_comments'^M
85584 * property contains the integer of total comments.^M
85585 *^M
85586 * The comment stats are cached and then retrieved, if they already exist in the^M
85587 * cache.^M
85588 *^M
85589 * @since 2.5.0^M
85590 *^M
85591 * @param int $post_id Optional. Post ID.^M
85592 * @return object Comment stats.^M
85593 */^M
85594 function wp_count_comments( $post_id = 0 ) {^M
85595 global $wpdb;^M
85596 ^M
85597 $post_id = (int) $post_id;^M
85598 ^M
85599 $stats = apply_filters('wp_count_comments', array(), $post_id);^M
85600 if ( !empty($stats) )^M
85601 return $stats;^M
85602 ^M
85603 $count = wp_cache_get("comments-{$post_id}", 'counts');^M
85604 ^M
85605 if ( false !== $count )^M
85606 return $count;^M
85607 ^M
85608 $where = '';^M
85609 if( $post_id > 0 )^M
85610 $where = $wpdb->prepare( "WHERE comment_post_ID = %d", $post_id );^M
85611 ^M
85612 $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );^M
85613 ^M
85614 $total = 0;^M
85615 $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam');^M
85616 $known_types = array_keys( $approved );^M
85617 foreach( (array) $count as $row_num => $row ) {^M
85618 $total += $row['num_comments'];^M
85619 if ( in_array( $row['comment_approved'], $known_types ) )^M
85620 $stats[$approved[$row['comment_approved']]] = $row['num_comments'];^M
85621 }^M
85622 ^M
85623 $stats['total_comments'] = $total;^M
85624 foreach ( $approved as $key ) {^M
85625 if ( empty($stats[$key]) )^M
85626 $stats[$key] = 0;^M
85627 }^M
85628 ^M
85629 $stats = (object) $stats;^M
85630 wp_cache_set("comments-{$post_id}", $stats, 'counts');^M
85631 ^M
85632 return $stats;^M
85633 }^M
85634 ^M
85635 /**^M
85636 * Removes comment ID and maybe updates post comment count.^M
85637 *^M
85638 * The post comment count will be updated if the comment was approved and has a^M
85639 * post ID available.^M
85640 *^M
85641 * @since 2.0.0^M
85642 * @uses $wpdb^M
85643 * @uses do_action() Calls 'delete_comment' hook on comment ID^M
85644 * @uses do_action() Calls 'wp_set_comment_status' hook on comment ID with 'delete' set for the second parameter^M
85645 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object^M
85646 *^M
85647 * @param int $comment_id Comment ID^M
85648 * @return bool False if delete comment query failure, true on success.^M
85649 */^M
85650 function wp_delete_comment($comment_id) {^M
85651 global $wpdb;^M
85652 do_action('delete_comment', $comment_id);^M
85653 ^M
85654 $comment = get_comment($comment_id);^M
85655 ^M
85656 if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) )^M
85657 return false;^M
85658 ^M
85659 $post_id = $comment->comment_post_ID;^M
85660 if ( $post_id && $comment->comment_approved == 1 )^M
85661 wp_update_comment_count($post_id);^M
85662 ^M
85663 clean_comment_cache($comment_id);^M
85664 ^M
85665 do_action('wp_set_comment_status', $comment_id, 'delete');^M
85666 wp_transition_comment_status('delete', $comment->comment_approved, $comment);^M
85667 return true;^M
85668 }^M
85669 ^M
85670 /**^M
85671 * The status of a comment by ID.^M
85672 *^M
85673 * @since 1.0.0^M
85674 *^M
85675 * @param int $comment_id Comment ID^M
85676 * @return string|bool Status might be 'deleted', 'approved', 'unapproved', 'spam'. False on failure.^M
85677 */^M
85678 function wp_get_comment_status($comment_id) {^M
85679 $comment = get_comment($comment_id);^M
85680 if ( !$comment )^M
85681 return false;^M
85682 ^M
85683 $approved = $comment->comment_approved;^M
85684 ^M
85685 if ( $approved == NULL )^M
85686 return 'deleted';^M
85687 elseif ( $approved == '1' )^M
85688 return 'approved';^M
85689 elseif ( $approved == '0' )^M
85690 return 'unapproved';^M
85691 elseif ( $approved == 'spam' )^M
85692 return 'spam';^M
85693 else^M
85694 return false;^M
85695 }^M
85696 ^M
85697 /**^M
85698 * Call hooks for when a comment status transition occurs.^M
85699 *^M
85700 * Calls hooks for comment status transitions. If the new comment status is not the same^M
85701 * as the previous comment status, then two hooks will be ran, the first is^M
85702 * 'transition_comment_status' with new status, old status, and comment data. The^M
85703 * next action called is 'comment_OLDSTATUS_to_NEWSTATUS' the NEWSTATUS is the^M
85704 * $new_status parameter and the OLDSTATUS is $old_status parameter; it has the^M
85705 * comment data.^M
85706 *^M
85707 * The final action will run whether or not the comment statuses are the same. The^M
85708 * action is named 'comment_NEWSTATUS_COMMENTTYPE', NEWSTATUS is from the $new_status^M
85709 * parameter and COMMENTTYPE is comment_type comment data.^M
85710 *^M
85711 * @since 2.7.0^M
85712 *^M
85713 * @param string $new_status New comment status.^M
85714 * @param string $old_status Previous comment status.^M
85715 * @param object $comment Comment data.^M
85716 */^M
85717 function wp_transition_comment_status($new_status, $old_status, $comment) {^M
85718 // Translate raw statuses to human readable formats for the hooks^M
85719 // This is not a complete list of comment status, it's only the ones that need to be renamed^M
85720 $comment_statuses = array(^M
85721 0 => 'unapproved',^M
85722 'hold' => 'unapproved', // wp_set_comment_status() uses "hold"^M
85723 1 => 'approved',^M
85724 'approve' => 'approved', // wp_set_comment_status() uses "approve"^M
85725 );^M
85726 if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status];^M
85727 if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status];^M
85728 ^M
85729 // Call the hooks^M
85730 if ( $new_status != $old_status ) {^M
85731 do_action('transition_comment_status', $new_status, $old_status, $comment);^M
85732 do_action("comment_${old_status}_to_$new_status", $comment);^M
85733 }^M
85734 do_action("comment_${new_status}_$comment->comment_type", $comment->comment_ID, $comment);^M
85735 }^M
85736 ^M
85737 /**^M
85738 * Get current commenter's name, email, and URL.^M
85739 *^M
85740 * Expects cookies content to already be sanitized. User of this function might^M
85741 * wish to recheck the returned array for validity.^M
85742 *^M
85743 * @see sanitize_comment_cookies() Use to sanitize cookies^M
85744 *^M
85745 * @since 2.0.4^M
85746 *^M
85747 * @return array Comment author, email, url respectively.^M
85748 */^M
85749 function wp_get_current_commenter() {^M
85750 // Cookies should already be sanitized.^M
85751 ^M
85752 $comment_author = '';^M
85753 if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) )^M
85754 $comment_author = $_COOKIE['comment_author_'.COOKIEHASH];^M
85755 ^M
85756 $comment_author_email = '';^M
85757 if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) )^M
85758 $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH];^M
85759 ^M
85760 $comment_author_url = '';^M
85761 if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) )^M
85762 $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH];^M
85763 ^M
85764 return compact('comment_author', 'comment_author_email', 'comment_author_url');^M
85765 }^M
85766 ^M
85767 /**^M
85768 * Inserts a comment to the database.^M
85769 *^M
85770 * The available comment data key names are 'comment_author_IP', 'comment_date',^M
85771 * 'comment_date_gmt', 'comment_parent', 'comment_approved', and 'user_id'.^M
85772 *^M
85773 * @since 2.0.0^M
85774 * @uses $wpdb^M
85775 *^M
85776 * @param array $commentdata Contains information on the comment.^M
85777 * @return int The new comment's ID.^M
85778 */^M
85779 function wp_insert_comment($commentdata) {^M
85780 global $wpdb;^M
85781 extract(stripslashes_deep($commentdata), EXTR_SKIP);^M
85782 ^M
85783 if ( ! isset($comment_author_IP) )^M
85784 $comment_author_IP = '';^M
85785 if ( ! isset($comment_date) )^M
85786 $comment_date = current_time('mysql');^M
85787 if ( ! isset($comment_date_gmt) )^M
85788 $comment_date_gmt = get_gmt_from_date($comment_date);^M
85789 if ( ! isset($comment_parent) )^M
85790 $comment_parent = 0;^M
85791 if ( ! isset($comment_approved) )^M
85792 $comment_approved = 1;^M
85793 if ( ! isset($user_id) )^M
85794 $user_id = 0;^M
85795 if ( ! isset($comment_type) )^M
85796 $comment_type = '';^M
85797 ^M
85798 $result = $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->comments^M
85799 (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)^M
85800 VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d)",^M
85801 $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) );^M
85802 ^M
85803 $id = (int) $wpdb->insert_id;^M
85804 ^M
85805 if ( $comment_approved == 1)^M
85806 wp_update_comment_count($comment_post_ID);^M
85807 ^M
85808 return $id;^M
85809 }^M
85810 ^M
85811 /**^M
85812 * Filters and sanitizes comment data.^M
85813 *^M
85814 * Sets the comment data 'filtered' field to true when finished. This can be^M
85815 * checked as to whether the comment should be filtered and to keep from^M
85816 * filtering the same comment more than once.^M
85817 *^M
85818 * @since 2.0.0^M
85819 * @uses apply_filters() Calls 'pre_user_id' hook on comment author's user ID^M
85820 * @uses apply_filters() Calls 'pre_comment_user_agent' hook on comment author's user agent^M
85821 * @uses apply_filters() Calls 'pre_comment_author_name' hook on comment author's name^M
85822 * @uses apply_filters() Calls 'pre_comment_content' hook on the comment's content^M
85823 * @uses apply_filters() Calls 'pre_comment_user_ip' hook on comment author's IP^M
85824 * @uses apply_filters() Calls 'pre_comment_author_url' hook on comment author's URL^M
85825 * @uses apply_filters() Calls 'pre_comment_author_email' hook on comment author's email address^M
85826 *^M
85827 * @param array $commentdata Contains information on the comment.^M
85828 * @return array Parsed comment information.^M
85829 */^M
85830 function wp_filter_comment($commentdata) {^M
85831 $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);^M
85832 $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']);^M
85833 $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);^M
85834 $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);^M
85835 $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);^M
85836 $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);^M
85837 $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);^M
85838 $commentdata['filtered'] = true;^M
85839 return $commentdata;^M
85840 }^M
85841 ^M
85842 /**^M
85843 * Whether comment should be blocked because of comment flood.^M
85844 *^M
85845 * @since 2.1.0^M
85846 *^M
85847 * @param bool $block Whether plugin has already blocked comment.^M
85848 * @param int $time_lastcomment Timestamp for last comment.^M
85849 * @param int $time_newcomment Timestamp for new comment.^M
85850 * @return bool Whether comment should be blocked.^M
85851 */^M
85852 function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {^M
85853 if ( $block ) // a plugin has already blocked... we'll let that decision stand^M
85854 return $block;^M
85855 if ( ($time_newcomment - $time_lastcomment) < 15 )^M
85856 return true;^M
85857 return false;^M
85858 }^M
85859 ^M
85860 /**^M
85861 * Adds a new comment to the database.^M
85862 *^M
85863 * Filters new comment to ensure that the fields are sanitized and valid before^M
85864 * inserting comment into database. Calls 'comment_post' action with comment ID^M
85865 * and whether comment is approved by WordPress. Also has 'preprocess_comment'^M
85866 * filter for processing the comment data before the function handles it.^M
85867 *^M
85868 * @since 1.5.0^M
85869 * @uses apply_filters() Calls 'preprocess_comment' hook on $commentdata parameter array before processing^M
85870 * @uses do_action() Calls 'comment_post' hook on $comment_ID returned from adding the comment and if the comment was approved.^M
85871 * @uses wp_filter_comment() Used to filter comment before adding comment.^M
85872 * @uses wp_allow_comment() checks to see if comment is approved.^M
85873 * @uses wp_insert_comment() Does the actual comment insertion to the database.^M
85874 *^M
85875 * @param array $commentdata Contains information on the comment.^M
85876 * @return int The ID of the comment after adding.^M
85877 */^M
85878 function wp_new_comment( $commentdata ) {^M
85879 $commentdata = apply_filters('preprocess_comment', $commentdata);^M
85880 ^M
85881 $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];^M
85882 $commentdata['user_ID'] = (int) $commentdata['user_ID'];^M
85883 ^M
85884 $commentdata['comment_parent'] = absint($commentdata['comment_parent']);^M
85885 $parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';^M
85886 $commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;^M
85887 ^M
85888 $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );^M
85889 $commentdata['comment_agent'] = $_SERVER['HTTP_USER_AGENT'];^M
85890 ^M
85891 $commentdata['comment_date'] = current_time('mysql');^M
85892 $commentdata['comment_date_gmt'] = current_time('mysql', 1);^M
85893 ^M
85894 $commentdata = wp_filter_comment($commentdata);^M
85895 ^M
85896 $commentdata['comment_approved'] = wp_allow_comment($commentdata);^M
85897 ^M
85898 $comment_ID = wp_insert_comment($commentdata);^M
85899 ^M
85900 do_action('comment_post', $comment_ID, $commentdata['comment_approved']);^M
85901 ^M
85902 if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching^M
85903 if ( '0' == $commentdata['comment_approved'] )^M
85904 wp_notify_moderator($comment_ID);^M
85905 ^M
85906 $post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment^M
85907 ^M
85908 if ( get_option('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID'] )^M
85909 wp_notify_postauthor($comment_ID, $commentdata['comment_type']);^M
85910 }^M
85911 ^M
85912 return $comment_ID;^M
85913 }^M
85914 ^M
85915 /**^M
85916 * Sets the status of a comment.^M
85917 *^M
85918 * The 'wp_set_comment_status' action is called after the comment is handled and^M
85919 * will only be called, if the comment status is either 'hold', 'approve', or^M
85920 * 'spam'. If the comment status is not in the list, then false is returned and^M
85921 * if the status is 'delete', then the comment is deleted without calling the^M
85922 * action.^M
85923 *^M
85924 * @since 1.0.0^M
85925 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object^M
85926 *^M
85927 * @param int $comment_id Comment ID.^M
85928 * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete'.^M
85929 * @return bool False on failure or deletion and true on success.^M
85930 */^M
85931 function wp_set_comment_status($comment_id, $comment_status) {^M
85932 global $wpdb;^M
85933 ^M
85934 switch ( $comment_status ) {^M
85935 case 'hold':^M
85936 $query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID = %d LIMIT 1", $comment_id);^M
85937 break;^M
85938 case 'approve':^M
85939 $query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID = %d LIMIT 1", $comment_id);^M
85940 if ( get_option('comments_notify') ) {^M
85941 $comment = get_comment($comment_id);^M
85942 wp_notify_postauthor($comment_id, $comment->comment_type);^M
85943 }^M
85944 break;^M
85945 case 'spam':^M
85946 $query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID = %d LIMIT 1", $comment_id);^M
85947 break;^M
85948 case 'delete':^M
85949 return wp_delete_comment($comment_id);^M
85950 break;^M
85951 default:^M
85952 return false;^M
85953 }^M
85954 ^M
85955 if ( !$wpdb->query($query) )^M
85956 return false;^M
85957 ^M
85958 clean_comment_cache($comment_id);^M
85959 ^M
85960 $comment = get_comment($comment_id);^M
85961 ^M
85962 do_action('wp_set_comment_status', $comment_id, $comment_status);^M
85963 wp_transition_comment_status($comment_status, $comment->comment_approved, $comment);^M
85964 ^M
85965 wp_update_comment_count($comment->comment_post_ID);^M
85966 ^M
85967 return true;^M
85968 }^M
85969 ^M
85970 /**^M
85971 * Updates an existing comment in the database.^M
85972 *^M
85973 * Filters the comment and makes sure certain fields are valid before updating.^M
85974 *^M
85975 * @since 2.0.0^M
85976 * @uses $wpdb^M
85977 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object^M
85978 *^M
85979 * @param array $commentarr Contains information on the comment.^M
85980 * @return int Comment was updated if value is 1, or was not updated if value is 0.^M
85981 */^M
85982 function wp_update_comment($commentarr) {^M
85983 global $wpdb;^M
85984 ^M
85985 // First, get all of the original fields^M
85986 $comment = get_comment($commentarr['comment_ID'], ARRAY_A);^M
85987 ^M
85988 // Escape data pulled from DB.^M
85989 foreach ( (array) $comment as $key => $value )^M
85990 $comment[$key] = $wpdb->escape($value);^M
85991 ^M
85992 // Merge old and new fields with new fields overwriting old ones.^M
85993 $commentarr = array_merge($comment, $commentarr);^M
85994 ^M
85995 $commentarr = wp_filter_comment( $commentarr );^M
85996 ^M
85997 // Now extract the merged array.^M
85998 extract(stripslashes_deep($commentarr), EXTR_SKIP);^M
85999 ^M
86000 $comment_content = apply_filters('comment_save_pre', $comment_content);^M
86001 ^M
86002 $comment_date_gmt = get_gmt_from_date($comment_date);^M
86003 ^M
86004 if ( !isset($comment_approved) )^M
86005 $comment_approved = 1;^M
86006 else if ( 'hold' == $comment_approved )^M
86007 $comment_approved = 0;^M
86008 else if ( 'approve' == $comment_approved )^M
86009 $comment_approved = 1;^M
86010 ^M
86011 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->comments SET^M
86012 comment_content = %s,^M
86013 comment_author = %s,^M
86014 comment_author_email = %s,^M
86015 comment_approved = %s,^M
86016 comment_author_url = %s,^M
86017 comment_date = %s,^M
86018 comment_date_gmt = %s^M
86019 WHERE comment_ID = %d",^M
86020 $comment_content,^M
86021 $comment_author,^M
86022 $comment_author_email,^M
86023 $comment_approved,^M
86024 $comment_author_url,^M
86025 $comment_date,^M
86026 $comment_date_gmt,^M
86027 $comment_ID) );^M
86028 ^M
86029 $rval = $wpdb->rows_affected;^M
86030 ^M
86031 clean_comment_cache($comment_ID);^M
86032 wp_update_comment_count($comment_post_ID);^M
86033 do_action('edit_comment', $comment_ID);^M
86034 $comment = get_comment($comment_ID);^M
86035 wp_transition_comment_status($comment_approved, $comment->comment_approved, $comment);^M
86036 return $rval;^M
86037 }^M
86038 ^M
86039 /**^M
86040 * Whether to defer comment counting.^M
86041 *^M
86042 * When setting $defer to true, all post comment counts will not be updated^M
86043 * until $defer is set to false. When $defer is set to false, then all^M
86044 * previously deferred updated post comment counts will then be automatically^M
86045 * updated without having to call wp_update_comment_count() after.^M
86046 *^M
86047 * @since 2.5.0^M
86048 * @staticvar bool $_defer^M
86049 *^M
86050 * @param bool $defer^M
86051 * @return unknown^M
86052 */^M
86053 function wp_defer_comment_counting($defer=null) {^M
86054 static $_defer = false;^M
86055 ^M
86056 if ( is_bool($defer) ) {^M
86057 $_defer = $defer;^M
86058 // flush any deferred counts^M
86059 if ( !$defer )^M
86060 wp_update_comment_count( null, true );^M
86061 }^M
86062 ^M
86063 return $_defer;^M
86064 }^M
86065 ^M
86066 /**^M
86067 * Updates the comment count for post(s).^M
86068 *^M
86069 * When $do_deferred is false (is by default) and the comments have been set to^M
86070 * be deferred, the post_id will be added to a queue, which will be updated at a^M
86071 * later date and only updated once per post ID.^M
86072 *^M
86073 * If the comments have not be set up to be deferred, then the post will be^M
86074 * updated. When $do_deferred is set to true, then all previous deferred post^M
86075 * IDs will be updated along with the current $post_id.^M
86076 *^M
86077 * @since 2.1.0^M
86078 * @see wp_update_comment_count_now() For what could cause a false return value^M
86079 *^M
86080 * @param int $post_id Post ID^M
86081 * @param bool $do_deferred Whether to process previously deferred post comment counts^M
86082 * @return bool True on success, false on failure^M
86083 */^M
86084 function wp_update_comment_count($post_id, $do_deferred=false) {^M
86085 static $_deferred = array();^M
86086 ^M
86087 if ( $do_deferred ) {^M
86088 $_deferred = array_unique($_deferred);^M
86089 foreach ( $_deferred as $i => $_post_id ) {^M
86090 wp_update_comment_count_now($_post_id);^M
86091 unset( $_deferred[$i] ); /** @todo Move this outside of the foreach and reset $_deferred to an array instead */^M
86092 }^M
86093 }^M
86094 ^M
86095 if ( wp_defer_comment_counting() ) {^M
86096 $_deferred[] = $post_id;^M
86097 return true;^M
86098 }^M
86099 elseif ( $post_id ) {^M
86100 return wp_update_comment_count_now($post_id);^M
86101 }^M
86102 ^M
86103 }^M
86104 ^M
86105 /**^M
86106 * Updates the comment count for the post.^M
86107 *^M
86108 * @since 2.5.0^M
86109 * @uses $wpdb^M
86110 * @uses do_action() Calls 'wp_update_comment_count' hook on $post_id, $new, and $old^M
86111 * @uses do_action() Calls 'edit_posts' hook on $post_id and $post^M
86112 *^M
86113 * @param int $post_id Post ID^M
86114 * @return bool False on '0' $post_id or if post with ID does not exist. True on success.^M
86115 */^M
86116 function wp_update_comment_count_now($post_id) {^M
86117 global $wpdb;^M
86118 $post_id = (int) $post_id;^M
86119 if ( !$post_id )^M
86120 return false;^M
86121 if ( !$post = get_post($post_id) )^M
86122 return false;^M
86123 ^M
86124 $old = (int) $post->comment_count;^M
86125 $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) );^M
86126 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_count = %d WHERE ID = %d", $new, $post_id) );^M
86127 ^M
86128 if ( 'page' == $post->post_type )^M
86129 clean_page_cache( $post_id );^M
86130 else^M
86131 clean_post_cache( $post_id );^M
86132 ^M
86133 do_action('wp_update_comment_count', $post_id, $new, $old);^M
86134 do_action('edit_post', $post_id, $post);^M
86135 ^M
86136 return true;^M
86137 }^M
86138 ^M
86139 //^M
86140 // Ping and trackback functions.^M
86141 //^M
86142 ^M
86143 /**^M
86144 * Finds a pingback server URI based on the given URL.^M
86145 *^M
86146 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does^M
86147 * a check for the x-pingback headers first and returns that, if available. The^M
86148 * check for the rel="pingback" has more overhead than just the header.^M
86149 *^M
86150 * @since 1.5.0^M
86151 *^M
86152 * @param string $url URL to ping.^M
86153 * @param int $deprecated Not Used.^M
86154 * @return bool|string False on failure, string containing URI on success.^M
86155 */^M
86156 function discover_pingback_server_uri($url, $deprecated = 2048) {^M
86157 ^M
86158 $pingback_str_dquote = 'rel="pingback"';^M
86159 $pingback_str_squote = 'rel=\'pingback\'';^M
86160 ^M
86161 /** @todo Should use Filter Extension or custom preg_match instead. */^M
86162 $parsed_url = parse_url($url);^M
86163 ^M
86164 if ( ! isset( $parsed_url['host'] ) ) // Not an URL. This should never happen.^M
86165 return false;^M
86166 ^M
86167 $response = wp_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.1' ) );^M
86168 ^M
86169 if ( is_wp_error( $response ) )^M
86170 return false;^M
86171 ^M
86172 if ( isset( $response['headers']['x-pingback'] ) )^M
86173 return $response['headers']['x-pingback'];^M
86174 ^M
86175 // Not an (x)html, sgml, or xml page, no use going further.^M
86176 if ( isset( $response['headers']['content-type'] ) && preg_match('#(image|audio|video|model)/#is', $response['headers']['content-type']) )^M
86177 return false;^M
86178 ^M
86179 $contents = $response['body'];^M
86180 ^M
86181 $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);^M
86182 $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);^M
86183 if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {^M
86184 $quote = ($pingback_link_offset_dquote) ? '"' : '\'';^M
86185 $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;^M
86186 $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);^M
86187 $pingback_href_start = $pingback_href_pos+6;^M
86188 $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);^M
86189 $pingback_server_url_len = $pingback_href_end - $pingback_href_start;^M
86190 $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);^M
86191 ^M
86192 // We may find rel="pingback" but an incomplete pingback URL^M
86193 if ( $pingback_server_url_len > 0 ) { // We got it!^M
86194 return $pingback_server_url;^M
86195 }^M
86196 }^M
86197 ^M
86198 return false;^M
86199 }^M
86200 ^M
86201 /**^M
86202 * Perform all pingbacks, enclosures, trackbacks, and send to pingback services.^M
86203 *^M
86204 * @since 2.1.0^M
86205 * @uses $wpdb^M
86206 */^M
86207 function do_all_pings() {^M
86208 global $wpdb;^M
86209 ^M
86210 // Do pingbacks^M
86211 while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {^M
86212 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");^M
86213 pingback($ping->post_content, $ping->ID);^M
86214 }^M
86215 ^M
86216 // Do Enclosures^M
86217 while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {^M
86218 $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_encloseme';", $enclosure->ID) );^M
86219 do_enclose($enclosure->post_content, $enclosure->ID);^M
86220 }^M
86221 ^M
86222 // Do Trackbacks^M
86223 $trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'");^M
86224 if ( is_array($trackbacks) )^M
86225 foreach ( $trackbacks as $trackback )^M
86226 do_trackbacks($trackback);^M
86227 ^M
86228 //Do Update Services/Generic Pings^M
86229 generic_ping();^M
86230 }^M
86231 ^M
86232 /**^M
86233 * Perform trackbacks.^M
86234 *^M
86235 * @since 1.5.0^M
86236 * @uses $wpdb^M
86237 *^M
86238 * @param int $post_id Post ID to do trackbacks on.^M
86239 */^M
86240 function do_trackbacks($post_id) {^M
86241 global $wpdb;^M
86242 ^M
86243 $post = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id) );^M
86244 $to_ping = get_to_ping($post_id);^M
86245 $pinged = get_pung($post_id);^M
86246 if ( empty($to_ping) ) {^M
86247 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = '' WHERE ID = %d", $post_id) );^M
86248 return;^M
86249 }^M
86250 ^M
86251 if ( empty($post->post_excerpt) )^M
86252 $excerpt = apply_filters('the_content', $post->post_content);^M
86253 else^M
86254 $excerpt = apply_filters('the_excerpt', $post->post_excerpt);^M
86255 $excerpt = str_replace(']]>', ']]>', $excerpt);^M
86256 $excerpt = wp_html_excerpt($excerpt, 252) . '...';^M
86257 ^M
86258 $post_title = apply_filters('the_title', $post->post_title);^M
86259 $post_title = strip_tags($post_title);^M
86260 ^M
86261 if ( $to_ping ) {^M
86262 foreach ( (array) $to_ping as $tb_ping ) {^M
86263 $tb_ping = trim($tb_ping);^M
86264 if ( !in_array($tb_ping, $pinged) ) {^M
86265 trackback($tb_ping, $post_title, $excerpt, $post_id);^M
86266 $pinged[] = $tb_ping;^M
86267 } else {^M
86268 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = %d", $post_id) );^M
86269 }^M
86270 }^M
86271 }^M
86272 }^M
86273 ^M
86274 /**^M
86275 * Sends pings to all of the ping site services.^M
86276 *^M
86277 * @since 1.2.0^M
86278 *^M
86279 * @param int $post_id Post ID. Not actually used.^M
86280 * @return int Same as Post ID from parameter^M
86281 */^M
86282 function generic_ping($post_id = 0) {^M
86283 $services = get_option('ping_sites');^M
86284 ^M
86285 $services = explode("\n", $services);^M
86286 foreach ( (array) $services as $service ) {^M
86287 $service = trim($service);^M
86288 if ( '' != $service )^M
86289 weblog_ping($service);^M
86290 }^M
86291 ^M
86292 return $post_id;^M
86293 }^M
86294 ^M
86295 /**^M
86296 * Pings back the links found in a post.^M
86297 *^M
86298 * @since 0.71^M
86299 * @uses $wp_version^M
86300 * @uses IXR_Client^M
86301 *^M
86302 * @param string $content Post content to check for links.^M
86303 * @param int $post_ID Post ID.^M
86304 */^M
86305 function pingback($content, $post_ID) {^M
86306 global $wp_version;^M
86307 include_once(ABSPATH . WPINC . '/class-IXR.php');^M
86308 ^M
86309 // original code by Mort (http://mort.mine.nu:8080)^M
86310 $post_links = array();^M
86311 ^M
86312 $pung = get_pung($post_ID);^M
86313 ^M
86314 // Variables^M
86315 $ltrs = '\w';^M
86316 $gunk = '/#~:.?+=&%@!\-';^M
86317 $punc = '.:?\-';^M
86318 $any = $ltrs . $gunk . $punc;^M
86319 ^M
86320 // Step 1^M
86321 // Parsing the post, external links (if any) are stored in the $post_links array^M
86322 // This regexp comes straight from phpfreaks.com^M
86323 // http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php^M
86324 preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);^M
86325 ^M
86326 // Step 2.^M
86327 // Walking thru the links array^M
86328 // first we get rid of links pointing to sites, not to specific files^M
86329 // Example:^M
86330 // http://dummy-weblog.org^M
86331 // http://dummy-weblog.org/^M
86332 // http://dummy-weblog.org/post.php^M
86333 // We don't wanna ping first and second types, even if they have a valid <link/>^M
86334 ^M
86335 foreach ( (array) $post_links_temp[0] as $link_test ) :^M
86336 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^M
86337 && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.^M
86338 if ( $test = @parse_url($link_test) ) {^M
86339 if ( isset($test['query']) )^M
86340 $post_links[] = $link_test;^M
86341 elseif ( ($test['path'] != '/') && ($test['path'] != '') )^M
86342 $post_links[] = $link_test;^M
86343 }^M
86344 endif;^M
86345 endforeach;^M
86346 ^M
86347 do_action_ref_array('pre_ping', array(&$post_links, &$pung));^M
86348 ^M
86349 foreach ( (array) $post_links as $pagelinkedto ) {^M
86350 $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048);^M
86351 ^M
86352 if ( $pingback_server_url ) {^M
86353 @ set_time_limit( 60 );^M
86354 // Now, the RPC call^M
86355 $pagelinkedfrom = get_permalink($post_ID);^M
86356 ^M
86357 // using a timeout of 3 seconds should be enough to cover slow servers^M
86358 $client = new IXR_Client($pingback_server_url);^M
86359 $client->timeout = 3;^M
86360 $client->useragent .= ' -- WordPress/' . $wp_version;^M
86361 ^M
86362 // when set to true, this outputs debug messages by itself^M
86363 $client->debug = false;^M
86364 ^M
86365 if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) ) // Already registered^M
86366 add_ping( $post_ID, $pagelinkedto );^M
86367 }^M
86368 }^M
86369 }^M
86370 ^M
86371 /**^M
86372 * Check whether blog is public before returning sites.^M
86373 *^M
86374 * @since 2.1.0^M
86375 *^M
86376 * @param mixed $sites Will return if blog is public, will not return if not public.^M
86377 * @return mixed Empty string if blog is not public, returns $sites, if site is public.^M
86378 */^M
86379 function privacy_ping_filter($sites) {^M
86380 if ( '0' != get_option('blog_public') )^M
86381 return $sites;^M
86382 else^M
86383 return '';^M
86384 }^M
86385 ^M
86386 /**^M
86387 * Send a Trackback.^M
86388 *^M
86389 * Updates database when sending trackback to prevent duplicates.^M
86390 *^M
86391 * @since 0.71^M
86392 * @uses $wpdb^M
86393 *^M
86394 * @param string $trackback_url URL to send trackbacks.^M
86395 * @param string $title Title of post.^M
86396 * @param string $excerpt Excerpt of post.^M
86397 * @param int $ID Post ID.^M
86398 * @return mixed Database query from update.^M
86399 */^M
86400 function trackback($trackback_url, $title, $excerpt, $ID) {^M
86401 global $wpdb;^M
86402 ^M
86403 if ( empty($trackback_url) )^M
86404 return;^M
86405 ^M
86406 $options = array();^M
86407 $options['timeout'] = 4;^M
86408 $options['body'] = array(^M
86409 'title' => $title,^M
86410 'url' => get_permalink($ID),^M
86411 'blog_name' => get_option('blogname'),^M
86412 'excerpt' => $excerpt^M
86413 );^M
86414 ^M
86415 $response = wp_remote_post($trackback_url, $options);^M
86416 ^M
86417 if ( is_wp_error( $response ) )^M
86418 return;^M
86419 ^M
86420 $tb_url = addslashes( $trackback_url );^M
86421 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = %d", $ID) );^M
86422 return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_url', '')) WHERE ID = %d", $ID) );^M
86423 }^M
86424 ^M
86425 /**^M
86426 * Send a pingback.^M
86427 *^M
86428 * @since 1.2.0^M
86429 * @uses $wp_version^M
86430 * @uses IXR_Client^M
86431 *^M
86432 * @param string $server Host of blog to connect to.^M
86433 * @param string $path Path to send the ping.^M
86434 */^M
86435 function weblog_ping($server = '', $path = '') {^M
86436 global $wp_version;^M
86437 include_once(ABSPATH . WPINC . '/class-IXR.php');^M
86438 ^M
86439 // using a timeout of 3 seconds should be enough to cover slow servers^M
86440 $client = new IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path));^M
86441 $client->timeout = 3;^M
86442 $client->useragent .= ' -- WordPress/'.$wp_version;^M
86443 ^M
86444 // when set to true, this outputs debug messages by itself^M
86445 $client->debug = false;^M
86446 $home = trailingslashit( get_option('home') );^M
86447 if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping^M
86448 $client->query('weblogUpdates.ping', get_option('blogname'), $home);^M
86449 }^M
86450 ^M
86451 //^M
86452 // Cache^M
86453 //^M
86454 ^M
86455 /**^M
86456 * Removes comment ID from the comment cache.^M
86457 *^M
86458 * @since 2.3.0^M
86459 * @package WordPress^M
86460 * @subpackage Cache^M
86461 *^M
86462 * @param int $id Comment ID to remove from cache^M
86463 */^M
86464 function clean_comment_cache($id) {^M
86465 wp_cache_delete($id, 'comment');^M
86466 }^M
86467 ^M
86468 /**^M
86469 * Updates the comment cache of given comments.^M
86470 *^M
86471 * Will add the comments in $comments to the cache. If comment ID already exists^M
86472 * in the comment cache then it will not be updated. The comment is added to the^M
86473 * cache using the comment group with the key using the ID of the comments.^M
86474 *^M
86475 * @since 2.3.0^M
86476 * @package WordPress^M
86477 * @subpackage Cache^M
86478 *^M
86479 * @param array $comments Array of comment row objects^M
86480 */^M
86481 function update_comment_cache($comments) {^M
86482 foreach ( (array) $comments as $comment )^M
86483 wp_cache_add($comment->comment_ID, $comment, 'comment');^M
86484 }^M
86485 ^M
86486 //^M
86487 // Internal^M
86488 //^M
86489 ^M
86490 /**^M
86491 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.^M
86492 *^M
86493 * @access private^M
86494 * @since 2.7.0^M
86495 *^M
86496 * @param object $posts Post data object.^M
86497 * @return object^M
86498 */^M
86499 function _close_comments_for_old_posts( $posts ) {^M
86500 if ( empty($posts) || !is_single() || !get_option('close_comments_for_old_posts') )^M
86501 return $posts;^M
86502 ^M
86503 $days_old = (int) get_option('close_comments_days_old');^M
86504 if ( !$days_old )^M
86505 return $posts;^M
86506 ^M
86507 if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) ) {^M
86508 $posts[0]->comment_status = 'closed';^M
86509 $posts[0]->ping_status = 'closed';^M
86510 }^M
86511 ^M
86512 return $posts;^M
86513 }^M
86514 ^M
86515 /**^M
86516 * Close comments on an old post. Hooked to comments_open and pings_open.^M
86517 *^M
86518 * @access private^M
86519 * @since 2.7.0^M
86520 *^M
86521 * @param bool $open Comments open or closed^M
86522 * @param int $post_id Post ID^M
86523 * @return bool $open^M
86524 */^M
86525 function _close_comments_for_old_post( $open, $post_id ) {^M
86526 if ( ! $open )^M
86527 return $open;^M
86528 ^M
86529 if ( !get_option('close_comments_for_old_posts') )^M
86530 return $open;^M
86531 ^M
86532 $days_old = (int) get_option('close_comments_days_old');^M
86533 if ( !$days_old )^M
86534 return $open;^M
86535 ^M
86536 $post = get_post($post_id);^M
86537 ^M
86538 if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) )^M
86539 return false;^M
86540 ^M
86541 return $open;^M
86542 }^M
86543 ^M
86544 ?>^M