Esempio n. 1
0
/**
 * Get array of latest comments
 *
 * @param array of params
 *			- Blog (object)
 *			- User (object)
 *			- limit (int) the number of comments to return
 *			- comment_ID (int) return specified comment or NULL to return all available
 *			- item_ID (int) return comments for specified item only
 * @return xmlrpcmsg
 */
function xmlrpc_get_comments($params, &$Blog)
{
    global $DB, $current_User;
    $params = array_merge(array('limit' => 0, 'comment_ID' => 0, 'item_ID' => 0, 'statuses' => '', 'types' => array('comment', 'trackback', 'pingback')), $params);
    $params['comment_ID'] = abs(intval($params['comment_ID']));
    $params['item_ID'] = abs(intval($params['item_ID']));
    if (empty($params['statuses'])) {
        // Return all except 'trash'
        $params['statuses'] = array('published', 'deprecated', 'draft');
    }
    if (!empty($params['comment_ID'])) {
        logIO('Getting comment #' . $params['comment_ID']);
        $filters = array('comment_ID' => $params['comment_ID'], 'types' => $params['types'], 'statuses' => $params['statuses']);
    } elseif (!empty($params['item_ID'])) {
        logIO('Getting comments to item #' . $params['item_ID']);
        $ItemCache =& get_ItemCache();
        $Item =& $ItemCache->get_by_ID($params['item_ID'], false, false);
        if (empty($Item)) {
            // Item not found
            return xmlrpcs_resperror(5, 'Requested post/Item (' . $params['item_ID'] . ') does not exist.');
        }
        if (!$Item->can_see_comments()) {
            // Cannot see comments
            return xmlrpcs_resperror(5, 'You are not allowed to view comments for this post/Item (' . $params['item_ID'] . ').');
        }
        $filters = array('post_ID' => $Item->ID, 'types' => $params['types'], 'statuses' => $params['statuses'], 'comments' => $params['limit'], 'order' => 'DESC');
    } else {
        logIO(sprintf('Trying to get latest comments (%s)', $params['limit'] ? $params['limit'] : 'all'));
        $filters = array('types' => $params['types'], 'statuses' => $params['statuses'], 'comments' => $params['limit'], 'order' => 'DESC');
    }
    //logIO( "Filters:\n".var_export($filters, true) );
    $CommentList = new CommentList2($Blog);
    // Filter list:
    $CommentList->set_filters($filters, false);
    // Get ready for display (runs the query):
    $CommentList->display_init();
    logIO('Comments found: ' . $CommentList->result_num_rows);
    $data = array();
    if ($CommentList->result_num_rows) {
        while ($Comment =& $CommentList->get_next()) {
            // Loop through comments:
            $Comment->get_Item();
            $data[] = array('dateCreated' => new xmlrpcval(datetime_to_iso8601($Comment->date, true), 'dateTime.iso8601'), 'date_created_gmt' => new xmlrpcval(datetime_to_iso8601($Comment->date, true), 'dateTime.iso8601'), 'user_id' => new xmlrpcval(intval($Comment->author_user_ID)), 'comment_id' => new xmlrpcval($Comment->ID), 'parent' => new xmlrpcval(intval($Comment->in_reply_to_cmt_ID)), 'status' => new xmlrpcval(wp_or_b2evo_comment_status($Comment->status, 'wp')), 'content' => new xmlrpcval($Comment->content), 'link' => new xmlrpcval($Comment->get_permanent_url()), 'post_id' => new xmlrpcval($Comment->Item->ID), 'post_title' => new xmlrpcval($Comment->Item->title), 'author' => new xmlrpcval($Comment->get_author_name()), 'author_url' => new xmlrpcval($Comment->get_author_url()), 'author_email' => new xmlrpcval($Comment->get_author_email()), 'author_ip' => new xmlrpcval($Comment->author_IP), 'type' => new xmlrpcval($Comment->type == 'comment' ? '' : $Comment->type));
        }
    }
    return $data;
}
Esempio n. 2
0
/**
 * wp.getPageList
 *
 * @see http://codex.wordpress.org/XML-RPC_wp#wp.getPageList
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 blogid (int): Unique identifier of the blog.
 *					1 username (string): User login.
 *					2 password (string): Password for said username.
 */
function wp_getpagelist($m)
{
    // CHECK LOGIN:
    /**
     * @var User
     */
    if (!($current_User =& xmlrpcs_login($m, 1, 2))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    // GET BLOG:
    /**
     * @var Blog
     */
    if (!($Blog =& xmlrpcs_get_Blog($m, 0))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    // Get the pages to display:
    load_class('items/model/_itemlistlight.class.php', 'ItemListLight');
    $MainList = new ItemListLight($Blog, NULL, NULL, 0);
    // Protected and private get checked by statuses_where_clause().
    $statuses = array('published', 'redirected', 'protected', 'private');
    if ($current_User->check_perm('blog_ismember', 'view', false, $Blog->ID)) {
        // These statuses require member status:
        $statuses = array_merge($statuses, array('draft', 'deprecated'));
    }
    logIO('Statuses: ' . implode(', ', $statuses));
    $MainList->set_filters(array('visibility_array' => $statuses, 'order' => 'DESC', 'unit' => 'posts', 'types' => '1000'));
    // Run the query:
    $MainList->query();
    logIO('Items:' . $MainList->result_num_rows);
    $data = array();
    while ($Item =& $MainList->get_item()) {
        logIO('Item:' . $Item->title . ' - Issued: ' . $Item->issue_date . ' - Modified: ' . $Item->datemodified);
        $data[] = new xmlrpcval(array('page_id' => new xmlrpcval($Item->ID, 'int'), 'page_title' => new xmlrpcval($Item->title), 'page_parent_id' => new xmlrpcval(isset($Item->parent_ID) ? $Item->parent_ID : 0, 'int'), 'dateCreated' => new xmlrpcval(datetime_to_iso8601($Item->issue_date), 'dateTime.iso8601'), 'date_created_gmt' => new xmlrpcval(datetime_to_iso8601($Item->issue_date, true), 'dateTime.iso8601')), 'struct');
    }
    logIO('OK.');
    return new xmlrpcresp(new xmlrpcval($data, 'array'));
}