Make WordPress Core


Ignore:
Timestamp:
08/04/2008 10:29:37 PM (18 years ago)
Author:
ryan
Message:

XML-RPC comments API. see #7446

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r8091 r8543  
    44 *
    55 * @package WordPress
     6 * @subpackage Comment
    67 */
    78
     
    163164
    164165/**
    165  * Retrieve an array of comment data about comment $comment_ID.
    166  *
    167  * get_comment() technically does the same thing as this function. This function
    168  * also appears to reference variables and then not use them or not update them
    169  * when needed. It is advised to switch to get_comment(), since this function
    170  * might be deprecated in favor of using get_comment().
    171  *
    172  * @deprecated Use get_comment()
    173  * @see get_comment()
    174  * @since 0.71
    175  *
    176  * @uses $postc Comment cache, might not be used any more
    177  * @uses $id
    178  * @uses $wpdb Database Object
    179  *
    180  * @param int $comment_ID The ID of the comment
    181  * @param int $no_cache Whether to use the cache or not (casted to bool)
    182  * @param bool $include_unapproved Whether to include unapproved comments or not
    183  * @return array The comment data
    184  */
    185 function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) {
    186     global $postc, $wpdb;
    187     if ( $no_cache ) {
    188         $query = $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID = %d", $comment_ID);
    189         if ( false == $include_unapproved )
    190             $query .= " AND comment_approved = '1'";
    191         $myrow = $wpdb->get_row($query, ARRAY_A);
     166 * Retrieve a list of comments
     167 *
     168 * {@internal Missing Long Description}}
     169 *
     170 * @package WordPress
     171 * @subpackage Comment
     172 * @since 2.7
     173 * @uses $wpdb
     174 *
     175 * @param mixed $args Optional. Array or string of options
     176 * @return array List of comments matching defaults or $args
     177 */
     178function get_comments( $args = '' ) {
     179    global $wpdb;
     180
     181    $defaults = array('status' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0);
     182
     183    $r = wp_parse_args( $args, $defaults );
     184    extract( $r, EXTR_SKIP );
     185
     186    $post_id = absint($post_id);
     187
     188    if ( 'hold' == $status )
     189        $approved = "comment_approved = '0'";
     190    elseif ( 'approve' == $status )
     191        $approved = "comment_approved = '1'";
     192    elseif ( 'spam' == $status )
     193        $approved = "comment_approved = 'spam'";
     194    else
     195        $approved = "( comment_approved = '0' OR comment_approved = '1' )";
     196
     197    if ( 'ASC' != $order )
     198        $order = 'DESC';
     199
     200    $orderby = 'comment_date_gmt';  // Hard code for now
     201
     202    $number = absint($number);
     203    $offset = absint($offset);
     204
     205    if ( !empty($number) ) {
     206        if ( $offset )
     207            $number = 'LIMIT ' . $offset . ',' . $number;
     208        else
     209            $number = 'LIMIT ' . $number;
     210
    192211    } else {
    193         $myrow['comment_ID']           = $postc->comment_ID;
    194         $myrow['comment_post_ID']      = $postc->comment_post_ID;
    195         $myrow['comment_author']       = $postc->comment_author;
    196         $myrow['comment_author_email'] = $postc->comment_author_email;
    197         $myrow['comment_author_url']   = $postc->comment_author_url;
    198         $myrow['comment_author_IP']    = $postc->comment_author_IP;
    199         $myrow['comment_date']         = $postc->comment_date;
    200         $myrow['comment_content']      = $postc->comment_content;
    201         $myrow['comment_karma']        = $postc->comment_karma;
    202         $myrow['comment_approved']     = $postc->comment_approved;
    203         $myrow['comment_type']         = $postc->comment_type;
    204     }
    205     return $myrow;
    206 }
     212        $number = '';
     213    }
     214
     215    if ( ! empty($post_id) )
     216        $post_where = "comment_post_ID = $post_id AND";
     217    else
     218        $post_where = '';
     219
     220    return $wpdb->get_results( "SELECT * FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $post_where $approved ORDER BY $orderby $order $number" );
     221}
     222
     223/**
     224 * Retrieve all of the WordPress supported comment statuses.
     225 *
     226 * Comments have a limited set of valid status values, this provides the
     227 * comment status values and descriptions.
     228 *
     229 * @package WordPress
     230 * @subpackage Post
     231 * @since 2.7
     232 *
     233 * @return array List of comment statuses.
     234 */
     235function get_comment_statuses( ) {
     236    $status = array(
     237        'hold'      => __('Unapproved'),
     238        'approve'   => __('Approved'),
     239        'spam'      => __('Spam'),
     240    );
     241
     242    return $status;
     243}
     244
    207245
    208246/**
     
    822860
    823861    $comment_date_gmt = get_gmt_from_date($comment_date);
     862
     863    if ( empty($comment_approved) )
     864        $comment_approved = 1;
     865    else if ( 'hold' == $comment_approved )
     866        $comment_approved = 0;
     867    else if ( 'approve' == $comment_approved )
     868        $comment_approved = 1;
    824869
    825870    $wpdb->query( $wpdb->prepare("UPDATE $wpdb->comments SET
Note: See TracChangeset for help on using the changeset viewer.