function flt_recent_comments($query)
 {
     // Due to missing get_comments hook prior to WP 3.1, this filter operates on every front-end query.
     // If query doesn't pertain to comments, skip out with as little overhead as possible.
     if (strpos($query, 'comment') && strpos($query, "ELECT") && !strpos($query, 'posts as parent') && !strpos($query, "COUNT") && strpos($query, "comment_approved")) {
         if (!is_attachment() && !is_content_administrator_rs()) {
             global $wpdb;
             if (strpos($query, " {$wpdb->posts} ")) {
                 return $query;
             }
             if (awp_is_plugin_active('wp-wall')) {
                 $options = WPWall_GetOptions();
                 if (strpos($query, 'comment_post_ID=' . $options['pageId'])) {
                     return $query;
                 }
             }
             if (strpos($query, $wpdb->comments)) {
                 $query = str_replace(" post_status = 'publish'", " {$wpdb->posts}.post_status = 'publish'", $query);
                 // theoretically, a slight performance enhancement if we can simplify the query to skip filtering of attachment comments
                 if (defined('SCOPER_NO_ATTACHMENT_COMMENTS') || false !== strpos($query, 'comment_post_ID =')) {
                     if (!strpos($query, "JOIN {$wpdb->posts}")) {
                         $query = preg_replace("/FROM\\s*{$wpdb->comments}\\s*WHERE /", "FROM {$wpdb->comments} INNER JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID WHERE ", $query);
                     }
                     $query = apply_filters('objects_request_rs', $query, 'post', '', array('skip_teaser' => true));
                 } else {
                     $query = str_replace("user_id ", "{$wpdb->comments}.user_id ", $query);
                     $query = str_replace("SELECT {$wpdb->comments}.* FROM {$wpdb->comments}", "SELECT DISTINCT {$wpdb->comments}.* FROM {$wpdb->comments}", $query);
                     if (!strpos($query, ' DISTINCT ')) {
                         $query = str_replace("SELECT ", "SELECT DISTINCT ", $query);
                     }
                     $post_types = array_diff(get_post_types(array('public' => true)), array('attachment'));
                     $post_type_in = "'" . implode("','", $post_types) . "'";
                     $join = "LEFT JOIN {$wpdb->posts} as parent ON parent.ID = {$wpdb->posts}.post_parent AND parent.post_type IN ({$post_type_in}) AND {$wpdb->posts}.post_type = 'attachment'";
                     $use_post_types = scoper_get_option('use_post_types');
                     $where = array();
                     foreach ($post_types as $type) {
                         if (!empty($use_post_types[$type])) {
                             $where_post = apply_filters('objects_where_rs', '', 'post', $type, array('skip_teaser' => true));
                         } else {
                             $where_post = "AND 1=1";
                         }
                         $where[] = "{$wpdb->posts}.post_type = '{$type}' {$where_post}";
                         $where[] = "{$wpdb->posts}.post_type = 'attachment' AND parent.post_type = '{$type}' " . str_replace("{$wpdb->posts}.", "parent.", $where_post);
                     }
                     $where = agp_implode(' ) OR ( ', $where, ' ( ', ' ) ');
                     if (!strpos($query, "JOIN {$wpdb->posts}")) {
                         $query = str_replace("WHERE ", "INNER JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID {$join} WHERE ( {$where} ) AND ", $query);
                     } else {
                         $query = str_replace("WHERE ", "{$join} WHERE {$where} AND ", $query);
                     }
                 }
             }
         }
     }
     return $query;
 }
    function display($args)
    {
        global $wpdb, $comments, $comment;
        extract($args, EXTR_SKIP);
        $options = get_option('wpwall_widget_recent_comments');
        $title = empty($options['title']) ? __('Recent Comments') : apply_filters('widget_title', $options['title']);
        if (!($number = (int) $options['number'])) {
            $number = 5;
        } else {
            if ($number < 1) {
                $number = 1;
            } else {
                if ($number > 15) {
                    $number = 15;
                }
            }
        }
        // get our page id
        $options = WPWall_GetOptions();
        $pageId = $options['pageId'];
        if (!($comments = wp_cache_get('recent_comments', 'widget'))) {
            $comments = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '1' AND comment_post_ID != '{$pageId}' ORDER BY comment_date_gmt DESC LIMIT {$number}");
            wp_cache_add('recent_comments', $comments, 'widget');
        }
        ?>

		<?php 
        echo $before_widget;
        ?>
			<?php 
        echo $before_title . $title . $after_title;
        ?>
			<ul id="recentcomments"><?php 
        if ($comments) {
            foreach ((array) $comments as $comment) {
                echo '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="' . clean_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
            }
        }
        ?>
</ul>
		<?php 
        echo $after_widget;
    }
예제 #3
0
function WPWall_Gravatar($comment)
{
    $options = WPWall_GetOptions();
    if (!$options['gravatar']) {
        return '';
    }
    $return = '<span class="wall-gravatar">';
    $size = 25;
    $email = strtolower(trim($comment->comment_author_email));
    $rating = "G";
    if (function_exists('get_avatar')) {
        $return .= get_avatar($email, $size);
    } else {
        $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=\n         " . md5($emaill) . "&size=" . $size . "&rating=" . $rating;
        $return .= "<img src='{$grav_url}'/>";
    }
    $return .= '</span>';
    return $return;
}
예제 #4
0
<?php

require_once "../../../../wp-config.php";
if ($_POST['submit_wall_post']) {
    $options = WPWall_GetOptions();
    $comment_post_ID = $options['pageId'];
    $actual_post = get_post($comment_post_ID);
    // sanity check to see if our page exists
    if (!$comment_post_ID || !$actual_post || $comment_post_ID != $actual_post->ID) {
        wp_die('Sorry, there was a problem posting your comment. Please try again.');
    }
    if ($options['disable_new']) {
        wp_die('Sorry, the comments are disabled at the moment.');
    }
    // extract data we need
    $comment_author = trim(strip_tags($_POST['wpwall_author']));
    $comment_content = trim($_POST['wpwall_comment']);
    $comment_author_email = trim($_POST['wpwall_email']);
    // If the user is logged in get his name
    $user = wp_get_current_user();
    if ($user->ID) {
        $comment_author = $wpdb->escape($user->display_name);
        $comment_author_email = $wpdb->escape($user->user_email);
    } else {
        if (get_user_by('login', $comment_author)) {
            wp_die('Sorry, you have to pick another name.');
        } else {
            if ($options['only_registered']) {
                wp_die('Sorry, you must be logged in to post a comment.');
            }
        }