コード例 #1
0
 /**
  * Annotaion Shortcode - End of a annotation
  * @param array $atts Attributes of the shortcode - only c for the comment id is accepted and required
  * @param null $content the Content in the code
  * @return null|string
  */
 public static function annot_end_shortcode($atts, $content = null)
 {
     // Attributes
     extract(shortcode_atts(array('c' => false), $atts));
     //Check if the comment is shown then add the span for the javascript
     if ($c && wp_get_comment_status($c) == 'approved') {
         return '<span id="annot-stop-' . $c . '" class="annot-stop"></span>' . $content;
     } else {
         return $content;
     }
 }
コード例 #2
0
 /**
  * Test as a privilged user (administrator)
  * Expects test to pass
  * @param mixed $comment Comment object
  * @return void
  */
 public function _test_as_admin($comment)
 {
     // Reset request
     $this->_clear_post_action();
     // Become an administrator
     $this->_setRole('administrator');
     // Set up a default request
     $_POST['id'] = $comment->comment_ID;
     $_POST['_ajax_nonce'] = wp_create_nonce('approve-comment_' . $comment->comment_ID);
     $_POST['_total'] = count($this->_comments);
     $_POST['_per_page'] = 100;
     $_POST['_page'] = 1;
     $_POST['_url'] = admin_url('edit-comments.php');
     // Save the comment status
     $prev_status = wp_get_comment_status($comment->comment_ID);
     // Make the request
     try {
         $this->_handleAjax('dim-comment');
     } catch (WPAjaxDieContinueException $e) {
         unset($e);
     }
     // Get the response
     $xml = simplexml_load_string($this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA);
     // Ensure everything is correct
     $this->assertEquals($comment->comment_ID, (string) $xml->response[0]->comment['id']);
     $this->assertEquals('dim-comment_' . $comment->comment_ID, (string) $xml->response['action']);
     $this->assertGreaterThanOrEqual(time() - 10, (int) $xml->response[0]->comment[0]->supplemental[0]->time[0]);
     $this->assertLessThanOrEqual(time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0]);
     // Check the status
     $current = wp_get_comment_status($comment->comment_ID);
     if (in_array($prev_status, array('unapproved', 'spam'))) {
         $this->assertEquals('approved', $current);
     } else {
         $this->assertEquals('unapproved', $current);
     }
     // The total is calculated based on a page break -OR- a random number.  Let's look for both possible outcomes
     $comment_count = wp_count_comments(0);
     $recalc_total = $comment_count->total_comments;
     // Delta is not specified, it will always be 1 lower than the request
     $total = $_POST['_total'] - 1;
     // Check for either possible total
     $this->assertTrue(in_array((int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array($total, $recalc_total)));
 }
コード例 #3
0
 /**
  * Get list of events. There's filter `slack_get_events`
  * to extend available events that can be notified to
  * Slack.
  */
 public function get_events()
 {
     return apply_filters('slack_get_events', array('post_published' => array('action' => 'transition_post_status', 'description' => __('When a post is published', 'slack'), 'default' => true, 'message' => function ($new_status, $old_status, $post) {
         $notified_post_types = apply_filters('slack_event_transition_post_status_post_types', array('post'));
         if (!in_array($post->post_type, $notified_post_types)) {
             return false;
         }
         if ('publish' !== $old_status && 'publish' === $new_status) {
             $excerpt = has_excerpt($post->ID) ? apply_filters('get_the_excerpt', $post->post_excerpt) : wp_trim_words(strip_shortcodes($post->post_content), 55, '&hellip;');
             return sprintf('New post published: *<%1$s|%2$s>* by *%3$s*' . "\n" . '> %4$s', get_permalink($post->ID), get_the_title($post->ID), get_the_author_meta('display_name', $post->post_author), $excerpt);
         }
     }), 'post_pending_review' => array('action' => 'transition_post_status', 'description' => __('When a post needs review', 'slack'), 'default' => false, 'message' => function ($new_status, $old_status, $post) {
         $notified_post_types = apply_filters('slack_event_transition_post_status_post_types', array('post'));
         if (!in_array($post->post_type, $notified_post_types)) {
             return false;
         }
         if ('pending' !== $old_status && 'pending' === $new_status) {
             $excerpt = has_excerpt($post->ID) ? apply_filters('get_the_excerpt', $post->post_excerpt) : wp_trim_words(strip_shortcodes($post->post_content), 55, '&hellip;');
             return sprintf('New post needs review: *<%1$s|%2$s>* by *%3$s*' . "\n" . '> %4$s', admin_url(sprintf('post.php?post=%d&action=edit', $post->ID)), get_the_title($post->ID), get_the_author_meta('display_name', $post->post_author), $excerpt);
         }
     }), 'new_comment' => array('action' => 'wp_insert_comment', 'priority' => 999, 'description' => __('When there is a new comment', 'slack'), 'default' => false, 'message' => function ($comment_id, $comment) {
         $comment = is_object($comment) ? $comment : get_comment(absint($comment));
         $post_id = $comment->comment_post_ID;
         $notified_post_types = apply_filters('slack_event_wp_insert_comment_post_types', array('post'));
         if (!in_array(get_post_type($post_id), $notified_post_types)) {
             return false;
         }
         $post_title = get_the_title($post_id);
         $comment_status = wp_get_comment_status($comment_id);
         // Ignore spam.
         if ('spam' === $comment_status) {
             return false;
         }
         return sprintf('<%1$s|New comment> by *%2$s* on *<%3$s|%4$s>* (_%5$s_)' . "\n" . '>%6$s', admin_url("comment.php?c={$comment_id}&action=editcomment"), $comment->comment_author, get_permalink($post_id), $post_title, $comment_status, preg_replace("/\n/", "\n>", get_comment_text($comment_id)));
     })));
 }
コード例 #4
0
 /**
  * @see CPAC_Column_Actions::get_actions()
  * @since 2.3.4
  */
 public function get_actions($id)
 {
     global $post, $comment_status;
     $comment = get_comment($id);
     // set uased vars
     $user_can = current_user_can('edit_comment', $comment->comment_ID);
     $the_comment_status = wp_get_comment_status($comment->comment_ID);
     if ($user_can) {
         $del_nonce = esc_html('_wpnonce=' . wp_create_nonce("delete-comment_{$comment->comment_ID}"));
         $approve_nonce = esc_html('_wpnonce=' . wp_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}");
     }
     /** begin - copied from class-wp-comments-list-table */
     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);
         $actions_copy = $actions;
         $actions = array();
         foreach ($actions_copy as $action => $link) {
             $action_append = '';
             // Reply and quickedit need a hide-if-no-js span when not added with ajax
             if (('reply' == $action || 'quickedit' == $action) && !defined('DOING_AJAX')) {
                 $action_append .= ' 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, '_wp_trash_meta_status', true)) {
                     $action_append .= ' approve';
                 } else {
                     $action_append .= ' unapprove';
                 }
             }
             $action .= $action_append;
             $actions[$action] = $link;
         }
     }
     return $actions;
 }
コード例 #5
0
ファイル: dashboard.php プロジェクト: riasnelli/WordPress
/**
 * @global WP_Comment $comment
 *
 * @param WP_Comment $comment
 * @param bool       $show_date
 */
function _wp_dashboard_recent_comments_row(&$comment, $show_date = true)
{
    $GLOBALS['comment'] = clone $comment;
    if ($comment->comment_post_ID > 0 && current_user_can('edit_post', $comment->comment_post_ID)) {
        $comment_post_title = _draft_or_post_title($comment->comment_post_ID);
        $comment_post_url = get_edit_post_link($comment->comment_post_ID);
        $comment_post_link = "<a href='{$comment_post_url}'>{$comment_post_title}</a>";
    } else {
        $comment_post_link = '';
    }
    $actions_string = '';
    if (current_user_can('edit_comment', $comment->comment_ID)) {
        // Pre-order it: Approve | Reply | Edit | Spam | Trash.
        $actions = array('approve' => '', 'unapprove' => '', 'reply' => '', 'edit' => '', 'spam' => '', 'trash' => '', 'delete' => '', 'view' => '');
        $del_nonce = esc_html('_wpnonce=' . wp_create_nonce("delete-comment_{$comment->comment_ID}"));
        $approve_nonce = esc_html('_wpnonce=' . wp_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}' data-wp-lists='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
        $actions['unapprove'] = "<a href='{$unapprove_url}' data-wp-lists='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved' class='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="window.commentReply && 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}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::spam=1' class='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}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1' class='delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
        } else {
            $actions['trash'] = "<a href='{$trash_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1' class='delete vim-d vim-destructive' title='" . esc_attr__('Move this comment to the trash') . "'>" . _x('Trash', 'verb') . '</a>';
        }
        if ('1' === $comment->comment_approved) {
            $actions['view'] = '<a class="comment-link" href="' . esc_url(get_comment_link($comment)) . '">' . _x('View', 'verb') . '</a>';
        }
        /**
         * Filter the action links displayed for each comment in the 'Recent Comments'
         * dashboard widget.
         *
         * @since 2.6.0
         *
         * @param array      $actions An array of comment actions. Default actions include:
         *                            'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
         *                            'Delete', and 'Trash'.
         * @param WP_Comment $comment The comment object.
         */
        $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', wp_get_comment_status($comment)), $comment);
    ?>
>

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

			<?php 
    if (!$comment->comment_type || 'comment' == $comment->comment_type) {
        ?>

			<div class="dashboard-comment-wrap has-row-actions">
			<h4 class="comment-meta">
				<?php 
        if ($comment_post_link) {
            printf(__('From %1$s on %2$s%3$s'), '<cite class="comment-author">' . get_comment_author_link($comment) . '</cite>', $comment_post_link, ' <span class="approve">' . __('[Pending]') . '</span>');
        } else {
            printf(__('From %1$s %2$s'), '<cite class="comment-author">' . get_comment_author_link($comment) . '</cite>', ' <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 has-row-actions">
			<?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);
        ?>
</h4>
			<p class="comment-author"><?php 
        comment_author_link($comment);
        ?>
</p>

			<?php 
    }
    // comment_type
    ?>
			<blockquote><p><?php 
    comment_excerpt($comment);
    ?>
</p></blockquote>
			<p class="row-actions"><?php 
    echo $actions_string;
    ?>
</p>
			</div>
		</div>
<?php 
    $GLOBALS['comment'] = null;
}
コード例 #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 WordPress. 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 wp-config.php, for your environment.
 * See {@link https://core.trac.wordpress.org/ticket/9235}
 *
 * @since 1.5.0
 * @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`.
 *
 * @see wp_insert_comment()
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Comment data.
 *
 *     @type string $comment_author       The name of the comment author.
 *     @type string $comment_author_email The comment author email address.
 *     @type string $comment_author_url   The comment author URL.
 *     @type string $comment_content      The content of the comment.
 *     @type string $comment_date         The date the comment was submitted. Default is the current time.
 *     @type string $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                        Default is `$comment_date` in the GMT timezone.
 *     @type int    $comment_parent       The ID of this comment's parent, if any. Default 0.
 *     @type int    $comment_post_ID      The ID of the post that relates to the comment.
 *     @type int    $user_id              The ID of the user who submitted the comment. Default 0.
 *     @type int    $user_ID              Kept for backward-compatibility. Use `$user_id` instead.
 *     @type string $comment_agent        Comment author user agent. Default is the value of 'HTTP_USER_AGENT'
 *                                        in the `$_SERVER` superglobal sent in the original request.
 *     @type string $comment_author_IP    Comment author IP address in IPv4 format. Default is the value of
 *                                        'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request.
 * }
 * @return int|false The ID of the comment on success, false on failure.
 */
function wp_new_comment($commentdata)
{
    global $wpdb;
    if (isset($commentdata['user_ID'])) {
        $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
    }
    $prefiltered_user_id = isset($commentdata['user_id']) ? (int) $commentdata['user_id'] : 0;
    /**
     * Filter a comment's data before it is sanitized and inserted into the database.
     *
     * @since 1.5.0
     *
     * @param array $commentdata Comment data.
     */
    $commentdata = apply_filters('preprocess_comment', $commentdata);
    $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
    if (isset($commentdata['user_ID']) && $prefiltered_user_id !== (int) $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'] ? wp_get_comment_status($commentdata['comment_parent']) : '';
    $commentdata['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $commentdata['comment_parent'] : 0;
    if (!isset($commentdata['comment_author_IP'])) {
        $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
    }
    $commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP']);
    if (!isset($commentdata['comment_agent'])) {
        $commentdata['comment_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    }
    $commentdata['comment_agent'] = substr($commentdata['comment_agent'], 0, 254);
    if (empty($commentdata['comment_date'])) {
        $commentdata['comment_date'] = current_time('mysql');
    }
    if (empty($commentdata['comment_date_gmt'])) {
        $commentdata['comment_date_gmt'] = current_time('mysql', 1);
    }
    $commentdata = wp_filter_comment($commentdata);
    $commentdata['comment_approved'] = wp_allow_comment($commentdata);
    $comment_ID = wp_insert_comment($commentdata);
    if (!$comment_ID) {
        $fields = array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_content');
        foreach ($fields as $field) {
            if (isset($commentdata[$field])) {
                $commentdata[$field] = $wpdb->strip_invalid_text_for_column($wpdb->comments, $field, $commentdata[$field]);
            }
        }
        $commentdata = wp_filter_comment($commentdata);
        $commentdata['comment_approved'] = wp_allow_comment($commentdata);
        $comment_ID = wp_insert_comment($commentdata);
        if (!$comment_ID) {
            return false;
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 1.2.0
     *
     * @param int        $comment_ID       The comment ID.
     * @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
     */
    do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
    return $comment_ID;
}
コード例 #7
0
 public static function cron_recheck()
 {
     global $wpdb;
     $api_key = self::get_api_key();
     $status = self::verify_key($api_key);
     if (get_option('akismet_alert_code') || $status == 'invalid') {
         // since there is currently a problem with the key, reschedule a check for 6 hours hence
         wp_schedule_single_event(time() + 21600, 'akismet_schedule_cron_recheck');
         do_action('akismet_scheduled_recheck', 'key-problem-' . get_option('akismet_alert_code') . '-' . $status);
         return false;
     }
     delete_option('akismet_available_servers');
     $comment_errors = $wpdb->get_col("SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'\tLIMIT 100");
     load_plugin_textdomain('akismet');
     foreach ((array) $comment_errors as $comment_id) {
         // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
         $comment = get_comment($comment_id);
         if (!$comment || strtotime($comment->comment_date_gmt) < strtotime("-15 days")) {
             delete_comment_meta($comment_id, 'akismet_error');
             delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
             continue;
         }
         add_comment_meta($comment_id, 'akismet_rechecking', true);
         $status = self::check_db_comment($comment_id, 'retry');
         $event = '';
         if ($status == 'true') {
             $event = 'cron-retry-spam';
         } elseif ($status == 'false') {
             $event = 'cron-retry-ham';
         }
         // If we got back a legit response then update the comment history
         // other wise just bail now and try again later.  No point in
         // re-trying all the comments once we hit one failure.
         if (!empty($event)) {
             delete_comment_meta($comment_id, 'akismet_error');
             self::update_comment_history($comment_id, '', $event);
             update_comment_meta($comment_id, 'akismet_result', $status);
             // make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
             $comment = get_comment($comment_id);
             if ($comment && 'unapproved' == wp_get_comment_status($comment_id)) {
                 if ($status == 'true') {
                     wp_spam_comment($comment_id);
                 } elseif ($status == 'false') {
                     // comment is good, but it's still in the pending queue.  depending on the moderation settings
                     // we may need to change it to approved.
                     if (check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type)) {
                         wp_set_comment_status($comment_id, 1);
                     } else {
                         if (get_comment_meta($comment_id, 'akismet_delayed_moderation_email', true)) {
                             wp_notify_moderator($comment_id);
                         }
                     }
                 }
             }
             delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
         } else {
             // If this comment has been pending moderation for longer than MAX_DELAY_BEFORE_MODERATION_EMAIL,
             // send a moderation email now.
             if (intval(gmdate('U')) - strtotime($comment->comment_date_gmt) < self::MAX_DELAY_BEFORE_MODERATION_EMAIL) {
                 delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
                 wp_notify_moderator($comment_id);
             }
             delete_comment_meta($comment_id, 'akismet_rechecking');
             wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
             do_action('akismet_scheduled_recheck', 'check-db-comment-' . $status);
             return;
         }
         delete_comment_meta($comment_id, 'akismet_rechecking');
     }
     $remaining = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'");
     if ($remaining && !wp_next_scheduled('akismet_schedule_cron_recheck')) {
         wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
         do_action('akismet_scheduled_recheck', 'remaining');
     }
 }
コード例 #8
0
 function get_comment($comment_id, $context)
 {
     global $blog_id;
     $comment = get_comment($comment_id);
     if (!$comment || is_wp_error($comment)) {
         return new WP_Error('unknown_comment', 'Unknown comment', 404);
     }
     $types = array('', 'comment', 'pingback', 'trackback');
     if (!in_array($comment->comment_type, $types)) {
         return new WP_Error('unknown_comment', 'Unknown comment', 404);
     }
     $post = get_post($comment->comment_post_ID);
     if (!$post || is_wp_error($post)) {
         return new WP_Error('unknown_post', 'Unknown post', 404);
     }
     $status = wp_get_comment_status($comment->comment_ID);
     // Permissions
     switch ($context) {
         case 'edit':
             if (!current_user_can('edit_comment', $comment->comment_ID)) {
                 return new WP_Error('unauthorized', 'User cannot edit comment', 403);
             }
             $GLOBALS['post'] = $post;
             $comment = get_comment_to_edit($comment->comment_ID);
             foreach (array('comment_author', 'comment_author_email', 'comment_author_url') as $field) {
                 $comment->{$field} = htmlspecialchars_decode($comment->{$field}, ENT_QUOTES);
             }
             break;
         case 'display':
             if ('approved' !== $status) {
                 $current_user_id = get_current_user_id();
                 $user_can_read_coment = false;
                 if ($current_user_id && $comment->user_id && $current_user_id == $comment->user_id) {
                     $user_can_read_coment = true;
                 } elseif ($comment->comment_author_email && $comment->comment_author && isset($this->api->token_details['user']) && isset($this->api->token_details['user']['user_email']) && $this->api->token_details['user']['user_email'] === $comment->comment_author_email && $this->api->token_details['user']['display_name'] === $comment->comment_author) {
                     $user_can_read_coment = true;
                 } else {
                     $user_can_read_coment = current_user_can('edit_comment', $comment->comment_ID);
                 }
                 if (!$user_can_read_coment) {
                     return new WP_Error('unauthorized', 'User cannot read unapproved comment', 403);
                 }
             }
             $GLOBALS['post'] = $post;
             setup_postdata($post);
             break;
         default:
             return new WP_Error('invalid_context', 'Invalid API CONTEXT', 400);
     }
     $can_view = $this->user_can_view_post($post->ID);
     if (!$can_view || is_wp_error($can_view)) {
         return $can_view;
     }
     $GLOBALS['comment'] = $comment;
     $response = array();
     foreach (array_keys($this->comment_object_format) as $key) {
         switch ($key) {
             case 'ID':
                 // explicitly cast all output
                 $response[$key] = (int) $comment->comment_ID;
                 break;
             case 'post':
                 $response[$key] = (object) array('ID' => (int) $post->ID, 'title' => (string) get_the_title($post->ID), 'type' => (string) $post->post_type, 'link' => (string) $this->links->get_post_link($this->api->get_blog_id_for_output(), $post->ID));
                 break;
             case 'author':
                 $response[$key] = (object) $this->get_author($comment, 'edit' === $context && current_user_can('edit_comment', $comment->comment_ID));
                 break;
             case 'date':
                 $response[$key] = (string) $this->format_date($comment->comment_date_gmt, $comment->comment_date);
                 break;
             case 'URL':
                 $response[$key] = (string) esc_url_raw(get_comment_link($comment->comment_ID));
                 break;
             case 'short_URL':
                 // @todo - pagination
                 $response[$key] = (string) esc_url_raw(wp_get_shortlink($post->ID) . "%23comment-{$comment->comment_ID}");
                 break;
             case 'content':
                 if ('display' === $context) {
                     ob_start();
                     comment_text();
                     $response[$key] = (string) ob_get_clean();
                 } else {
                     $response[$key] = (string) $comment->comment_content;
                 }
                 break;
             case 'status':
                 $response[$key] = (string) $status;
                 break;
             case 'parent':
                 // (object|false)
                 if ($comment->comment_parent) {
                     $parent = get_comment($comment->comment_parent);
                     $response[$key] = (object) array('ID' => (int) $parent->comment_ID, 'type' => (string) ($parent->comment_type ? $parent->comment_type : 'comment'), 'link' => (string) $this->links->get_comment_link($blog_id, $parent->comment_ID));
                 } else {
                     $response[$key] = false;
                 }
                 break;
             case 'type':
                 $response[$key] = (string) ($comment->comment_type ? $comment->comment_type : 'comment');
                 break;
             case 'like_count':
                 if (defined('IS_WPCOM') && IS_WPCOM) {
                     $response[$key] = (int) $this->api->comment_like_count($blog_id, $post->ID, $comment->comment_ID);
                 }
                 break;
             case 'i_like':
                 if (defined('IS_WPCOM') && IS_WPCOM) {
                     $response[$key] = (bool) Likes::comment_like_current_user_likes($blog_id, $comment->comment_ID);
                 }
                 break;
             case 'meta':
                 $response[$key] = (object) array('links' => (object) array('self' => (string) $this->links->get_comment_link($this->api->get_blog_id_for_output(), $comment->comment_ID), 'help' => (string) $this->links->get_comment_link($this->api->get_blog_id_for_output(), $comment->comment_ID, 'help'), 'site' => (string) $this->links->get_site_link($this->api->get_blog_id_for_output()), 'post' => (string) $this->links->get_post_link($this->api->get_blog_id_for_output(), $comment->comment_post_ID), 'replies' => (string) $this->links->get_comment_link($this->api->get_blog_id_for_output(), $comment->comment_ID, 'replies/'), 'likes' => (string) $this->links->get_comment_link($this->api->get_blog_id_for_output(), $comment->comment_ID, 'likes/')));
                 break;
         }
     }
     unset($GLOBALS['comment'], $GLOBALS['post']);
     return $response;
 }
コード例 #9
0
        function get_comment_list_item($id, $alt = 0, $reply = false)
        {
            global $authordata, $comment, $wpdb, $user_identity, $user_email, $user_url;
            get_currentuserinfo();
            $id = (int) $id;
            $comment =& get_comment($id);
            $class = '';
            $post = get_post($comment->comment_post_ID);
            $authordata = get_userdata($post->post_author);
            $comment_status = wp_get_comment_status($comment->comment_ID);
            if (isset($_GET['replyid'])) {
                $query = remove_query_arg('replyid');
            } else {
                $query = add_query_arg('replyid', $comment->comment_ID);
            }
            if ('unapproved' == $comment_status) {
                $class .= ' unapproved';
            }
            if ($alt % 2) {
                $class .= ' alternate';
            }
            echo "<li id='comment-{$comment->comment_ID}' class='{$class}'>";
            ?>
			<p><strong><?php 
            comment_author();
            ?>
</strong> <?php 
            if ($comment->comment_author_email) {
                ?>
| <?php 
                comment_author_email_link();
                ?>
 <?php 
            }
            if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) {
                ?>
 | <?php 
                comment_author_url_link();
                ?>
 <?php 
            }
            ?>
| <?php 
            _e('IP:');
            ?>
 <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php 
            comment_author_IP();
            ?>
"><?php 
            comment_author_IP();
            ?>
</a></p>

			<?php 
            comment_text();
            ?>

			<p><?php 
            comment_date(__('M j, g:i A'));
            ?>
 &#8212; [
			<?php 
            if (current_user_can('edit_post', $comment->comment_post_ID)) {
                echo " <a href='comment.php?action=editcomment&amp;c=" . $comment->comment_ID . "'>" . __('Edit') . '</a>';
                echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
                if ('none' != $comment_status && current_user_can('moderate_comments')) {
                    echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
                    echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
                }
                echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', {$comment->comment_ID}, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> ";
                echo " | <a href='" . $query . "' onclick=' return addReplyForm(\"" . get_option('siteurl') . "/wp-content/plugins/soc-comments/soc-comments-post.php\"," . $id . "," . $comment->comment_post_ID . ",\"" . $user_identity . "\",\"" . $user_email . "\",\"" . $user_url . "\",\"" . wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) . "\",\"" . add_query_arg('ajax', '1') . "\")' >" . __('Reply') . " </a>";
            }
            $post = get_post($comment->comment_post_ID);
            $post_title = wp_specialchars($post->post_title, 'double');
            $post_title = '' == $post_title ? "# {$comment->comment_post_ID}" : $post_title;
            ?>
 			] &#8212; <a href="<?php 
            echo get_permalink($comment->comment_post_ID);
            ?>
"><?php 
            echo $post_title;
            ?>
</a></p>
			
			<div id="com-<?php 
            echo $comment->comment_ID;
            ?>
" >
			<?php 
            if (true == $reply) {
                ?>
	
			<?php 
                if ('open' == $post->comment_status) {
                    ?>

			<form action="<?php 
                    echo get_option('siteurl');
                    ?>
/wp-comments-post.php" method="POST" id="comment-reply-form">
			
			<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>

			<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
			<input type="hidden" name="comment_post_ID" value="<?php 
                    echo $comment->comment_post_ID;
                    ?>
" />
			<input type="hidden" id="author" name="author" value="<?php 
                    echo $user_identity;
                    ?>
" />
			<input type="hidden" id="email" name="email" value="<?php 
                    echo $user_email;
                    ?>
" />
			<input type="hidden" id="url" name="url" value="<?php 
                    echo $user_url;
                    ?>
" />
			<?php 
                    $qs = remove_query_arg('replyid');
                    ?>
			<input type="hidden" id="redirect_to"name="redirect_to" value="<?php 
                    echo $qs;
                    ?>
" />
			</p>
			<?php 
                    do_action('comment_form', $comment->comment_post_ID);
                    ?>
			</form>
			<?php 
                } else {
                    ?>
				<p> Sorry. Comments for this post are closed</p>
			</div>
			<?php 
                }
            }
            ?>
				</li>
				<?php 
        }
コード例 #10
0
 function delete_comment($path, $blog_id, $comment_id)
 {
     $comment = get_comment($comment_id);
     if (!$comment || is_wp_error($comment)) {
         return new WP_Error('unknown_comment', 'Unknown comment', 404);
     }
     if (!current_user_can('edit_comment', $comment->comment_ID)) {
         // [sic] There is no delete_comment cap
         return new WP_Error('unauthorized', 'User cannot delete comment', 403);
     }
     $args = $this->query_args();
     $return = $this->get_comment($comment->comment_ID, $args['context']);
     if (!$return || is_wp_error($return)) {
         return $return;
     }
     do_action('wpcom_json_api_objects', 'comments');
     wp_delete_comment($comment->comment_ID);
     $status = wp_get_comment_status($comment->comment_ID);
     if (false === $status) {
         $return['status'] = 'deleted';
         return $return;
     }
     return $this->get_comment($comment->comment_ID, $args['context']);
 }
コード例 #11
0
     if (wp_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 WP_Ajax_Response(array('what' => 'comment', 'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))));
         $x->send();
     }
     if (!current_user_can('edit_post', $comment->comment_post_ID) && !current_user_can('moderate_comments')) {
         die('-1');
     }
     $current = wp_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 = wp_set_comment_status($comment->comment_ID, 'approve', true);
     } else {
         $result = wp_set_comment_status($comment->comment_ID, 'hold', true);
     }
     if (is_wp_error($result)) {
         $x = new WP_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
     _wp_ajax_delete_comment_response($comment->comment_ID);
コード例 #12
0
 /**
  * Set the comment_status of a given comment object when creating or updating a comment.
  *
  * @param string|int $new_status
  * @param object     $comment
  * @return boolean   $changed
  */
 protected function handle_status_param($new_status, $comment)
 {
     $old_status = wp_get_comment_status($comment->comment_ID);
     if ($new_status === $old_status) {
         return false;
     }
     switch ($new_status) {
         case 'approved':
         case 'approve':
         case '1':
             $changed = wp_set_comment_status($comment->comment_ID, 'approve');
             break;
         case 'hold':
         case '0':
             $changed = wp_set_comment_status($comment->comment_ID, 'hold');
             break;
         case 'spam':
             $changed = wp_spam_comment($comment->comment_ID);
             break;
         case 'unspam':
             $changed = wp_unspam_comment($comment->comment_ID);
             break;
         case 'trash':
             $changed = wp_trash_comment($comment->comment_ID);
             break;
         case 'untrash':
             $changed = wp_untrash_comment($comment->comment_ID);
             break;
         default:
             $changed = false;
             break;
     }
     return $changed;
 }
コード例 #13
0
 function hook_edit_comment($comment_id)
 {
     if (wp_get_comment_status($comment_id) == 'approved') {
         $container = blcContainerHelper::get_container(array($this->container_type, $comment_id));
         $container->mark_as_unsynched();
     }
 }
コード例 #14
0
        function widget($args, $instance)
        {
            if (RWLogger::IsOn()) {
                $params = func_get_args();
                RWLogger::LogEnterence("RatingWidgetPlugin_TopRatedWidget.widget", $params, true);
            }
            if (!defined("WP_RW__SITE_PUBLIC_KEY") || false === WP_RW__SITE_PUBLIC_KEY) {
                return;
            }
            if (RatingWidgetPlugin::$WP_RW__HIDE_RATINGS) {
                return;
            }
            extract($args, EXTR_SKIP);
            $bpInstalled = ratingwidget()->IsBuddyPressInstalled();
            $bbInstalled = ratingwidget()->IsBBPressInstalled();
            $types = $this->GetTypesInfo();
            $show_any = false;
            foreach ($types as $type => $data) {
                if (false !== $instance["show_{$type}"]) {
                    $show_any = true;
                    break;
                }
            }
            if (RWLogger::IsOn()) {
                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget', 'show_any = ' . ($show_any ? 'TRUE' : 'FALSE'));
            }
            if (false === $show_any) {
                // Nothing to show.
                return;
            }
            $details = array("uid" => WP_RW__SITE_PUBLIC_KEY);
            $queries = array();
            foreach ($types as $type => $type_data) {
                if (isset($instance["show_{$type}"]) && $instance["show_{$type}"] && $instance["{$type}_count"] > 0) {
                    $options = ratingwidget()->GetOption($type_data["options"]);
                    $queries[$type] = array("rclasses" => $type_data["classes"], "votes" => max(1, (int) $instance["{$type}_min_votes"]), "orderby" => $instance["{$type}_orderby"], "order" => $instance["{$type}_order"], "limit" => (int) $instance["{$type}_count"], "types" => isset($options->type) ? $options->type : "star");
                    $since_created = isset($instance["{$type}_since_created"]) ? (int) $instance["{$type}_since_created"] : WP_RW__TIME_ALL_TIME;
                    // since_created should be at least 24 hours (86400 seconds), skip otherwise.
                    if ($since_created >= WP_RW__TIME_24_HOURS_IN_SEC) {
                        $time = current_time('timestamp', true) - $since_created;
                        // c: ISO 8601 full date/time, e.g.: 2004-02-12T15:19:21+00:00
                        $queries[$type]['since_created'] = date('c', $time);
                    }
                }
            }
            $details["queries"] = urlencode(json_encode($queries));
            $rw_ret_obj = ratingwidget()->RemoteCall("action/query/ratings.php", $details, WP_RW__CACHE_TIMEOUT_TOP_RATED);
            if (false === $rw_ret_obj) {
                return;
            }
            $rw_ret_obj = json_decode($rw_ret_obj);
            if (null === $rw_ret_obj || true !== $rw_ret_obj->success) {
                return;
            }
            $title = empty($instance['title']) ? __('Top Rated', WP_RW__ID) : apply_filters('widget_title', $instance['title']);
            $titleMaxLength = isset($instance['title_max_length']) && is_numeric($instance['title_max_length']) ? (int) $instance['title_max_length'] : 30;
            $empty = true;
            $toprated_data = new stdClass();
            $toprated_data->id = rand(1, 100);
            $toprated_data->title = array('label' => $title, 'show' => true, 'before' => $this->EncodeHtml($before_title), 'after' => $this->EncodeHtml($after_title));
            $toprated_data->options = array('align' => 'vertical', 'direction' => 'ltr', 'html' => array('before' => $this->EncodeHtml($before_widget), 'after' => $this->EncodeHtml($after_widget)));
            $toprated_data->site = array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST'], 'type' => 'WordPress');
            $toprated_data->itemGroups = array();
            if (count($rw_ret_obj->data) > 0) {
                foreach ($rw_ret_obj->data as $type => $ratings) {
                    if (is_array($ratings) && count($ratings) > 0) {
                        $item_group = new stdClass();
                        $item_group->type = $type;
                        $item_group->title = $instance["{$type}_title"];
                        $item_group->showTitle = 1 === $instance["show_{$type}_title"] && '' !== trim($item_group->title);
                        if (is_numeric($instance["{$type}_style"])) {
                            switch ($instance["{$type}_style"]) {
                                case 0:
                                    $instance["{$type}_style"] = 'legacy';
                                    break;
                                case 1:
                                default:
                                    $instance["{$type}_style"] = 'thumbs';
                                    break;
                            }
                        }
                        $item_group->style = $instance["{$type}_style"];
                        $item_group->options = array('title' => array('maxLen' => $titleMaxLength));
                        $item_group->items = array();
                        $has_thumb = strtolower($instance["{$type}_style"]) !== 'legacy';
                        $thumb_width = 160;
                        $thumb_height = 100;
                        if ($has_thumb) {
                            switch ($instance["{$type}_style"]) {
                                case '2':
                                case 'compact_thumbs':
                                    $thumb_width = 50;
                                    $thumb_height = 40;
                                    break;
                                case '1':
                                case 'thumbs':
                                default:
                                    $thumb_width = 160;
                                    $thumb_height = 100;
                                    break;
                            }
                            $item_group->options['thumb'] = array('width' => $thumb_width, 'height' => $thumb_height);
                        }
                        $cell = 0;
                        foreach ($ratings as $rating) {
                            $urid = $rating->urid;
                            $rclass = $types[$type]["rclass"];
                            $rclasses[$rclass] = true;
                            $extension_type = false;
                            if (RWLogger::IsOn()) {
                                RWLogger::Log('HANDLED_ITEM', 'Urid = ' . $urid . '; Class = ' . $rclass . ';');
                            }
                            if ('posts' === $type || 'pages' === $type) {
                                $post = null;
                                $id = RatingWidgetPlugin::Urid2PostId($urid);
                                $status = @get_post_status($id);
                                if (false === $status) {
                                    if (RWLogger::IsOn()) {
                                        RWLogger::Log('POST_NOT_EXIST', $id);
                                    }
                                    // Post not exist.
                                    continue;
                                } else {
                                    if ('publish' !== $status && 'private' !== $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('POST_NOT_VISIBLE', 'status = ' . $status);
                                        }
                                        // Post not yet published.
                                        continue;
                                    } else {
                                        if ('private' === $status && !is_user_logged_in()) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget::widget', 'POST_PRIVATE && USER_LOGGED_OUT');
                                            }
                                            // Private post but user is not logged in.
                                            continue;
                                        }
                                    }
                                }
                                $post = @get_post($id);
                                $title = trim(strip_tags($post->post_title));
                                $permalink = get_permalink($post->ID);
                            } else {
                                if ('comments' === $type) {
                                    $comment = null;
                                    $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                    $status = @wp_get_comment_status($id);
                                    if (false === $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('COMMENT_NOT_EXIST', $id);
                                        }
                                        // Comment not exist.
                                        continue;
                                    } else {
                                        if ('approved' !== $status) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('COMMENT_NOT_VISIBLE', 'status = ' . $status);
                                            }
                                            // Comment not approved.
                                            continue;
                                        }
                                    }
                                    $comment = @get_comment($id);
                                    $title = trim(strip_tags($comment->comment_content));
                                    $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                } else {
                                    if ('activity_updates' === $type || 'activity_comments' === $type) {
                                        $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                        $activity = new bp_activity_activity($id);
                                        if (!is_object($activity)) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('BP_ACTIVITY_NOT_EXIST', $id);
                                            }
                                            // Activity not exist.
                                            continue;
                                        } else {
                                            if (!empty($activity->is_spam)) {
                                                if (RWLogger::IsOn()) {
                                                    RWLogger::Log('BP_ACTIVITY_NOT_VISIBLE (SPAM or TRASH)');
                                                }
                                                // Activity marked as SPAM or TRASH.
                                                continue;
                                            } else {
                                                if (!empty($activity->hide_sitewide)) {
                                                    if (RWLogger::IsOn()) {
                                                        RWLogger::Log('BP_ACTIVITY_HIDE_SITEWIDE');
                                                    }
                                                    // Activity marked as hidden in site.
                                                    continue;
                                                }
                                            }
                                        }
                                        $title = trim(strip_tags($activity->content));
                                        $permalink = bp_activity_get_permalink($id);
                                    } else {
                                        if ('users' === $type) {
                                            $id = RatingWidgetPlugin::Urid2UserId($urid);
                                            if ($bpInstalled) {
                                                $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                                $permalink = bp_core_get_user_domain($id);
                                            } else {
                                                if ($bbInstalled) {
                                                    $title = trim(strip_tags(bbp_get_user_display_name($id)));
                                                    $permalink = bbp_get_user_profile_url($id);
                                                } else {
                                                    continue;
                                                }
                                            }
                                        } else {
                                            if ('forum_posts' === $type || 'forum_replies' === $type) {
                                                $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                                if (function_exists('bp_forums_get_post')) {
                                                    $forum_post = @bp_forums_get_post($id);
                                                    if (!is_object($forum_post)) {
                                                        continue;
                                                    }
                                                    $title = trim(strip_tags($forum_post->post_text));
                                                    $page = bb_get_page_number($forum_post->post_position);
                                                    $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                                } else {
                                                    if (function_exists('bbp_get_reply_id')) {
                                                        $forum_item = bbp_get_topic();
                                                        if (is_object($forum_item)) {
                                                            $is_topic = true;
                                                        } else {
                                                            $is_topic = false;
                                                            $forum_item = bbp_get_reply($id);
                                                            if (!is_object($forum_item)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_FORUM_ITEM_NOT_EXIST', $id);
                                                                }
                                                                // Invalid id (no topic nor reply).
                                                                continue;
                                                            }
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_IS_TOPIC_REPLY', $is_topic ? 'FALSE' : 'TRUE');
                                                            }
                                                        }
                                                        // Visible statueses: Public or Closed.
                                                        $visible_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id());
                                                        if (!in_array($forum_item->post_status, $visible_statuses)) {
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_FORUM_ITEM_HIDDEN', $forum_item->post_status);
                                                            }
                                                            // Item is not public nor closed.
                                                            continue;
                                                        }
                                                        $is_reply = !$is_topic;
                                                        if ($is_reply) {
                                                            // Get parent topic.
                                                            $forum_topic = bbp_get_topic($forum_post->post_parent);
                                                            if (!in_array($forum_topic->post_status, $visible_statuses)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_PARENT_FORUM_TOPIC_IS_HIDDEN', 'TRUE');
                                                                }
                                                                // Parent topic is not public nor closed.
                                                                continue;
                                                            }
                                                        }
                                                        $title = trim(strip_tags($forum_post->post_title));
                                                        $permalink = get_permalink($forum_post->ID);
                                                    } else {
                                                        continue;
                                                    }
                                                }
                                                $types[$type]['handler']->GetElementInfoByRating();
                                            } else {
                                                $found_handler = false;
                                                $extensions = ratingwidget()->GetExtensions();
                                                foreach ($extensions as $ext) {
                                                    $result = $ext->GetElementInfoByRating($type, $rating);
                                                    if (false !== $result) {
                                                        $found_handler = true;
                                                        break;
                                                    }
                                                }
                                                if ($found_handler) {
                                                    $id = $result['id'];
                                                    $title = $result['title'];
                                                    $permalink = $result['permalink'];
                                                    $img = rw_get_thumb_url($result['img'], $thumb_width, $thumb_height, $result['permalink']);
                                                    $extension_type = true;
                                                } else {
                                                    continue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            $queued = ratingwidget()->QueueRatingData($urid, "", "", $rclass);
                            // Override rating class in case the same rating has already been queued with a different rclass.
                            $rclass = $queued['rclass'];
                            $short = mb_strlen($title) > $titleMaxLength ? trim(mb_substr($title, 0, $titleMaxLength)) . "..." : $title;
                            $item = array('site' => array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST']), 'page' => array('externalID' => $id, 'url' => $permalink, 'title' => $short), 'rating' => array('localID' => $urid, 'options' => array('rclass' => $rclass)));
                            // Add thumb url.
                            if ($extension_type && is_string($img)) {
                                $item['page']['img'] = $img;
                            } else {
                                if ($has_thumb && in_array($type, array('posts', 'pages'))) {
                                    $item['page']['img'] = rw_get_post_thumb_url($post, $thumb_width, $thumb_height);
                                }
                            }
                            $item_group->items[] = $item;
                            $cell++;
                            $empty = false;
                        }
                        $toprated_data->itemGroups[] = $item_group;
                    }
                }
            }
            if (true === $empty) {
                //            echo '<p style="margin: 0;">There are no rated items for this period.</p>';
                //        echo $before_widget;
                //        echo $after_widget;
            } else {
                // Set a flag that the widget is loaded.
                ratingwidget()->TopRatedWidgetLoaded();
                ?>
					<b class="rw-ui-recommendations" data-id="<?php 
                echo $toprated_data->id;
                ?>
"></b>
					<script type="text/javascript">
						var _rwq = _rwq || [];
						_rwq.push(['_setRecommendations', <?php 
                echo json_encode($toprated_data);
                ?>
]);
					</script>
				<?php 
            }
        }
コード例 #15
0
 /**
  * Returns a approve/unapprove/spam/unspam/trash/untrash link for a comment
  *
  * @param $comment_id int The comment_id of the comment you want the URL to affect
  * @param $type string The type of action you want the link to apply to the comment: approve/spam/trash
  */
 public function get_status_link($comment_id, $type)
 {
     if (!($comment = get_comment($comment_id))) {
         return FALSE;
     }
     // END if
     if (!in_array($type, array('approve', 'spam', 'trash'))) {
         return FALSE;
     }
     // END if
     $text = NULL;
     $class = NULL;
     $status = wp_get_comment_status($comment->comment_ID);
     if ('approve' == $type) {
         if ('approved' == $status) {
             $text = 'Unapprove';
             $class = 'approved-comment';
         } else {
             $text = 'Approve';
             $class = 'unapproved-comment';
         }
         //end else
     } elseif ('spam' == $type) {
         if ('spam' == $status) {
             $text = 'Unspam';
             $class = 'spammed-comment';
         } else {
             $text = 'Spam';
             $class = 'unspamed-comment';
         }
         //end else
     } elseif ('trash' == $type) {
         if ('trash' == $status) {
             $text = 'Untrash';
             $class = 'trashed-comment';
         } else {
             $text = 'Trash';
             $class = 'untrashed-comment';
         }
         //end else
     }
     //end elseif
     if (!$text) {
         return;
     }
     //end if
     $url = $this->get_status_url($comment->comment_ID, $type);
     return '<a href="' . esc_url($url) . '" title="' . $text . '" class="' . $class . '">' . $text . '</a>';
 }
コード例 #16
0
function _wp_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 = 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="' . get_comment_link() . '">#</a>';

	$delete_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
	$approve_url = clean_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
	$unapprove_url = clean_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
	$spam_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );

	$actions = array();

	$actions_string = '';
	if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
		$actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( '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='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
		$actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
		//$actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\',\'edit\');return false;" class="vim-q" title="'.__('Quick Edit').'" href="#">' . __('Quick&nbsp;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="'.__('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='" . __( 'Mark this comment as spam' ) . "'>" . _c( 'Spam|verb' ) . '</a>';
		$actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';

		$actions = apply_filters( 'comment_row_actions', $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', wp_get_comment_status($comment->comment_ID) ) ); ?>>
			<?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>

			<?php echo get_avatar( $comment, 50 ); ?>
			<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 );
				endswitch;
				$type = wp_specialchars( $type );
			?>

			<h4 class="comment-meta"><?php printf( __( '%1$s on %2$s' ), "<strong>$type</strong>", $comment_post_link ); ?></h4>
			<p class="comment-author"><?php comment_author_link(); ?></p>

			<?php endif; // comment_type ?>
			<blockquote><p><?php comment_excerpt(); ?></p></blockquote>
			<p class="row-actions"><?php echo $actions_string; ?></p>

			<div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
				<textarea class="comment" rows="3" cols="10"><?php echo $comment->comment_content; ?></textarea>
				<div class="author-email"><?php echo attribute_escape( $comment->comment_author_email ); ?></div>
				<div class="author"><?php echo attribute_escape( $comment->comment_author ); ?></div>
				<div class="author-url"><?php echo attribute_escape( $comment->comment_author_url ); ?></div>
				<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
			</div>

		</div>
<?php
}
コード例 #17
0
    function column_comment($comment)
    {
        global $comment_status;
        $post = get_post();
        $user_can = $this->user_can;
        $comment_url = esc_url(get_comment_link($comment->comment_ID));
        $the_comment_status = wp_get_comment_status($comment->comment_ID);
        $ptime = date('G', strtotime($comment->comment_date));
        if (abs(time() - $ptime) < DAY_IN_SECONDS) {
            $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('_wpnonce=' . wp_create_nonce("delete-comment_{$comment->comment_ID}"));
            $approve_nonce = esc_html('_wpnonce=' . wp_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}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=unapproved' class='vim-u vim-destructive' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
                } else {
                    if ('unapproved' == $the_comment_status) {
                        $actions['approve'] = "<a href='{$approve_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=approved' class='vim-a vim-destructive' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
                    }
                }
            } else {
                $actions['approve'] = "<a href='{$approve_url}' data-wp-lists='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
                $actions['unapprove'] = "<a href='{$unapprove_url}' data-wp-lists='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved' class='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}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::spam=1' class='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}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1' class='vim-z vim-destructive'>" . _x('Not Spam', 'comment') . '</a>';
            } elseif ('trash' == $the_comment_status) {
                $actions['untrash'] = "<a href='{$untrash_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1' class='vim-z vim-destructive'>" . __('Restore') . '</a>';
            }
            if ('spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS) {
                $actions['delete'] = "<a href='{$delete_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::delete=1' class='delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
            } else {
                $actions['trash'] = "<a href='{$trash_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1' class='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, '_wp_trash_meta_status', true)) {
                        $action .= ' approve';
                    } else {
                        $action .= ' unapprove';
                    }
                }
                echo "<span class='{$action}'>{$sep}{$link}</span>";
            }
            echo '</div>';
        }
    }
コード例 #18
0
 function get_recent_comments($pAllowedStatuses, $pCount)
 {
     if (!function_exists('get_comment_author_url')) {
         include_once WPINC . '/comment-template.php';
     }
     $allComments = array();
     foreach ($pAllowedStatuses as $status) {
         $params = array('status' => $status);
         if (0 !== $pCount) {
             $params['number'] = $pCount;
         }
         $comments = get_comments($params);
         if (is_array($comments)) {
             foreach ($comments as $comment) {
                 $post = get_post($comment->comment_post_ID);
                 $outComment = array();
                 $outComment['id'] = $comment->comment_ID;
                 $outComment['status'] = wp_get_comment_status($comment->comment_ID);
                 $outComment['author'] = $comment->comment_author;
                 $outComment['author_url'] = get_comment_author_url($comment->comment_ID);
                 $outComment['author_ip'] = get_comment_author_IP($comment->comment_ID);
                 $outComment['author_email'] = $email = apply_filters('comment_email', $comment->comment_author_email);
                 if (!empty($outComment['author_email']) && '@' !== $outComment['author_email']) {
                     $outComment['author_email'] = '<a href="mailto:' . $outComment['author_email'] . '">' . $outComment['author_email'] . '</a>';
                 }
                 $outComment['postId'] = $comment->comment_post_ID;
                 $outComment['postName'] = $post->post_title;
                 $outComment['comment_count'] = $post->comment_count;
                 $outComment['content'] = $comment->comment_content;
                 $outComment['dts'] = strtotime($comment->comment_date_gmt);
                 $allComments[] = $outComment;
             }
         }
     }
     return $allComments;
 }
コード例 #19
0
ファイル: jetpack-carousel.php プロジェクト: ugurozer/little
 function post_attachment_comment()
 {
     if (!headers_sent()) {
         header('Content-type: text/javascript');
     }
     if (empty($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'carousel_nonce')) {
         die(json_encode(array('error' => __('Nonce verification failed.', 'jetpack'))));
     }
     $_blog_id = (int) $_POST['blog_id'];
     $_post_id = (int) $_POST['id'];
     $comment = $_POST['comment'];
     if (empty($_blog_id)) {
         die(json_encode(array('error' => __('Missing target blog ID.', 'jetpack'))));
     }
     if (empty($_post_id)) {
         die(json_encode(array('error' => __('Missing target post ID.', 'jetpack'))));
     }
     if (empty($comment)) {
         die(json_encode(array('error' => __('No comment text was submitted.', 'jetpack'))));
     }
     // Used in context like NewDash
     $switched = false;
     if (is_multisite() && $_blog_id != get_current_blog_id()) {
         switch_to_blog($_blog_id);
         $switched = true;
     }
     do_action('jp_carousel_check_blog_user_privileges');
     if (!comments_open($_post_id)) {
         die(json_encode(array('error' => __('Comments on this post are closed.', 'jetpack'))));
     }
     if (is_user_logged_in()) {
         $user = wp_get_current_user();
         $user_id = $user->ID;
         $display_name = $user->display_name;
         $email = $user->user_email;
         $url = $user->user_url;
         if (empty($user_id)) {
             die(json_encode(array('error' => __('Sorry, but we could not authenticate your request.', 'jetpack'))));
         }
     } else {
         $user_id = 0;
         $display_name = $_POST['author'];
         $email = $_POST['email'];
         $url = $_POST['url'];
         if (get_option('require_name_email')) {
             if (empty($display_name)) {
                 die(json_encode(array('error' => __('Please provide your name.', 'jetpack'))));
             }
             if (empty($email)) {
                 die(json_encode(array('error' => __('Please provide an email address.', 'jetpack'))));
             }
             if (!is_email($email)) {
                 die(json_encode(array('error' => __('Please provide a valid email address.', 'jetpack'))));
             }
         }
     }
     $comment_data = array('comment_content' => $comment, 'comment_post_ID' => $_post_id, 'comment_author' => $display_name, 'comment_author_email' => $email, 'comment_author_url' => $url, 'comment_approved' => 0, 'comment_type' => '');
     if (!empty($user_id)) {
         $comment_data['user_id'] = $user_id;
     }
     // Note: wp_new_comment() sanitizes and validates the values (too).
     $comment_id = wp_new_comment($comment_data);
     do_action('jp_carousel_post_attachment_comment');
     $comment_status = wp_get_comment_status($comment_id);
     if (true == $switched) {
         restore_current_blog();
     }
     die(json_encode(array('comment_id' => $comment_id, 'comment_status' => $comment_status)));
 }
コード例 #20
0
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $comment_id
 * @param unknown_type $mode
 * @param unknown_type $comment_status
 * @param unknown_type $checkbox
 */
function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true, $from_ajax = false ) {
	global $comment, $post, $_comment_pending_count;
	$comment = get_comment( $comment_id );
	$post = get_post($comment->comment_post_ID);
	$the_comment_status = wp_get_comment_status($comment->comment_ID);

	$author_url = get_comment_author_url();
	if ( 'http://' == $author_url )
		$author_url = '';
	$author_url_display = $author_url;
	$author_url_display = str_replace('http://www.', '', $author_url_display);
	$author_url_display = str_replace('http://', '', $author_url_display);
	if ( strlen($author_url_display) > 50 )
		$author_url_display = substr($author_url_display, 0, 49) . '...';

	$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 );

	$delete_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$post->ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
	$approve_url = clean_url( wp_nonce_url( "comment.php?action=approvecomment&p=$post->ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
	$unapprove_url = clean_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$post->ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
	$spam_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$post->ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );

	echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
	$columns = get_column_headers('edit-comments');
	$hidden = get_hidden_columns('edit-comments');
	foreach ( $columns as $column_name => $column_display_name ) {
		$class = "class=\"$column_name column-$column_name\"";

		$style = '';
		if ( in_array($column_name, $hidden) )
			$style = ' style="display:none;"';

		$attributes = "$class$style";

		switch ($column_name) {
			case 'cb':
				if ( !$checkbox ) break;
				echo '<th scope="row" class="check-column">';
				if ( current_user_can('edit_post', $post->ID) ) echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />";
				echo '</th>';
				break;
			case 'comment':
				echo "<td $attributes>";
				echo '<div id="submitted-on">';
				printf(__('Submitted on <a href="%1$s">%2$s at %3$s</a>'), get_comment_link($comment->comment_ID), get_comment_date(__('Y/m/d')), get_comment_date(__('g:ia')));
				echo '</div>';
				comment_text(); ?>
				<div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
				<textarea class="comment" rows="3" cols="10"><?php echo $comment->comment_content; ?></textarea>
				<div class="author-email"><?php echo attribute_escape( $comment->comment_author_email ); ?></div>
				<div class="author"><?php echo attribute_escape( $comment->comment_author ); ?></div>
				<div class="author-url"><?php echo attribute_escape( $comment->comment_author_url ); ?></div>
				<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
				</div>
				<?php
				$actions = array();

				if ( current_user_can('edit_post', $post->ID) ) {
					$actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( '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='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
					if ( $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='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
							unset($actions['approve']);
						} else {
							$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='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
							unset($actions['unapprove']);
						}
					}
					if ( 'spam' != $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='" . __( 'Mark this comment as spam' ) . "'>" . _c( 'Spam|verb' ) . '</a>';
					$actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
					$actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
					$actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\');return false;" class="vim-q" title="'.__('Quick Edit').'" href="#">' . __('Quick&nbsp;Edit') . '</a>';
					if ( 'spam' != $the_comment_status )
						$actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\');return false;" class="vim-r" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';

					$actions = apply_filters( 'comment_row_actions', $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) && ! $from_ajax )
							$action .= ' hide-if-no-js';

						echo "<span class='$action'>$sep$link</span>";
					}
					echo '</div>';
				}

				echo '</td>';
				break;
			case 'author':
				echo "<td $attributes><strong>"; comment_author(); echo '</strong><br />';
				if ( !empty($author_url) )
					echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />";
				if ( current_user_can( 'edit_post', $post->ID ) ) {
					if ( !empty($comment->comment_author_email) ) {
						comment_author_email_link();
						echo '<br />';
					}
					echo '<a href="edit-comments.php?s=';
					comment_author_IP();
					echo '&amp;mode=detail';
					if ( 'spam' == $comment_status )
						echo '&amp;comment_status=spam';
					echo '">';
					comment_author_IP();
					echo '</a>';
				} //current_user_can
				echo '</td>';
				break;
			case 'date':
				echo "<td $attributes>" . get_comment_date(__('Y/m/d \a\t g:ia')) . '</td>';
				break;
			case 'response':
				if ( 'single' !== $mode ) {
					if ( isset( $_comment_pending_count[$post->ID] ) ) {
						$pending_comments = absint( $_comment_pending_count[$post->ID] );
					} else {
						$_comment_pending_count_temp = (array) get_pending_comments_num( array( $post->ID ) );
						$pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp[$post->ID];
					}
					if ( current_user_can( 'edit_post', $post->ID ) ) {
						$post_link = "<a href='" . get_edit_post_link($post->ID) . "'>";
						$post_link .= get_the_title($post->ID) . '</a>';
					} else {
						$post_link = get_the_title($post->ID);
					}
					echo "<td $attributes>\n";
					echo $post_link;

					echo '<div class="response-links"><span class="post-com-count-wrapper">';
					$pending_phrase = sprintf( __('%s pending'), number_format( $pending_comments ) );
					if ( $pending_comments )
						echo '<strong>';
					comments_number("<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('0') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('1') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('%') . '</span></a>');
					if ( $pending_comments )
						echo '</strong>';
					echo '</span> ';
					echo "<a href='" . get_permalink( $post->ID ) . "'>#</a>";
					echo '</div></td>';
				}
		}
	}
	echo "</tr>\n";
}
コード例 #21
0
ファイル: akismet.php プロジェクト: GarryVeles/Artibaltika
function akismet_cron_recheck()
{
    global $wpdb;
    $status = akismet_verify_key(akismet_get_key());
    if (get_option('akismet_alert_code') || $status == 'invalid') {
        // since there is currently a problem with the key, reschedule a check for 6 hours hence
        wp_schedule_single_event(time() + 21600, 'akismet_schedule_cron_recheck');
        return false;
    }
    delete_option('akismet_available_servers');
    $comment_errors = $wpdb->get_col("\n\t\tSELECT comment_id\n\t\tFROM {$wpdb->prefix}commentmeta\n\t\tWHERE meta_key = 'akismet_error'\n\t\tLIMIT 100\n\t");
    foreach ((array) $comment_errors as $comment_id) {
        // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
        $comment = get_comment($comment_id);
        if (!$comment || strtotime($comment->comment_date_gmt) < strtotime("-15 days")) {
            delete_comment_meta($comment_id, 'akismet_error');
            continue;
        }
        add_comment_meta($comment_id, 'akismet_rechecking', true);
        $status = akismet_check_db_comment($comment_id, 'retry');
        $msg = '';
        if ($status == 'true') {
            $msg = __('Akismet caught this comment as spam during an automatic retry.');
        } elseif ($status == 'false') {
            $msg = __('Akismet cleared this comment during an automatic retry.');
        }
        // If we got back a legit response then update the comment history
        // other wise just bail now and try again later.  No point in
        // re-trying all the comments once we hit one failure.
        if (!empty($msg)) {
            delete_comment_meta($comment_id, 'akismet_error');
            akismet_update_comment_history($comment_id, $msg, 'cron-retry');
            update_comment_meta($comment_id, 'akismet_result', $status);
            // make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
            $comment = get_comment($comment_id);
            if ($comment && 'unapproved' == wp_get_comment_status($comment_id)) {
                if ($status == 'true') {
                    wp_spam_comment($comment_id);
                } elseif ($status == 'false') {
                    // comment is good, but it's still in the pending queue.  depending on the moderation settings
                    // we may need to change it to approved.
                    if (check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type)) {
                        wp_set_comment_status($comment_id, 1);
                    }
                }
            }
        } else {
            delete_comment_meta($comment_id, 'akismet_rechecking');
            wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
            return;
        }
        delete_comment_meta($comment_id, 'akismet_rechecking');
    }
    $remaining = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'");
    if ($remaining && !wp_next_scheduled('akismet_schedule_cron_recheck')) {
        wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
    }
}
コード例 #22
0
 >
  <?php 
            comment_date('Y-n-j');
            ?>
 
  @
  <?php 
            comment_time('g:m:s a');
            ?>
 
  <?php 
            if (current_user_can('edit_post', $post->ID)) {
                echo "[ <a href=\"post.php?action=editcomment&amp;comment=" . $comment->comment_ID . "\">" . __('Edit') . "</a>";
                echo ' - <a href="' . wp_nonce_url('post.php?action=deletecomment&amp;p=' . $post->ID . '&amp;comment=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return confirm(\'' . __("You are about to delete this comment.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete.") . "');\">" . __('Delete') . '</a> ';
                if ('none' != $comment_status && current_user_can('moderate_comments')) {
                    if ('approved' == wp_get_comment_status($comment->comment_ID)) {
                        echo ' - <a href="' . wp_nonce_url('post.php?action=unapprovecomment&amp;p=' . $post->ID . '&amp;comment=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '">' . __('Unapprove') . '</a> ';
                    } else {
                        echo ' - <a href="' . wp_nonce_url('post.php?action=approvecomment&amp;p=' . $post->ID . '&amp;comment=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '">' . __('Approve') . '</a> ';
                    }
                }
                echo "]";
            }
            // end if any comments to show
            ?>
 
  <br /> 
  <strong> 
  <?php 
            comment_author();
            ?>
コード例 #23
0
 public static function comment_row_action($a, $comment)
 {
     // failsafe for old WP versions
     if (!function_exists('add_comment_meta')) {
         return $a;
     }
     $akismet_result = get_comment_meta($comment->comment_ID, 'akismet_result', true);
     $akismet_error = get_comment_meta($comment->comment_ID, 'akismet_error', true);
     $user_result = get_comment_meta($comment->comment_ID, 'akismet_user_result', true);
     $comment_status = wp_get_comment_status($comment->comment_ID);
     $desc = null;
     if ($akismet_error) {
         $desc = __('Awaiting spam check', 'akismet');
     } elseif (!$user_result || $user_result == $akismet_result) {
         // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
         if ($akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash') {
             $desc = __('Flagged as spam by Akismet', 'akismet');
         } elseif ($akismet_result == 'false' && $comment_status == 'spam') {
             $desc = __('Cleared by Akismet', 'akismet');
         }
     } else {
         $who = get_comment_meta($comment->comment_ID, 'akismet_user', true);
         if ($user_result == 'true') {
             $desc = sprintf(__('Flagged as spam by %s', 'akismet'), $who);
         } else {
             $desc = sprintf(__('Un-spammed by %s', 'akismet'), $who);
         }
     }
     // add a History item to the hover links, just after Edit
     if ($akismet_result) {
         $b = array();
         foreach ($a as $k => $item) {
             $b[$k] = $item;
             if ($k == 'edit' || $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4) {
                 $b['history'] = '<a href="comment.php?action=editcomment&amp;c=' . $comment->comment_ID . '#akismet-status" title="' . esc_attr__('View comment history', 'akismet') . '"> ' . esc_html__('History', 'akismet') . '</a>';
             }
         }
         $a = $b;
     }
     if ($desc) {
         echo '<span class="akismet-status" commentid="' . $comment->comment_ID . '"><a href="comment.php?action=editcomment&amp;c=' . $comment->comment_ID . '#akismet-status" title="' . esc_attr__('View comment history', 'akismet') . '">' . esc_html($desc) . '</a></span>';
     }
     if (apply_filters('akismet_show_user_comments_approved', get_option('akismet_show_user_comments_approved'))) {
         $comment_count = Akismet::get_user_comments_approved($comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url);
         $comment_count = intval($comment_count);
         echo '<span class="akismet-user-comment-count" commentid="' . $comment->comment_ID . '" style="display:none;"><br><span class="akismet-user-comment-counts">' . sprintf(esc_html(_n('%s approved', '%s approved', $comment_count, 'akismet')), number_format_i18n($comment_count)) . '</span></span>';
     }
     return $a;
 }
コード例 #24
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 WordPress. 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 wp-config.php, for your environment.
 * See {@link http://core.trac.wordpress.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 wp_filter_comment() Used to filter comment before adding comment.
 * @uses wp_allow_comment() checks to see if comment is approved.
 * @uses wp_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 wp_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'] ? wp_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'] = isset($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 254) : '';
    $commentdata['comment_date'] = current_time('mysql');
    $commentdata['comment_date_gmt'] = current_time('mysql', 1);
    $commentdata = wp_filter_comment($commentdata);
    $commentdata['comment_approved'] = wp_allow_comment($commentdata);
    $comment_ID = wp_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']) {
            wp_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'])) {
            wp_notify_postauthor($comment_ID, isset($commentdata['comment_type']) ? $commentdata['comment_type'] : '');
        }
    }
    return $comment_ID;
}
コード例 #25
0
 /**
  * Generate and display row actions links.
  *
  * @since 4.3.0
  * @access protected
  *
  * @param object $comment     Comment being acted upon.
  * @param string $column_name Current column name.
  * @param string $primary     Primary column name.
  * @return string|void Comment row actions output.
  */
 protected function handle_row_actions($comment, $column_name, $primary)
 {
     global $comment_status;
     if ($primary !== $column_name) {
         return '';
     }
     if (!$this->user_can) {
         return;
     }
     $the_comment_status = wp_get_comment_status($comment);
     $out = '';
     $del_nonce = esc_html('_wpnonce=' . wp_create_nonce("delete-comment_{$comment->comment_ID}"));
     $approve_nonce = esc_html('_wpnonce=' . wp_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}");
     // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
     $actions = array('approve' => '', 'unapprove' => '', 'reply' => '', 'quickedit' => '', 'edit' => '', 'spam' => '', 'unspam' => '', 'trash' => '', 'untrash' => '', 'delete' => '');
     // Not looking at all comments.
     if ($comment_status && 'all' != $comment_status) {
         if ('approved' == $the_comment_status) {
             $actions['unapprove'] = "<a href='{$unapprove_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=unapproved' class='vim-u vim-destructive' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
         } elseif ('unapproved' == $the_comment_status) {
             $actions['approve'] = "<a href='{$approve_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=approved' class='vim-a vim-destructive' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
         }
     } else {
         $actions['approve'] = "<a href='{$approve_url}' data-wp-lists='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
         $actions['unapprove'] = "<a href='{$unapprove_url}' data-wp-lists='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
     }
     if ('spam' != $the_comment_status) {
         $actions['spam'] = "<a href='{$spam_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::spam=1' class='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}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1' class='vim-z vim-destructive'>" . _x('Not Spam', 'comment') . '</a>';
     }
     if ('trash' == $the_comment_status) {
         $actions['untrash'] = "<a href='{$untrash_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1' class='vim-z vim-destructive'>" . __('Restore') . '</a>';
     }
     if ('spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS) {
         $actions['delete'] = "<a href='{$delete_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::delete=1' class='delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
     } else {
         $actions['trash'] = "<a href='{$trash_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1' class='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>';
         $format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" title="%s" href="#">%s</a>';
         $actions['quickedit'] = sprintf($format, $comment->comment_ID, $comment->comment_post_ID, 'edit', 'vim-q comment-inline', esc_attr__('Edit this item inline'), __('Quick&nbsp;Edit'));
         $actions['reply'] = sprintf($format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__('Reply to this comment'), __('Reply'));
     }
     /** This filter is documented in wp-admin/includes/dashboard.php */
     $actions = apply_filters('comment_row_actions', array_filter($actions), $comment);
     $i = 0;
     $out .= '<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, '_wp_trash_meta_status', true)) {
                 $action .= ' approve';
             } else {
                 $action .= ' unapprove';
             }
         }
         $out .= "<span class='{$action}'>{$sep}{$link}</span>";
     }
     $out .= '</div>';
     $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details') . '</span></button>';
     return $out;
 }
コード例 #26
0
ファイル: template.php プロジェクト: 64kbytes/stayinba
function _wp_comment_list_item($id, $alt = 0)
{
    global $authordata, $comment, $wpdb;
    $id = (int) $id;
    $comment =& get_comment($id);
    $class = '';
    $post = get_post($comment->comment_post_ID);
    $authordata = get_userdata($post->post_author);
    $comment_status = wp_get_comment_status($comment->comment_ID);
    if ('unapproved' == $comment_status) {
        $class .= ' unapproved';
    }
    if ($alt % 2) {
        $class .= ' alternate';
    }
    echo "<li id='comment-{$comment->comment_ID}' class='{$class}'>";
    ?>
<p><strong><?php 
    comment_author();
    ?>
</strong> <?php 
    if ($comment->comment_author_email) {
        ?>
| <?php 
        comment_author_email_link();
        ?>
 <?php 
    }
    if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) {
        ?>
 | <?php 
        comment_author_url_link();
        ?>
 <?php 
    }
    ?>
| <?php 
    _e('IP:');
    ?>
 <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php 
    comment_author_IP();
    ?>
"><?php 
    comment_author_IP();
    ?>
</a></p>

<?php 
    comment_text();
    ?>

<p><?php 
    comment_date(__('M j, g:i A'));
    ?>
 &#8212; [
<?php 
    if (current_user_can('edit_post', $comment->comment_post_ID)) {
        echo " <a href='comment.php?action=editcomment&amp;c=" . $comment->comment_ID . "'>" . __('Edit') . '</a>';
        echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
        if ('none' != $comment_status && current_user_can('moderate_comments')) {
            echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
            echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
        }
        echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', {$comment->comment_ID}, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> ";
    }
    $post = get_post($comment->comment_post_ID, OBJECT, 'display');
    $post_title = wp_specialchars($post->post_title, 'double');
    $post_title = '' == $post_title ? "# {$comment->comment_post_ID}" : $post_title;
    ?>
 ] &#8212; <a href="<?php 
    echo get_permalink($comment->comment_post_ID);
    ?>
"><?php 
    echo $post_title;
    ?>
</a></p>
		</li>
<?php 
}
コード例 #27
0
ファイル: comment.php プロジェクト: voldemortensen/wp-cli
 /**
  * Get status of a comment.
  *
  * ## OPTIONS
  *
  * <id>
  * : The ID of the comment to check.
  *
  * ## EXAMPLES
  *
  *     $ wp comment status 1337
  *     approved
  */
 public function status($args, $assoc_args)
 {
     list($comment_id) = $args;
     $status = wp_get_comment_status($comment_id);
     if (false === $status) {
         WP_CLI::error("Could not check status of comment {$comment_id}.");
     } else {
         WP_CLI::line($status);
     }
 }
コード例 #28
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 WordPress. 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 wp-config.php, for your environment.
 * See {@link https://core.trac.wordpress.org/ticket/9235}
 *
 * @since 1.5.0
 * @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`.
 *
 * @see wp_insert_comment()
 *
 * @global wpdb $wpdb
 *
 * @param array $commentdata {
 *     Comment data.
 *
 *     @type string $comment_author       The name of the comment author.
 *     @type string $comment_author_email The comment author email address.
 *     @type string $comment_author_url   The comment author URL.
 *     @type string $comment_content      The content of the comment.
 *     @type string $comment_date         The date the comment was submitted. Default is the current time.
 *     @type string $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                        Default is `$comment_date` in the GMT timezone.
 *     @type int    $comment_parent       The ID of this comment's parent, if any. Default 0.
 *     @type int    $comment_post_ID      The ID of the post that relates to the comment.
 *     @type int    $user_id              The ID of the user who submitted the comment. Default 0.
 *     @type int    $user_ID              Kept for backward-compatibility. Use `$user_id` instead.
 *     @type string $comment_agent        Comment author user agent. Default is the value of 'HTTP_USER_AGENT'
 *                                        in the `$_SERVER` superglobal sent in the original request.
 *     @type string $comment_author_IP    Comment author IP address in IPv4 format. Default is the value of
 *                                        'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request.
 * }
 * @return int|false The ID of the comment on success, false on failure.
 */
function wp_new_comment($commentdata)
{
    global $wpdb;
    if (isset($commentdata['user_ID'])) {
        $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
    }
    $prefiltered_user_id = isset($commentdata['user_id']) ? (int) $commentdata['user_id'] : 0;
    /**
     * Filter a comment's data before it is sanitized and inserted into the database.
     *
     * @since 1.5.0
     *
     * @param array $commentdata Comment data.
     */
    $commentdata = apply_filters('preprocess_comment', $commentdata);
    $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
    if (isset($commentdata['user_ID']) && $prefiltered_user_id !== (int) $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'] ? wp_get_comment_status($commentdata['comment_parent']) : '';
    $commentdata['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $commentdata['comment_parent'] : 0;
    if (!isset($commentdata['comment_author_IP'])) {
        $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
    }
    $commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP']);
    if (!isset($commentdata['comment_agent'])) {
        $commentdata['comment_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    }
    $commentdata['comment_agent'] = substr($commentdata['comment_agent'], 0, 254);
    if (empty($commentdata['comment_date'])) {
        $commentdata['comment_date'] = current_time('mysql');
    }
    if (empty($commentdata['comment_date_gmt'])) {
        $commentdata['comment_date_gmt'] = current_time('mysql', 1);
    }
    $commentdata = wp_filter_comment($commentdata);
    $commentdata['comment_approved'] = wp_allow_comment($commentdata);
    $comment_ID = wp_insert_comment($commentdata);
    if (!$comment_ID) {
        $fields = array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_content');
        foreach ($fields as $field) {
            if (isset($commentdata[$field])) {
                $commentdata[$field] = $wpdb->strip_invalid_text_for_column($wpdb->comments, $field, $commentdata[$field]);
            }
        }
        $commentdata = wp_filter_comment($commentdata);
        $commentdata['comment_approved'] = wp_allow_comment($commentdata);
        $comment_ID = wp_insert_comment($commentdata);
        if (!$comment_ID) {
            return false;
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 1.2.0
     *
     * @param int $comment_ID       The comment ID.
     * @param int $comment_approved 1 (true) if the comment is approved, 0 (false) if not.
     */
    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']) {
            wp_notify_moderator($comment_ID);
        }
        // wp_notify_postauthor() checks if notifying the author of their own comment.
        // By default, it won't, but filters can override this.
        if (get_option('comments_notify') && $commentdata['comment_approved']) {
            wp_notify_postauthor($comment_ID);
        }
    }
    return $comment_ID;
}
コード例 #29
0
ファイル: ajax-actions.php プロジェクト: hughnet/WordPress
/**
 * Ajax handler to dim a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    if (!($comment = get_comment($id))) {
        $x = new WP_Ajax_Response(array('what' => 'comment', 'id' => new WP_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')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'))) {
        $result = wp_set_comment_status($comment, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment, 'hold', true);
    }
    if (is_wp_error($result)) {
        $x = new WP_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
    _wp_ajax_delete_comment_response($comment->comment_ID);
    wp_die(0);
}
コード例 #30
0
if (1 == count($posts)) {
    $comments = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = {$id} AND comment_approved != 'spam' ORDER BY comment_date");
    if ($comments) {
        ?>
<h3 id="comments"><?php 
        _e('Comments');
        ?>
</h3>
<ol id="the-comment-list" class="commentlist">
<?php 
        $i = 0;
        foreach ($comments as $comment) {
            ++$i;
            $class = '';
            $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM {$wpdb->posts} WHERE ID = {$comment->comment_post_ID}"));
            $comment_status = wp_get_comment_status($comment->comment_ID);
            if ('unapproved' == $comment_status) {
                $class .= ' unapproved';
            }
            if ($i % 2) {
                $class .= ' alternate';
            }
            echo "<li id='comment-{$comment->comment_ID}' class='{$class}'>";
            ?>
<p><strong><?php 
            comment_author();
            ?>
</strong> <?php 
            if ($comment->comment_author_email) {
                ?>
| <?php