/**
  * Returns a list of all sitewide comments.
  *
  * If desired, this function can be passed a boolean indicating whether or
  * not to return only approved comments, which is the action performed when
  * `$approved_only` is true.  By default, this value is true.
  *
  * @param  bool  $approved_only only return approved comments
  * @return array                all sitewide comments
  *
  * @since 0.1
  */
 public function get_sitewide_comments($approved_only = true)
 {
     // Set a proper cache key based upon which sort of comments are allowed
     $cache_key = 'comments_';
     $cache_key .= $approved_only ? 'approved' : 'all';
     // Return the cached comments if possible
     $cached = $this->get_site_cache($cache_key);
     if ($cached !== null) {
         return $cached;
     }
     // Filter out any unapproved comments if we're only allowing approved ones
     $approved_filter = "";
     if ($approved_only) {
         $approved_filter = "AND c.comment_approved = '1'";
     }
     global $nxtdb;
     $comments = $nxtdb->get_results("\n\t\t\tSELECT c.*, p.post_title\n\t\t\tFROM {$this->sw_tables->comments} AS c, {$this->sw_tables->posts} AS p\n\t\t\tWHERE p.ID = c.comment_post_ID AND c.cb_sw_blog_id = p.cb_sw_blog_id {$approved_filter}\n\t\t\tORDER BY c.comment_date DESC");
     // Even if all comments are allowed, don't display spam comments
     if (!$approved_only) {
         global $blog_id;
         $current_blog_id = $blog_id;
         $no_spam = array();
         foreach ($comments as $comment) {
             ClassBlogs_NXTClass::switch_to_blog($comment->cb_sw_blog_id);
             if (nxt_get_comment_status($comment->comment_ID) != 'spam') {
                 $no_spam[] = $comment;
             }
         }
         ClassBlogs_Utils::restore_blog($current_blog_id);
         $comments = $no_spam;
     }
     $this->set_site_cache($cache_key, $comments);
     return $comments;
 }
Exemple #2
0
     if (nxt_delete_post($id)) {
         die('1');
     } else {
         die('0');
     }
     break;
 case 'dim-comment':
     // On success, die with time() instead of 1
     if (!($comment = get_comment($id))) {
         $x = new nxt_Ajax_Response(array('what' => 'comment', 'id' => new nxt_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))));
         $x->send();
     }
     if (!current_user_can('edit_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
         die('-1');
     }
     $current = nxt_get_comment_status($comment->comment_ID);
     if ($_POST['new'] == $current) {
         die((string) time());
     }
     check_ajax_referer("approve-comment_{$id}");
     if (in_array($current, array('unapproved', 'spam'))) {
         $result = nxt_set_comment_status($comment->comment_ID, 'approve', true);
     } else {
         $result = nxt_set_comment_status($comment->comment_ID, 'hold', true);
     }
     if (is_nxt_error($result)) {
         $x = new nxt_Ajax_Response(array('what' => 'comment', 'id' => $result));
         $x->send();
     }
     // Decide if we need to send back '1' or a more complicated response including page links and comment counts
     _nxt_ajax_delete_comment_response($comment->comment_ID);
    function column_comment($comment)
    {
        global $post, $comment_status;
        $user_can = $this->user_can;
        $comment_url = esc_url(get_comment_link($comment->comment_ID));
        $the_comment_status = nxt_get_comment_status($comment->comment_ID);
        $ptime = date('G', strtotime($comment->comment_date));
        if (abs(time() - $ptime) < 86400) {
            $ptime = sprintf(__('%s ago'), human_time_diff($ptime));
        } else {
            $ptime = mysql2date(__('Y/m/d \\a\\t g:i A'), $comment->comment_date);
        }
        if ($user_can) {
            $del_nonce = esc_html('_nxtnonce=' . nxt_create_nonce("delete-comment_{$comment->comment_ID}"));
            $approve_nonce = esc_html('_nxtnonce=' . nxt_create_nonce("approve-comment_{$comment->comment_ID}"));
            $url = "comment.php?c={$comment->comment_ID}";
            $approve_url = esc_url($url . "&action=approvecomment&{$approve_nonce}");
            $unapprove_url = esc_url($url . "&action=unapprovecomment&{$approve_nonce}");
            $spam_url = esc_url($url . "&action=spamcomment&{$del_nonce}");
            $unspam_url = esc_url($url . "&action=unspamcomment&{$del_nonce}");
            $trash_url = esc_url($url . "&action=trashcomment&{$del_nonce}");
            $untrash_url = esc_url($url . "&action=untrashcomment&{$del_nonce}");
            $delete_url = esc_url($url . "&action=deletecomment&{$del_nonce}");
        }
        echo '<div class="submitted-on">';
        /* translators: 2: comment date, 3: comment time */
        printf(__('Submitted on <a href="%1$s">%2$s at %3$s</a>'), $comment_url, get_comment_date(__('Y/m/d')), get_comment_date(get_option('time_format')));
        if ($comment->comment_parent) {
            $parent = get_comment($comment->comment_parent);
            $parent_link = esc_url(get_comment_link($comment->comment_parent));
            $name = get_comment_author($parent->comment_ID);
            printf(' | ' . __('In reply to <a href="%1$s">%2$s</a>.'), $parent_link, $name);
        }
        echo '</div>';
        comment_text();
        if ($user_can) {
            ?>
		<div id="inline-<?php 
            echo $comment->comment_ID;
            ?>
" class="hidden">
		<textarea class="comment" rows="1" cols="1"><?php 
            echo esc_textarea(apply_filters('comment_edit_pre', $comment->comment_content));
            ?>
</textarea>
		<div class="author-email"><?php 
            echo esc_attr($comment->comment_author_email);
            ?>
</div>
		<div class="author"><?php 
            echo esc_attr($comment->comment_author);
            ?>
</div>
		<div class="author-url"><?php 
            echo esc_attr($comment->comment_author_url);
            ?>
</div>
		<div class="comment_status"><?php 
            echo $comment->comment_approved;
            ?>
</div>
		</div>
		<?php 
        }
        if ($user_can) {
            // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
            $actions = array('approve' => '', 'unapprove' => '', 'reply' => '', 'quickedit' => '', 'edit' => '', 'spam' => '', 'unspam' => '', 'trash' => '', 'untrash' => '', 'delete' => '');
            if ($comment_status && 'all' != $comment_status) {
                // not looking at all comments
                if ('approved' == $the_comment_status) {
                    $actions['unapprove'] = "<a href='{$unapprove_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
                } else {
                    if ('unapproved' == $the_comment_status) {
                        $actions['approve'] = "<a href='{$approve_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
                    }
                }
            } else {
                $actions['approve'] = "<a href='{$approve_url}' class='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
                $actions['unapprove'] = "<a href='{$unapprove_url}' class='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
            }
            if ('spam' != $the_comment_status && 'trash' != $the_comment_status) {
                $actions['spam'] = "<a href='{$spam_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::spam=1 vim-s vim-destructive' title='" . esc_attr__('Mark this comment as spam') . "'>" . _x('Spam', 'verb') . '</a>';
            } elseif ('spam' == $the_comment_status) {
                $actions['unspam'] = "<a href='{$unspam_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1 vim-z vim-destructive'>" . _x('Not Spam', 'comment') . '</a>';
            } elseif ('trash' == $the_comment_status) {
                $actions['untrash'] = "<a href='{$untrash_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1 vim-z vim-destructive'>" . __('Restore') . '</a>';
            }
            if ('spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS) {
                $actions['delete'] = "<a href='{$delete_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::delete=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
            } else {
                $actions['trash'] = "<a href='{$trash_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1 delete vim-d vim-destructive' title='" . esc_attr__('Move this comment to the trash') . "'>" . _x('Trash', 'verb') . '</a>';
            }
            if ('spam' != $the_comment_status && 'trash' != $the_comment_status) {
                $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>" . __('Edit') . '</a>';
                $actions['quickedit'] = '<a onclick="commentReply.open( \'' . $comment->comment_ID . '\',\'' . $post->ID . '\',\'edit\' );return false;" class="vim-q" title="' . esc_attr__('Quick Edit') . '" href="#">' . __('Quick&nbsp;Edit') . '</a>';
                $actions['reply'] = '<a onclick="commentReply.open( \'' . $comment->comment_ID . '\',\'' . $post->ID . '\' );return false;" class="vim-r" title="' . esc_attr__('Reply to this comment') . '" href="#">' . __('Reply') . '</a>';
            }
            $actions = apply_filters('comment_row_actions', array_filter($actions), $comment);
            $i = 0;
            echo '<div class="row-actions">';
            foreach ($actions as $action => $link) {
                ++$i;
                ('approve' == $action || 'unapprove' == $action) && 2 === $i || 1 === $i ? $sep = '' : ($sep = ' | ');
                // Reply and quickedit need a hide-if-no-js span when not added with ajax
                if (('reply' == $action || 'quickedit' == $action) && !defined('DOING_AJAX')) {
                    $action .= ' hide-if-no-js';
                } elseif ($action == 'untrash' && $the_comment_status == 'trash' || $action == 'unspam' && $the_comment_status == 'spam') {
                    if ('1' == get_comment_meta($comment->comment_ID, '_nxt_trash_meta_status', true)) {
                        $action .= ' approve';
                    } else {
                        $action .= ' unapprove';
                    }
                }
                echo "<span class='{$action}'>{$sep}{$link}</span>";
            }
            echo '</div>';
        }
    }
Exemple #4
0
function _nxt_dashboard_recent_comments_row(&$comment, $show_date = true)
{
    $GLOBALS['comment'] =& $comment;
    $comment_post_url = get_edit_post_link($comment->comment_post_ID);
    $comment_post_title = strip_tags(get_the_title($comment->comment_post_ID));
    $comment_post_link = "<a href='{$comment_post_url}'>{$comment_post_title}</a>";
    $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
    $actions_string = '';
    if (current_user_can('edit_comment', $comment->comment_ID)) {
        // preorder it: Approve | Reply | Edit | Spam | Trash
        $actions = array('approve' => '', 'unapprove' => '', 'reply' => '', 'edit' => '', 'spam' => '', 'trash' => '', 'delete' => '');
        $del_nonce = esc_html('_nxtnonce=' . nxt_create_nonce("delete-comment_{$comment->comment_ID}"));
        $approve_nonce = esc_html('_nxtnonce=' . nxt_create_nonce("approve-comment_{$comment->comment_ID}"));
        $approve_url = esc_url("comment.php?action=approvecomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$approve_nonce}");
        $unapprove_url = esc_url("comment.php?action=unapprovecomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$approve_nonce}");
        $spam_url = esc_url("comment.php?action=spamcomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$del_nonce}");
        $trash_url = esc_url("comment.php?action=trashcomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$del_nonce}");
        $delete_url = esc_url("comment.php?action=deletecomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$del_nonce}");
        $actions['approve'] = "<a href='{$approve_url}' class='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
        $actions['unapprove'] = "<a href='{$unapprove_url}' class='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
        $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>" . __('Edit') . '</a>';
        $actions['reply'] = '<a onclick="commentReply.open(\'' . $comment->comment_ID . '\',\'' . $comment->comment_post_ID . '\');return false;" class="vim-r hide-if-no-js" title="' . esc_attr__('Reply to this comment') . '" href="#">' . __('Reply') . '</a>';
        $actions['spam'] = "<a href='{$spam_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::spam=1 vim-s vim-destructive' title='" . esc_attr__('Mark this comment as spam') . "'>" . _x('Spam', 'verb') . '</a>';
        if (!EMPTY_TRASH_DAYS) {
            $actions['delete'] = "<a href='{$delete_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
        } else {
            $actions['trash'] = "<a href='{$trash_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1 delete vim-d vim-destructive' title='" . esc_attr__('Move this comment to the trash') . "'>" . _x('Trash', 'verb') . '</a>';
        }
        $actions = apply_filters('comment_row_actions', array_filter($actions), $comment);
        $i = 0;
        foreach ($actions as $action => $link) {
            ++$i;
            ('approve' == $action || 'unapprove' == $action) && 2 === $i || 1 === $i ? $sep = '' : ($sep = ' | ');
            // Reply and quickedit need a hide-if-no-js span
            if ('reply' == $action || 'quickedit' == $action) {
                $action .= ' hide-if-no-js';
            }
            $actions_string .= "<span class='{$action}'>{$sep}{$link}</span>";
        }
    }
    ?>

		<div id="comment-<?php 
    echo $comment->comment_ID;
    ?>
" <?php 
    comment_class(array('comment-item', nxt_get_comment_status($comment->comment_ID)));
    ?>
>
			<?php 
    if (!$comment->comment_type || 'comment' == $comment->comment_type) {
        ?>

			<?php 
        echo get_avatar($comment, 50);
        ?>

			<div class="dashboard-comment-wrap">
			<h4 class="comment-meta">
				<?php 
        printf(__('From %1$s on %2$s%3$s'), '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link . ' ' . $comment_link, ' <span class="approve">' . __('[Pending]') . '</span>');
        ?>
			</h4>

			<?php 
    } else {
        switch ($comment->comment_type) {
            case 'pingback':
                $type = __('Pingback');
                break;
            case 'trackback':
                $type = __('Trackback');
                break;
            default:
                $type = ucwords($comment->comment_type);
        }
        $type = esc_html($type);
        ?>
			<div class="dashboard-comment-wrap">
			<?php 
        /* translators: %1$s is type of comment, %2$s is link to the post */
        ?>
			<h4 class="comment-meta"><?php 
        printf(_x('%1$s on %2$s', 'dashboard'), "<strong>{$type}</strong>", $comment_post_link . " " . $comment_link);
        ?>
</h4>
			<p class="comment-author"><?php 
        comment_author_link();
        ?>
</p>

			<?php 
    }
    // comment_type
    ?>
			<blockquote><p><?php 
    comment_excerpt();
    ?>
</p></blockquote>
			<p class="row-actions"><?php 
    echo $actions_string;
    ?>
</p>
			</div>
		</div>
<?php 
}
 /**
  * Monitors updates to all comments tables and updates the sitewide comments
  * table based on the status of the comment.
  *
  * This does not actually perform any modifications to the sitewide comments
  * table, as such actions are delegated to various other functions that
  * handle addition, deletion or modification.
  *
  * @param int    $comment_id the ID of the comment being modified
  * @param string $status     the optional new comment status
  *
  * @access private
  * @since 0.2
  */
 public function _track_single_comment($comment_id, $status = "")
 {
     global $blog_id;
     $this->clear_site_cache();
     // Since this function may be called be either the comment_posted hook
     // or the nxt_set_comment_status hook, we might receive the actual status
     // of the post in the $status arg, or we might need to look it up using
     // the post's ID, if no status information was passed
     if (!$status) {
         $status = nxt_get_comment_status($comment_id);
     }
     // If the comment is an initial comment, don't do anything
     $comment = get_comment($comment_id);
     $for_post = get_post($comment->comment_post_ID);
     if ($this->_content_is_initial_for_user($comment->comment_date_gmt, $for_post->post_author)) {
         return;
     }
     // If the comment is being made public, update its sitewide record,
     // and remove it if it is no longer publicly visible
     switch ($status) {
         case 'approve':
         case 'approved':
             $this->_update_sw_comment($blog_id, $comment_id);
             break;
         default:
             $this->_delete_sw_comment($blog_id, $comment_id);
     }
 }
Exemple #6
0
/**
 * Adds a new comment to the database.
 *
 * Filters new comment to ensure that the fields are sanitized and valid before
 * inserting comment into database. Calls 'comment_post' action with comment ID
 * and whether comment is approved by NXTClass. Also has 'preprocess_comment'
 * filter for processing the comment data before the function handles it.
 *
 * We use REMOTE_ADDR here directly. If you are behind a proxy, you should ensure
 * that it is properly set, such as in nxt-config.php, for your environment.
 * See {@link http://core.trac.nxtclass.org/ticket/9235}
 *
 * @since 1.5.0
 * @uses apply_filters() Calls 'preprocess_comment' hook on $commentdata parameter array before processing
 * @uses do_action() Calls 'comment_post' hook on $comment_ID returned from adding the comment and if the comment was approved.
 * @uses nxt_filter_comment() Used to filter comment before adding comment.
 * @uses nxt_allow_comment() checks to see if comment is approved.
 * @uses nxt_insert_comment() Does the actual comment insertion to the database.
 *
 * @param array $commentdata Contains information on the comment.
 * @return int The ID of the comment after adding.
 */
function nxt_new_comment($commentdata)
{
    $commentdata = apply_filters('preprocess_comment', $commentdata);
    $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
    if (isset($commentdata['user_ID'])) {
        $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
    } elseif (isset($commentdata['user_id'])) {
        $commentdata['user_id'] = (int) $commentdata['user_id'];
    }
    $commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
    $parent_status = 0 < $commentdata['comment_parent'] ? nxt_get_comment_status($commentdata['comment_parent']) : '';
    $commentdata['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $commentdata['comment_parent'] : 0;
    $commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
    $commentdata['comment_agent'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 254);
    $commentdata['comment_date'] = current_time('mysql');
    $commentdata['comment_date_gmt'] = current_time('mysql', 1);
    $commentdata = nxt_filter_comment($commentdata);
    $commentdata['comment_approved'] = nxt_allow_comment($commentdata);
    $comment_ID = nxt_insert_comment($commentdata);
    do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
    if ('spam' !== $commentdata['comment_approved']) {
        // If it's spam save it silently for later crunching
        if ('0' == $commentdata['comment_approved']) {
            nxt_notify_moderator($comment_ID);
        }
        $post =& get_post($commentdata['comment_post_ID']);
        // Don't notify if it's your own comment
        if (get_option('comments_notify') && $commentdata['comment_approved'] && (!isset($commentdata['user_id']) || $post->post_author != $commentdata['user_id'])) {
            nxt_notify_postauthor($comment_ID, isset($commentdata['comment_type']) ? $commentdata['comment_type'] : '');
        }
    }
    return $comment_ID;
}