Make WordPress Core


Ignore:
Timestamp:
12/07/2006 03:57:23 AM (19 years ago)
Author:
markjaquith
Message:

Bunch of whitespace and coding standardization.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r4495 r4626  
    44    global $wpdb;
    55
    6     if (1 == get_option('comment_moderation')) return false; // If moderation is set to manual
     6    if ( 1 == get_option('comment_moderation') )
     7        return false; // If moderation is set to manual
    78
    89    if ( preg_match_all("|(href\t*?=\t*?['\"]?)?(https?:)?//|i", $comment, $out) >= get_option('comment_max_links') )
    910        return false; // Check # of external links
    1011
    11     $mod_keys = trim( get_option('moderation_keys') );
     12    $mod_keys = trim(get_option('moderation_keys'));
    1213    if ( !empty($mod_keys) ) {
    1314        $words = explode("\n", $mod_keys );
     
    1718
    1819            // Skip empty lines
    19             if (empty($word)) { continue; }
     20            if ( empty($word) )
     21                continue;
    2022
    2123            // Do some escaping magic so that '#' chars in the
     
    4446            else
    4547                return false;
    46         } elseif( $author != '' && $email != '' ) {
     48        } elseif ( $author != '' && $email != '' ) {
    4749            $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");
    4850            if ( ( 1 == $ok_to_comment ) &&
     
    5557        }
    5658    }
    57 
    5859    return true;
    5960}
     61
    6062
    6163function get_approved_comments($post_id) {
     
    6567    return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1' ORDER BY comment_date");
    6668}
     69
    6770
    6871// Retrieves comment data given a comment ID or comment object.
     
    98101}
    99102
     103
    100104// Deprecate in favor of get_comment()?
    101105function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries
    102106    global $postc, $id, $commentdata, $wpdb;
    103     if ($no_cache) {
     107    if ( $no_cache ) {
    104108        $query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'";
    105         if (false == $include_unapproved) {
    106                 $query .= " AND comment_approved = '1'";
    107         }
    108                 $myrow = $wpdb->get_row($query, ARRAY_A);
     109        if ( false == $include_unapproved )
     110            $query .= " AND comment_approved = '1'";
     111        $myrow = $wpdb->get_row($query, ARRAY_A);
    109112    } else {
    110         $myrow['comment_ID'] = $postc->comment_ID;
    111         $myrow['comment_post_ID'] = $postc->comment_post_ID;
    112         $myrow['comment_author'] = $postc->comment_author;
     113        $myrow['comment_ID']           = $postc->comment_ID;
     114        $myrow['comment_post_ID']      = $postc->comment_post_ID;
     115        $myrow['comment_author']       = $postc->comment_author;
    113116        $myrow['comment_author_email'] = $postc->comment_author_email;
    114         $myrow['comment_author_url'] = $postc->comment_author_url;
    115         $myrow['comment_author_IP'] = $postc->comment_author_IP;
    116         $myrow['comment_date'] = $postc->comment_date;
    117         $myrow['comment_content'] = $postc->comment_content;
    118         $myrow['comment_karma'] = $postc->comment_karma;
    119         $myrow['comment_approved'] = $postc->comment_approved;
    120         $myrow['comment_type'] = $postc->comment_type;
     117        $myrow['comment_author_url']   = $postc->comment_author_url;
     118        $myrow['comment_author_IP']    = $postc->comment_author_IP;
     119        $myrow['comment_date']         = $postc->comment_date;
     120        $myrow['comment_content']      = $postc->comment_content;
     121        $myrow['comment_karma']        = $postc->comment_karma;
     122        $myrow['comment_approved']     = $postc->comment_approved;
     123        $myrow['comment_type']         = $postc->comment_type;
    121124    }
    122125    return $myrow;
    123126}
     127
    124128
    125129function get_lastcommentmodified($timezone = 'server') {
     
    129133    $now = current_time('mysql', 1);
    130134    if ( !isset($cache_lastcommentmodified[$timezone]) ) {
    131         switch(strtolower($timezone)) {
     135        switch ( strtolower($timezone)) {
    132136            case 'gmt':
    133137                $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1");
     
    147151}
    148152
     153
    149154function sanitize_comment_cookies() {
    150155    if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) {
     
    169174    }
    170175}
     176
    171177
    172178function wp_allow_comment($commentdata) {
     
    199205    }
    200206
    201     // The author and the admins get respect.
    202207    if ( $userdata && ( $user_id == $post_author || $user->has_cap('level_9') ) ) {
     208        // The author and the admins get respect.
    203209        $approved = 1;
    204     }
    205 
    206     // Everyone else's comments will be checked.
    207     else {
     210     } else {
     211        // Everyone else's comments will be checked.
    208212        if ( check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type) )
    209213            $approved = 1;
     
    218222}
    219223
     224
    220225function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {
    221226    global $wpdb;
     
    224229
    225230    if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) {
    226         foreach ($chars[1] as $char) {
     231        foreach ( (array) $chars[1] as $char ) {
    227232            // If it's an encoded char in the normal ASCII set, reject
    228233            if ( 38 == $char )
    229234                continue; // Unless it's &
    230             if ($char < 128)
     235            if ( $char < 128 )
    231236                return true;
    232237        }
     
    234239
    235240    $mod_keys = trim( get_option('blacklist_keys') );
    236     if ('' == $mod_keys )
     241    if ( '' == $mod_keys )
    237242        return false; // If moderation keys are empty
    238243    $words = explode("\n", $mod_keys );
    239244
    240     foreach ($words as $word) {
     245    foreach ( (array) $words as $word ) {
    241246        $word = trim($word);
    242247
     
    249254
    250255        $pattern = "#$word#i";
    251         if ( preg_match($pattern, $author    ) ) return true;
    252         if ( preg_match($pattern, $email     ) ) return true;
    253         if ( preg_match($pattern, $url       ) ) return true;
    254         if ( preg_match($pattern, $comment   ) ) return true;
    255         if ( preg_match($pattern, $user_ip   ) ) return true;
    256         if ( preg_match($pattern, $user_agent) ) return true;
    257     }
    258 
     256        if (
     257               preg_match($pattern, $author)
     258            || preg_match($pattern, $email)
     259            || preg_match($pattern, $url)
     260            || preg_match($pattern, $comment)
     261            || preg_match($pattern, $user_ip)
     262            || preg_match($pattern, $user_agent)
     263         )
     264            return true;
     265    }
    259266    return false;
    260267}
     268
    261269
    262270function wp_delete_comment($comment_id) {
     
    277285}
    278286
     287
    279288function wp_get_comment_status($comment_id) {
    280289    global $wpdb;
    281290
    282291    $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
    283     if ($result == NULL) {
     292
     293    if ( $result == NULL )
    284294        return 'deleted';
    285     } else if ($result == '1') {
     295    elseif ( $result == '1' )
    286296        return 'approved';
    287     } else if ($result == '0') {
     297    elseif ( $result == '0' )
    288298        return 'unapproved';
    289     } else if ($result == 'spam') {
     299    elseif ( $result == 'spam' )
    290300        return 'spam';
    291     } else {
     301    else
    292302        return false;
    293     }
    294 }
     303}
     304
    295305
    296306function wp_get_current_commenter() {
     
    311321    return compact('comment_author', 'comment_author_email', 'comment_author_url');
    312322}
     323
    313324
    314325function wp_insert_comment($commentdata) {
     
    343354}
    344355
     356
    345357function wp_filter_comment($commentdata) {
    346358    $commentdata['user_id']              = apply_filters('pre_user_id', $commentdata['user_ID']);
     
    355367}
    356368
     369
    357370function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {
    358371    if ( $block ) // a plugin has already blocked... we'll let that decision stand
     
    363376}
    364377
     378
    365379function wp_new_comment( $commentdata ) {
    366380    $commentdata = apply_filters('preprocess_comment', $commentdata);
     
    374388    $commentdata['comment_date']     = current_time('mysql');
    375389    $commentdata['comment_date_gmt'] = current_time('mysql', 1);
    376 
    377390
    378391    $commentdata = wp_filter_comment($commentdata);
     
    397410}
    398411
     412
    399413function wp_set_comment_status($comment_id, $comment_status) {
    400         global $wpdb;
    401 
    402         switch($comment_status) {
     414    global $wpdb;
     415
     416    switch ( $comment_status ) {
    403417        case 'hold':
    404418            $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1";
    405         break;
     419            break;
    406420        case 'approve':
    407421            $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";
    408         break;
     422            break;
    409423        case 'spam':
    410424            $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1";
    411         break;
     425            break;
    412426        case 'delete':
    413427            return wp_delete_comment($comment_id);
    414         break;
     428            break;
    415429        default:
    416430            return false;
    417         }
    418 
    419         if ($wpdb->query($query)) {
     431    }
     432
     433    if ( $wpdb->query($query) ) {
    420434        do_action('wp_set_comment_status', $comment_id, $comment_status);
    421435
    422436        $comment = get_comment($comment_id);
    423437        $comment_post_ID = $comment->comment_post_ID;
    424         $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'" );
    425         if( is_object( $c ) )
    426             $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" );
     438        $c = $wpdb->get_row("SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'");
     439        if ( is_object($c) )
     440            $wpdb->query("UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'");
    427441        return true;
    428         } else {
     442    } else {
    429443        return false;
    430         }
    431 }
     444    }
     445}
     446
    432447
    433448function wp_update_comment($commentarr) {
     
    438453
    439454    // Escape data pulled from DB.
    440     foreach ($comment as $key => $value)
     455    foreach ( (array) $comment as $key => $value )
    441456        $comment[$key] = $wpdb->escape($value);
    442457
     
    453468    $result = $wpdb->query(
    454469        "UPDATE $wpdb->comments SET
    455             comment_content = '$comment_content',
    456             comment_author = '$comment_author',
     470            comment_content      = '$comment_content',
     471            comment_author       = '$comment_author',
    457472            comment_author_email = '$comment_author_email',
    458             comment_approved = '$comment_approved',
    459             comment_author_url = '$comment_author_url',
    460             comment_date = '$comment_date'
     473            comment_approved     = '$comment_approved',
     474            comment_author_url   = '$comment_author_url',
     475            comment_date         = '$comment_date'
    461476        WHERE comment_ID = $comment_ID" );
    462477
    463478    $rval = $wpdb->rows_affected;
    464 
    465479    wp_update_comment_count($comment_post_ID);
    466 
    467480    do_action('edit_comment', $comment_ID);
    468 
    469481    return $rval;
    470482}
     483
    471484
    472485function wp_update_comment_count($post_id) {
     
    481494}
    482495
     496
    483497//
    484498// Ping and trackback functions.
     
    498512    extract(parse_url($url));
    499513
    500     if (!isset($host)) {
    501         // Not an URL. This should never happen.
     514    if ( !isset($host) ) // Not an URL. This should never happen.
    502515        return false;
    503     }
    504 
    505     $path  = (!isset($path)) ? '/'        : $path;
    506     $path .= (isset($query)) ? '?'.$query : '';
    507     $port  = (isset($port))  ? $port      : 80;
     516
     517    $path  = ( !isset($path) ) ? '/'          : $path;
     518    $path .= ( isset($query) ) ? '?' . $query : '';
     519    $port  = ( isset($port)  ) ? $port        : 80;
    508520
    509521    // Try to connect to the server at $host
    510522    $fp = @fsockopen($host, $port, $errno, $errstr, 2);
    511     if (!$fp) {
    512         // Couldn't open a connection to $host;
     523    if ( !$fp ) // Couldn't open a connection to $host
    513524        return false;
    514     }
    515525
    516526    // Send the GET request
    517527    $request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: WordPress/$wp_version \r\n\r\n";
    518 //  ob_end_flush();
     528    // ob_end_flush();
    519529    fputs($fp, $request);
    520530
    521531    // Let's check for an X-Pingback header first
    522     while (!feof($fp)) {
     532    while ( !feof($fp) ) {
    523533        $line = fgets($fp, 512);
    524         if (trim($line) == '') {
     534        if ( trim($line) == '' )
    525535            break;
    526         }
    527536        $headers .= trim($line)."\n";
    528537        $x_pingback_header_offset = strpos(strtolower($headers), $x_pingback_str);
    529         if ($x_pingback_header_offset) {
     538        if ( $x_pingback_header_offset ) {
    530539            // We got it!
    531540            preg_match('#x-pingback: (.+)#is', $headers, $matches);
     
    533542            return $pingback_server_url;
    534543        }
    535         if(strpos(strtolower($headers), 'content-type: ')) {
     544        if ( strpos(strtolower($headers), 'content-type: ') ) {
    536545            preg_match('#content-type: (.+)#is', $headers, $matches);
    537546            $content_type = trim($matches[1]);
     
    539548    }
    540549
    541     if (preg_match('#(image|audio|video|model)/#is', $content_type)) {
    542         // Not an (x)html, sgml, or xml page, no use going further
     550    if ( preg_match('#(image|audio|video|model)/#is', $content_type) ) // Not an (x)html, sgml, or xml page, no use going further
    543551        return false;
    544     }
    545 
    546     while (!feof($fp)) {
     552
     553    while ( !feof($fp) ) {
    547554        $line = fgets($fp, 1024);
    548555        $contents .= trim($line);
    549556        $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    550557        $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    551         if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
     558        if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {
    552559            $quote = ($pingback_link_offset_dquote) ? '"' : '\'';
    553560            $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
     
    558565            $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
    559566            // We may find rel="pingback" but an incomplete pingback URL
    560             if ($pingback_server_url_len > 0) {
    561                 // We got it!
     567            if ( $pingback_server_url_len > 0 ) // We got it!
    562568                return $pingback_server_url;
    563             }
    564569        }
    565570        $byte_count += strlen($line);
    566         if ($byte_count > $timeout_bytes) {
     571        if ( $byte_count > $timeout_bytes ) {
    567572            // It's no use going further, there probably isn't any pingback
    568573            // server to find in this file. (Prevents loading large files.)
     
    574579    return false;
    575580}
     581
    576582
    577583function do_all_pings() {
     
    593599    $trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status = 'publish'");
    594600    if ( is_array($trackbacks) ) {
    595         foreach ( $trackbacks as $trackback ) {
     601        foreach ( $trackbacks as $trackback )
    596602            do_trackbacks($trackback->ID);
    597         }
    598603    }
    599604
     
    613618    }
    614619
    615     if (empty($post->post_excerpt))
     620    if ( empty($post->post_excerpt) )
    616621        $excerpt = apply_filters('the_content', $post->post_content);
    617622    else
     
    627632    $post_title = strip_tags($post_title);
    628633
    629     if ($to_ping) : foreach ($to_ping as $tb_ping) :
    630         $tb_ping = trim($tb_ping);
    631         if ( !in_array($tb_ping, $pinged) ) {
    632             trackback($tb_ping, $post_title, $excerpt, $post_id);
    633             $pinged[] = $tb_ping;
    634         } else {
    635             $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = '$post_id'");
    636         }
    637     endforeach; endif;
    638 }
     634    if ( $to_ping ) {
     635        foreach ( (array) $to_ping as $tb_ping ) {
     636            $tb_ping = trim($tb_ping);
     637            if ( !in_array($tb_ping, $pinged) ) {
     638                trackback($tb_ping, $post_title, $excerpt, $post_id);
     639                $pinged[] = $tb_ping;
     640            } else {
     641                $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = '$post_id'");
     642            }
     643        }
     644    }
     645}
     646
    639647
    640648function generic_ping($post_id = 0) {
     
    644652    if ( '' != $services ) {
    645653        $services = explode("\n", $services);
    646         foreach ($services as $service) {
     654        foreach ( (array) $services as $service )
    647655            weblog_ping($service);
    648         }
    649656    }
    650657
    651658    return $post_id;
    652659}
     660
    653661
    654662function pingback($content, $post_ID) {
    655663    global $wp_version, $wpdb;
    656     include_once (ABSPATH . WPINC . '/class-IXR.php');
     664    include_once(ABSPATH . WPINC . '/class-IXR.php');
    657665
    658666    // original code by Mort (http://mort.mine.nu:8080)
    659667    $log = debug_fopen(ABSPATH . '/pingback.log', 'a');
    660668    $post_links = array();
    661     debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
     669    debug_fwrite($log, 'BEGIN ' . date('YmdHis', time()) . "\n");
    662670
    663671    $pung = get_pung($post_ID);
     
    688696    // We don't wanna ping first and second types, even if they have a valid <link/>
    689697
    690     foreach($post_links_temp[0] as $link_test) :
     698    foreach ( $post_links_temp[0] as $link_test ) :
    691699        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
    692700                && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
    693701            $test = parse_url($link_test);
    694             if (isset($test['query']))
     702            if ( isset($test['query']) )
    695703                $post_links[] = $link_test;
    696             elseif(($test['path'] != '/') && ($test['path'] != ''))
     704            elseif ( ($test['path'] != '/') && ($test['path'] != '') )
    697705                $post_links[] = $link_test;
    698706        endif;
    699707    endforeach;
    700708
    701     do_action_ref_array('pre_ping',  array(&$post_links, &$pung));
    702 
    703     foreach ($post_links as $pagelinkedto){
     709    do_action_ref_array('pre_ping', array(&$post_links, &$pung));
     710
     711    foreach ( (array) $post_links as $pagelinkedto ) {
    704712        debug_fwrite($log, "Processing -- $pagelinkedto\n");
    705713        $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048);
    706714
    707         if ($pingback_server_url) {
     715        if ( $pingback_server_url ) {
    708716            @ set_time_limit( 60 );
    709717             // Now, the RPC call
     
    732740}
    733741
    734 function privacy_ping_filter( $sites ) {
     742
     743function privacy_ping_filter($sites) {
    735744    if ( '0' != get_option('blog_public') )
    736745        return $sites;
     
    781790}
    782791
     792
    783793function weblog_ping($server = '', $path = '') {
    784794    global $wp_version;
    785     include_once (ABSPATH . WPINC . '/class-IXR.php');
     795    include_once(ABSPATH . WPINC . '/class-IXR.php');
    786796
    787797    // using a timeout of 3 seconds should be enough to cover slow servers
Note: See TracChangeset for help on using the changeset viewer.