<?php if (bymt_c('open_sidebar')) { ?> <li id="f_o"><a href="javascript:;" title="打开侧边栏"><i class="icon-pause"></i></a></li><?php } ?> </ul> <?php } ?> <span class="pauthor"><i class="icon-user-add"></i><?php the_author_posts_link(); ?> </span> <span class="ptime"><i class="icon-calendar"></i><?php bymt_time_diff($time_type = 'post'); ?> </span> <span class="pcate"><i class="icon-category"></i><?php the_category(', '); ?> </span> <?php if (bymt_c('postinfoviews')) { ?> <span class="pview"><i class="icon-pass"></i><?php if (function_exists('the_views')) { the_views(); } ?> </span><?php
function bymt_ajax_comment() { if (isset($_POST['action']) && $_POST['action'] == 'bymt_ajax_comment' && 'POST' == $_SERVER['REQUEST_METHOD']) { global $wpdb; nocache_headers(); $comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0; $post = get_post($comment_post_ID); if (empty($post->comment_status)) { do_action('comment_id_not_found', $comment_post_ID); err(__('无效的评论状态')); // 將 exit 改為錯誤提示 } // get_post_status() will get the parent status for attachments. $status = get_post_status($post); $status_obj = get_post_status_object($status); if (!comments_open($comment_post_ID)) { do_action('comment_closed', $comment_post_ID); err(__('评论已关闭!')); // 將 wp_die 改為錯誤提示 } elseif ('trash' == $status) { do_action('comment_on_trash', $comment_post_ID); err(__('无效的评论状态')); // 將 exit 改為錯誤提示 } elseif (!$status_obj->public && !$status_obj->private) { do_action('comment_on_draft', $comment_post_ID); err(__('无效的评论状态')); // 將 exit 改為錯誤提示 } elseif (post_password_required($comment_post_ID)) { do_action('comment_on_password_protected', $comment_post_ID); err(__('受密码保护请先输入密码')); // 將 exit 改為錯誤提示 } else { do_action('pre_comment_on_post', $comment_post_ID); } $comment_author = isset($_POST['author']) ? trim(strip_tags($_POST['author'])) : null; $comment_author_email = isset($_POST['email']) ? trim($_POST['email']) : null; $comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : null; $comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : null; $edit_id = isset($_POST['edit_id']) ? $_POST['edit_id'] : null; // 提取 edit_id // If the user is logged in $user = wp_get_current_user(); if ($user->exists()) { if (empty($user->display_name)) { $user->display_name = $user->user_login; } $comment_author = esc_sql($user->display_name); $comment_author_email = esc_sql($user->user_email); $comment_author_url = esc_sql($user->user_url); if (current_user_can('unfiltered_html')) { if (wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment']) { kses_remove_filters(); // start with a clean slate kses_init_filters(); // set up the filters } } } else { if (get_option('comment_registration') || 'private' == $status) { err(__('您必须先登陆才可以发表评论')); } // 將 wp_die 改為錯誤提示 } $comment_type = ''; if (get_option('require_name_email') && !$user->exists()) { if (6 > strlen($comment_author_email) || '' == $comment_author) { err(__('请填写昵称和邮箱')); } elseif (!is_email($comment_author_email)) { err(__('请填写一个有效的邮箱')); } // 將 wp_die 改為錯誤提示 } if ('' == $comment_content) { err(__('请输入评论内容')); } // 將 wp_die 改為錯誤提示 // 增加: 檢查重覆評論功能 $dupe = "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = '{$comment_post_ID}' AND ( comment_author = '{$comment_author}' "; if ($comment_author_email) { $dupe .= "OR comment_author_email = '{$comment_author_email}' "; } $dupe .= ") AND comment_content = '{$comment_content}' LIMIT 1"; if ($wpdb->get_var($dupe)) { err(__('您已经发布过一条相同的评论!')); } // 增加: 檢查評論太快功能 if ($lasttime = $wpdb->get_var($wpdb->prepare("SELECT comment_date_gmt FROM {$wpdb->comments} WHERE comment_author = %s ORDER BY comment_date DESC LIMIT 1", $comment_author))) { $time_lastcomment = mysql2date('U', $lasttime, false); $time_newcomment = mysql2date('U', current_time('mysql', 1), false); $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment); if ($flood_die) { err(__('请过一会再发表评论')); } } $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0; $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID'); // 增加: 檢查評論是否正被編輯, 更新或新建評論 if ($edit_id) { // 判断当前用户是否具有编辑该评论权限 if (current_user_can("edit_comment", $edit_id)) { // 判断当前用户的邮箱是否与评论邮箱相同 if ($current_user->user_email == $comment_author_email) { $comment_id = $commentdata['comment_ID'] = $edit_id; wp_update_comment($commentdata); } else { err(__('您不能修改为他人评论!')); } } else { err(__('您没有权限编辑该评论!')); } } else { $comment_id = wp_new_comment($commentdata); } $comment = get_comment($comment_id); do_action('set_comment_cookies', $comment, $user); $comment_depth = 1; //为评论的 class 属性准备的 $tmp_c = $comment; while ($tmp_c->comment_parent != 0) { $comment_depth++; $tmp_c = get_comment($tmp_c->comment_parent); } //此处非常必要,无此处下面的评论无法输出 by mufeng $GLOBALS['comment'] = $comment; global $depth; //以下是評論式樣, 不含 "回覆". 要用你模板的式樣 copy 覆蓋. ?> <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?> " <?php if ($depth > get_option('thread_comments_depth') && !wp_is_mobile()) { echo ' style="margin-left:0px;"'; } ?> > <div id="div-comment-<?php comment_ID(); ?> " class="comment-body"> <?php $add_below = 'div-comment'; ?> <div class="comment-author vcard gravatar"><?php echo bymt_avatar($comment->comment_author_email); ?> </div> <div class="floor">新楼</div> <div class="commenttext"> <span class="commentid"><?php comment_author_link(); ?> </span> <?php get_author_class($comment->comment_author_email, $comment->comment_author_url); ?> <span class="datetime"><?php bymt_time_diff($time_type = 'comment'); ?> </span> <span class="edit_comment"><?php edit_comment_link('[编辑]'); ?> </span> <div class="comment_text"> <?php if ($comment->comment_approved == '0') { ?> <span style="color:#f00;">您的评论正在等待审核中...</span> <?php comment_text(); ?> <?php } else { ?> <?php comment_text(); ?> <?php } ?> </div> </div> </div> <?php die; //以上是評論式樣, 不含 "回覆". 要用你模板的式樣 copy 覆蓋. } else { return; } }