/** * 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; }
/** * wp.editComment * * @see http://codex.wordpress.org/XML-RPC_wp#wp.editComment * * Leave the second and third parameter blank to send anonymous comments * * @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. * 3 comment_id (int): Target post ID * 4 params (struct): * - status (string) * - date_created_gmt (string) * - content (string) * - author (string) * - author_url (string) * - author_email (string) */ function wp_editcomment($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))) { // Blog not found return xmlrpcs_resperror(); } /** * @var Comment */ if (!($edited_Comment =& xmlrpcs_get_Comment($m, 3))) { // Return (last) error: return xmlrpcs_resperror(); } if (!$current_User->check_perm('comment!CURSTATUS', 'edit', false, $edited_Comment)) { // Permission denied return xmlrpcs_resperror(3); } $options = $m->getParam(4); $options = xmlrpc_decode_recurse($options); //logIO( 'Params: '.var_export($options, true) ); $params = array('status' => wp_or_b2evo_comment_status($options['status'], 'b2evo'), 'date' => _mw_decode_date($options), 'content' => $options['content'], 'author' => isset($options['author']) ? $options['author'] : '', 'author_url' => isset($options['author_url']) ? $options['author_url'] : '', 'author_email' => isset($options['author_email']) ? $options['author_email'] : ''); return xmlrpcs_edit_comment($params, $edited_Comment); }