Make WordPress Core

Changeset 549


Ignore:
Timestamp:
11/15/2003 08:58:18 AM (22 years ago)
Author:
saxmatt
Message:

Cleaning up comment moderation and the comment code in general. More to do tomorrow with regards to wp-moderation.php.

Location:
trunk
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/b2-include/b2functions.php

    r548 r549  
    6565}
    6666
    67 function wpautop($pee, $br=1) {
     67function wpautop($pee, $br = 1) {
    6868    $pee = $pee . "\n"; // just to make things a little easier, pad the end
    6969    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
     
    170170    }
    171171    return $j;
     172}
     173
     174function current_time($type) {
     175    $time_difference = get_settings('time_difference');
     176    switch ($type) {
     177        case 'mysql':
     178            return date('Y-m-d H:i:s', (time() + ($time_difference * 3600) ) );
     179            break;
     180        case 'timestamp':
     181            return (time() + ($time_difference * 3600) );
     182            break;
     183    }
    172184}
    173185
     
    13951407
    13961408    switch($comment_status) {
    1397     case 'hold':
    1398     $query = "UPDATE $tablecomments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1";
    1399     break;
    1400     case 'approve':
    1401     $query = "UPDATE $tablecomments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";
    1402     break;
    1403     case 'delete':
    1404     $query = "DELETE FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1";
    1405     break;
    1406     default:
    1407     return false;
     1409        case 'hold':
     1410            $query = "UPDATE $tablecomments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1";
     1411        break;
     1412        case 'approve':
     1413            $query = "UPDATE $tablecomments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";
     1414        break;
     1415        case 'delete':
     1416            $query = "DELETE FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1";
     1417        break;
     1418        default:
     1419            return false;
    14081420    }
    14091421   
    14101422    if ($wpdb->query($query)) {
    1411     return true;
     1423        return true;
    14121424    } else {
    1413     return false;
     1425        return false;
    14141426    }
    14151427}
  • trunk/b2comments.php

    r546 r549  
    2020<!-- You can start editing here. -->
    2121
    22 <h2>Comments</h2>
     22<h2 id="comments">Comments</h2>
    2323
    24 <p><a href="<?php echo $siteurl; ?>/wp-commentsrss2.php?p=<?php echo $id; ?>">RSS feed for comments on this post.</a></p>
     24<p><a href="<?php echo $siteurl; ?>/wp-commentsrss2.php?p=<?php echo $id; ?>"><abbr title="Really Simple Syndication">RSS</abbr> feed for comments on this post.</a></p>
    2525
    2626<?php if ('open' == $post->ping_status) { ?>
     
    2828<?php } ?>
    2929
    30 <ol id="comments">
    31 <?php
    32 // this line is WordPress' motor, do not delete it.
    33 if ($comments) {
    34     foreach ($comments as $comment) {
    35 ?>
    36    
    37 <li id="comment-<?php comment_ID() ?>">
    38 <?php comment_text() ?>
    39 <p><cite><?php comment_type(); ?> by <?php comment_author_link() ?> &#8212; <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite></p>
    40 </li>
    4130
    42 <?php } // end for each comment
    43 } else { // this is displayed if there are no comments so far
    44 ?>
    45     <li>No comments yet.</li>
     31<?php if ($comments) { ?>
     32<ol id="commentlist">
     33<?php foreach ($comments as $comment) { ?>
     34    <li id="comment-<?php comment_ID() ?>">
     35    <?php comment_text() ?>
     36    <p><cite><?php comment_type(); ?> by <?php comment_author_link() ?> &#8212; <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite></p>
     37    </li>
     38
     39<?php } // end for each comment ?>
     40</ol>
     41<?php } else { // this is displayed if there are no comments so far ?>
     42    <p>No comments yet.</p>
    4643<?php } ?>
    47 </ol>
     44
    4845<h2>Leave a Comment</h2>
    4946<?php if ('open' == $post->comment_status) { ?>
     
    7875?>
    7976    <p>
    80     <strong>Please note:</strong><br />
    81     This blog uses comment moderation. In other words: your comment will need approval
    82     by the administrator before it will appear in the blog. Approval usually happens
    83     within the next 24 hours. Please send your comment only once. Thank you.
     77    <strong>Please note:</strong> Comment moderation is currently enabled so there may be a delay between when you post your comment and when it shows up. Patience is a virtue; there&#8217;s no need to resubmit your comment.
    8478    </p>
    8579<?php
  • trunk/b2comments.post.php

    r546 r549  
    4444    die('Sorry, comments are closed for this item.');
    4545
    46 if ($require_name_email && ($email == '' || $email == '@' || $author == '' || $author == 'name')) { //original fix by Dodo, and then Drinyth
    47     echo 'Error: please fill the required fields (name, email).';
    48     exit;
     46if ($require_name_email && ($email == '' || $author == '')) { //original fix by Dodo, and then Drinyth
     47    die('Error: please fill the required fields (name, email).');
    4948}
    5049if ($comment == 'comment' || $comment == '') {
    51     echo "Error: please type a comment";
    52     exit;
     50    die('Error: please type a comment.');
    5351}
    5452
    55 $time_difference = get_settings('time_difference');
    56 $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
     53
     54$now = current_time('mysql');
    5755
    5856$comment = strip_tags($comment, $comment_allowed_tags);
     
    6967$url = addslashes($url);
    7068
    71 /* flood-protection */
     69/* Flood-protection */
    7270$lasttime = $wpdb->get_var("SELECT comment_date FROM $tablecomments WHERE comment_author_IP = '$user_ip' ORDER BY comment_date DESC LIMIT 1");
    7371$ok = true;
     
    7876        $ok = false;
    7977}
    80 /* end flood-protection */
     78/* End flood-protection */
    8179
    8280
    8381
    8482if ($ok) { // if there was no comment from this IP in the last 10 seconds
    85     $comment_moderation = get_settings("comment_moderation");
    86     $moderation_notify = get_settings("moderation_notify");
     83    $comment_moderation = get_settings('comment_moderation');
     84    $moderation_notify = get_settings('moderation_notify');
    8785   
    8886    // o42: this place could be the hook for further comment spam checking
     
    9896    $wpdb->query("INSERT INTO $tablecomments (comment_ID,comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_author_IP,comment_date,comment_content,comment_karma,comment_approved) VALUES ('0', '$comment_post_ID', '$author', '$email', '$url', '$user_ip', '$now', '$comment', '0', '$approved')");
    9997
    100     // o42: this should be changed as soon as other sql dbs are supported
    101     // as it's proprietary to mysql
    102     $comment_ID = $wpdb->get_var("SELECT last_insert_id()");
     98/*
     99    $comment_ID = $wpdb->get_var('SELECT last_insert_id()');
    103100
    104101    $fp = fopen("/tmp/wpdebug.txt", "w+");
     
    118115    fclose($fp);
    119116
     117*/
    120118    if ($email == '')
    121119        $email = ' '; // this to make sure a cookie is set for 'no email'
     
    128126    setcookie('comment_author_url_'.$cookiehash, $url, time()+30000000);
    129127
    130         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    131         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     128    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     129    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    132130    header('Cache-Control: no-cache, must-revalidate');
    133131    header('Pragma: no-cache');
    134     $location = (!empty($HTTP_POST_VARS['redirect_to'])) ? $HTTP_POST_VARS['redirect_to'] : $HTTP_SERVER_VARS["HTTP_REFERER"];
     132    $location = (empty($HTTP_POST_VARS['redirect_to'])) ? $HTTP_SERVER_VARS["HTTP_REFERER"] : $HTTP_POST_VARS['redirect_to'];
    135133    if ($is_IIS) {
    136134        header("Refresh: 0;url=$location");
  • trunk/b2commentspopup.php

    r546 r549  
    2020<h1 id="header"><a href="" title="<?php echo $blogname ?>"><?php echo $blogname ?></a></h1>
    2121
    22 <h2>Comments</h2>
     22<h2 id="comments">Comments</h2>
    2323
    2424<p><a href="<?php echo $siteurl; ?>/wp-commentsrss2.php?p=<?php echo $post->ID; ?>">RSS feed for comments on this post.</a></p>
     
    2828<?php } ?>
    2929
    30 <ol id="comments">
    3130<?php
    3231// this line is WordPress' motor, do not delete it.
     
    3433$commentstatus = $wpdb->get_row("SELECT comment_status, post_password FROM $tableposts WHERE ID = $id");
    3534if (!empty($commentstatus->post_password) && $HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $commentstatus->post_password) {  // and it doesn't match the cookie
    36     echo("<li>".get_the_password_form()."</li></ol>");
    37 }
    38 else {
    39     if ($comments) {
    40 // this line is WordPress' motor, do not delete it.
    41         foreach ($comments as $comment) {
    42 ?>
    43 <!-- comment -->
    44 <li id="comment-<?php comment_ID() ?>">
    45 <?php comment_text() ?>
    46 <p><cite><?php comment_type(); ?> by <?php comment_author_link() ?> &#8212; <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite></p>
    47 </li>
     35    echo(get_the_password_form());
     36} else { ?>
    4837
    49 <?php       } // end for each comment
    50     } else { // this is displayed if there are no comments so far
    51 ?>
    52     <li>No comments yet.</li>
     38<?php if ($comments) { ?>
     39<ol id="commentlist">
     40<?php foreach ($comments as $comment) { ?>
     41    <li id="comment-<?php comment_ID() ?>">
     42    <?php comment_text() ?>
     43    <p><cite><?php comment_type(); ?> by <?php comment_author_link() ?> &#8212; <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite></p>
     44    </li>
     45
     46<?php } // end for each comment ?>
     47</ol>
     48<?php } else { // this is displayed if there are no comments so far ?>
     49    <p>No comments yet.</p>
    5350<?php } ?>
    54 </ol>
    55 <?php
    56     if ('open' == $commentstatus->comment_status) { ?>
     51
     52<?php if ('open' == $commentstatus->comment_status) { ?>
    5753<h2>Leave a Comment</h2>
    5854<p>Line and paragraph breaks automatic, website trumps email, <acronym title="Hypertext Markup Language">HTML</acronym> allowed: <code><?php echo htmlentities(str_replace('<', ' <', $comment_allowed_tags)); ?></code></p>
  • trunk/wp-admin/b2menutop.txt

    r546 r549  
    111   wp-post.php Post
    221   edit.php    Edit
    3 3   wp-moderation.php   Moderation
    433   b2team.php  Team
    544   wp-options.php  Options
  • trunk/wp-admin/edit-comments.php

    r546 r549  
    3838?>
    3939<ul id="adminmenu2">
    40     <li><a href="edit.php">Posts</a></li>
    41     <li class="last"><a href="edit-comments.php" class="current">Comments</a></li>
     40    <li><a href="edit.php">Latest Posts</a></li>
     41    <li class="last"><a href="edit-comments.php" class="current">Latest Comments</a></li>
     42    <li><a href="wp-moderation.php">Comments Awaiting Moderation</a></li>
    4243</ul>
    4344
  • trunk/wp-admin/upgrade-072-to-073.php

    r516 r549  
    7777}
    7878
    79 $wpdb->query("INSERT INTO `$tableoptions` (`option_id`, `blog_id`, `option_name`, `option_can_override`, `option_type`, `option_value`, `option_width`, `option_height`, `option_description`, `option_admin_level`) VALUES ('', '0', 'permalink_structure', 'Y', '3', '', '20', '8', 'How the permalinks for your site are constructed.', '8');");
    80 ?>
    81   <strong>Done.</strong></p>
     79if (!$wpdb->get_var("SELECT option_name FROM $tableoptions WHERE option_name = 'permalink_structure'")) { // If it's not already there
     80    $wpdb->query("INSERT INTO `$tableoptions`
     81        (`option_id`, `blog_id`, `option_name`, `option_can_override`, `option_type`, `option_value`, `option_width`, `option_height`, `option_description`, `option_admin_level`)
     82        VALUES
     83        ('', '0', 'permalink_structure', 'Y', '3', '', '20', '8', 'How the permalinks for your site are constructed. See <a href=\"wp-options-permalink.php\">permalink options page</a> for necessary mod_rewrite rules and more information.', '8');");
     84    }
     85?>
     86  Done with the name game. Now a little option action. </p>
    8287  <p>Now on to <a href="upgrade-072-to-073.php?step=2">step 2</a>.</p>
    8388<?php
     
    101106        echo ' .';
    102107        flush();
    103         // add link to date format help page
    104         $wpdb->query("UPDATE $tableoptions SET option_description = 'see <a href=\"help/en/dateformats.help.html\">help</a> for format characters' WHERE option_id = 52");
    105         $wpdb->query("UPDATE $tableoptions SET option_description = 'see <a href=\"help/en/dateformats.help.html\">help</a> for format characters' WHERE option_id = 53");
    106         echo ' .';
    107         flush();
    108 ?>
    109     <strong>Done.</strong></p>
    110 <p>See, that didn&#8217;t hurt a bit. All done!</p>
     108        // add link to php date format. this could be to a wordpress.org page in the future
     109        $wpdb->query("UPDATE $tableoptions SET option_description = 'see <a href=\"http://php.net/date\">help</a> for format characters' WHERE option_id = 52");
     110        $wpdb->query("UPDATE $tableoptions SET option_description = 'see <a href=\"http://php.net/date\">help</a> for format characters' WHERE option_id = 53");
     111        echo ' .';
     112        flush();
     113?>
     114    <strong>Done with the options updates. Now for a bit of comment action</strong></p>
     115<?php
     116$result = '';
     117$error_count = 0;
     118$continue = true;
     119
     120// Insert new column "comment_approved" to $tablecomments
     121if ($continue) {
     122    $ddl = "ALTER TABLE $tablecomments ADD COLUMN comment_approved ENUM('0', '1') DEFAULT '1' NOT NULL";
     123    if (maybe_add_column($tablecomments, $tablecol, $ddl)) {
     124        $wpdb->query("ALTER TABLE $tablecomments ADD INDEX (comment_approved)");
     125    }
     126}
     127
     128// Insert new option "comment_moderation" to settings   
     129if (!$wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'comment_moderation'")) {
     130    $wpdb->query("INSERT INTO $tableoptions
     131        (option_id, blog_id, option_name, option_can_override, option_type, option_value, option_width, option_height, option_description, option_admin_level)
     132        VALUES
     133        ('0', '0', 'comment_moderation', 'Y', '5',' none', 20, 8, 'If enabled, comments will only be shown after they have been approved.', 8)");
     134}
     135
     136// attach option to group "General blog settings"
     137if ($continue) {
     138    $oid = $wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'comment_moderation'");     
     139    $gid = $wpdb->get_var("SELECT group_id FROM $tableoptiongroups WHERE group_name = 'General blog settings'");
     140   
     141    $seq = $wpdb->get_var("SELECT MAX(seq) FROM $tableoptiongroup_options WHERE group_id = '$gid'");
     142   
     143    ++$seq;
     144
     145    $wpdb->query("INSERT INTO $tableoptiongroup_options
     146        (group_id, option_id, seq)
     147        VALUES
     148        ('$gid', '$oid', '$seq')");
     149}
     150
     151// Insert option values for new option "comment_moderation"
     152if ($continue) {
     153    $ddl = array();     
     154    $ddl[] = "INSERT INTO $tableoptionvalues
     155        (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
     156        VALUES
     157        ('$oid', 'none', 'None', NULL, NULL, 1)";
     158    $ddl[] = "INSERT INTO $tableoptionvalues
     159        (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
     160        VALUES
     161        ('$oid', 'manual', 'Manual', NULL, NULL, 2)";
     162    $ddl[] = "INSERT INTO $tableoptionvalues
     163        (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
     164        VALUES
     165        ('$oid','auto', 'Automatic', NULL, NULL, 3)";
     166       
     167    foreach ($ddl as $query) {
     168        $wpdb->query($query);
     169    }
     170   
     171}
     172
     173// Insert new option "moderation_notify" to settings   
     174if (!$wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'moderation_notify'")) {
     175    $wpdb->query("INSERT INTO $tableoptions
     176        (option_id, blog_id, option_name, option_can_override, option_type, option_value, option_width, option_height, option_description, option_admin_level)
     177        VALUES
     178        ('0', '0', 'moderation_notify' , 'Y', '2', '1', 20, 8, 'Set this to true if you want to be notified about new comments that wait for approval', 8)");
     179}
     180
     181// attach option to group "General blog settings"
     182if ($continue) {
     183    $oid = $wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'moderation_notify'");       
     184    $gid = $wpdb->get_var("SELECT group_id FROM $tableoptiongroups WHERE group_name = 'General blog settings'");
     185   
     186    $seq = $wpdb->get_var("SELECT MAX(seq) FROM $tableoptiongroup_options WHERE group_id = '$gid'");
     187
     188    ++$seq;
     189    $wpdb->query("INSERT INTO $tableoptiongroup_options
     190        (group_id, option_id, seq)
     191        VALUES
     192        ('$gid', '$oid', '$seq')");
     193}
     194?>
     195<p>Comment spammers should now watch out for you.</p>
     196<p>See, that didn&#8217;t hurt a bit (again). All done!</p>
    111197<?php
    112198    break;
  • trunk/wp-admin/wp-moderation.php

    r546 r549  
    4343
    4444    $standalone = 1;
    45     require_once("b2header.php");
     45    require_once('b2header.php');
    4646
    4747    if ($user_level < 3) {
    48         die('<p>You have no right to moderate comments.<br />Ask for a promotion to your <a href="mailto:$admin_email">blog admin</a>. :)</p>');
     48        die('<p>Your level is not high enough to moderate comments. Ask for a promotion from your <a href="mailto:$admin_email">blog admin</a>. :)</p>');
    4949    }
    5050   
    5151    // check if comment moderation is turned on in the settings
    5252    // if not, just give a short note and stop
    53     if (get_settings("comment_moderation") == "none") {
    54         echo "<div class=\"wrap\">\n";
    55         echo "Comment moderation has been turned off.<br /><br />\n";
    56         echo "</div>\n";
    57         include("b2footer.php");
     53    if ('none' == get_settings("comment_moderation")) {
     54        echo '<div class="wrap">
     55        <p>Comment moderation has been turned off.</p>
     56        </div>';
     57        require('b2footer.php');
    5858        exit;
    5959    }   
     
    6565    foreach($comment as $key => $value) {
    6666        switch($value) {
    67         case "later":
    68         // do nothing with that comment
    69         // wp_set_comment_status($key, "hold");
    70         ++$item_ignored;
    71         break;
    72        
    73         case "delete":
    74         wp_set_comment_status($key, "delete");
    75         ++$item_deleted;
    76         break;
    77        
    78         case "approve":
    79         wp_set_comment_status($key, "approve");
    80         if (get_settings("comments_notify") == true) {
    81             wp_notify_postauthor($key);
    82         }
    83         ++$item_approved;
    84         break;
     67            case 'later':
     68                // do nothing with that comment
     69                // wp_set_comment_status($key, "hold");
     70                ++$item_ignored;
     71                break;
     72           
     73            case 'delete':
     74                wp_set_comment_status($key, 'delete');
     75                ++$item_deleted;
     76                break;
     77           
     78            case 'approve':
     79                wp_set_comment_status($key, 'approve');
     80                if (get_settings('comments_notify') == true) {
     81                    wp_notify_postauthor($key);
     82                }
     83                ++$item_approved;
     84                break;
    8585        }
    8686    }
     
    9797
    9898    if ($user_level <= 3) {
    99         die('<p>You have no right to moderate comments.<br>Ask for a promotion to your <a href="mailto:$admin_email">blog admin</a>. :)</p>');
     99        die('<p>Your level is not high enough to moderate comments. Ask for a promotion from your <a href="mailto:$admin_email">blog admin</a>. :)</p>');
    100100    }
    101101
    102102    // check if comment moderation is turned on in the settings
    103103    // if not, just give a short note and stop
    104     if (get_settings("comment_moderation") == "none") {
    105         echo "<div class=\"wrap\">\n";
    106         echo "Comment moderation has been turned off.<br /><br />\n";
    107         echo "</div>\n";
     104    if ('none' == get_settings('comment_moderation')) {
     105        echo '<div class="wrap">
     106        <p>Comment moderation has been turned off.</p>
     107        </div>';
    108108        include("b2footer.php");
    109109        exit;
     
    145145    <?php
    146146   
    147 $comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_approved='0'");
     147$comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_approved = 0");
    148148if ($comments) {
    149149    // list all comments that are waiting for approval
Note: See TracChangeset for help on using the changeset viewer.