/** * Update a comment with values provided in $_POST. * * @since 2.0.0 */ function edit_comment() { if (!current_user_can('edit_comment', (int) $_POST['comment_ID'])) { nxt_die(__('You are not allowed to edit comments on this post.')); } $_POST['comment_author'] = $_POST['newcomment_author']; $_POST['comment_author_email'] = $_POST['newcomment_author_email']; $_POST['comment_author_url'] = $_POST['newcomment_author_url']; $_POST['comment_approved'] = $_POST['comment_status']; $_POST['comment_content'] = $_POST['content']; $_POST['comment_ID'] = (int) $_POST['comment_ID']; foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) { if (!empty($_POST['hidden_' . $timeunit]) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit]) { $_POST['edit_date'] = '1'; break; } } if (!empty($_POST['edit_date'])) { $aa = $_POST['aa']; $mm = $_POST['mm']; $jj = $_POST['jj']; $hh = $_POST['hh']; $mn = $_POST['mn']; $ss = $_POST['ss']; $jj = $jj > 31 ? 31 : $jj; $hh = $hh > 23 ? $hh - 24 : $hh; $mn = $mn > 59 ? $mn - 60 : $mn; $ss = $ss > 59 ? $ss - 60 : $ss; $_POST['comment_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}"; } nxt_update_comment($_POST); }
/** * Automatically approve any comments left by a classmate. * * @param int $id the database ID of the comment * @param object $comment the saved comment object * * @access private * @since 0.1 */ public function _approve_classmate_comments($id, $comment) { if (!$comment->comment_approved) { if ($comment->user_id || get_user_by('email', $comment->comment_author_email)) { $comment->comment_approved = 1; nxt_update_comment((array) $comment); } } }
/** * Edit comment. * * Besides the common blog_id, username, and password arguments, it takes a * comment_id integer and a content_struct array as last argument. * * The allowed keys in the content_struct array are: * - 'author' * - 'author_url' * - 'author_email' * - 'content' * - 'date_created_gmt' * - 'status'. Common statuses are 'approve', 'hold', 'spam'. See {@link get_comment_statuses()} for more details * * @since 2.7.0 * * @param array $args. Contains: * - blog_id * - username * - password * - comment_id * - content_struct * @return bool True, on success. */ function nxt_editComment($args) { $this->escape($args); $blog_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; $comment_ID = (int) $args[3]; $content_struct = $args[4]; if (!($user = $this->login($username, $password))) { return $this->error; } if (!current_user_can('moderate_comments')) { return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); } if (!get_comment($comment_ID)) { return new IXR_Error(404, __('Invalid comment ID.')); } if (!current_user_can('edit_comment', $comment_ID)) { return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); } do_action('xmlrpc_call', 'nxt.editComment'); if (isset($content_struct['status'])) { $statuses = get_comment_statuses(); $statuses = array_keys($statuses); if (!in_array($content_struct['status'], $statuses)) { return new IXR_Error(401, __('Invalid comment status.')); } $comment_approved = $content_struct['status']; } // Do some timestamp voodoo if (!empty($content_struct['date_created_gmt'])) { $dateCreated = str_replace('Z', '', $content_struct['date_created_gmt']->getIso()) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); $comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); } if (isset($content_struct['content'])) { $comment_content = $content_struct['content']; } if (isset($content_struct['author'])) { $comment_author = $content_struct['author']; } if (isset($content_struct['author_url'])) { $comment_author_url = $content_struct['author_url']; } if (isset($content_struct['author_email'])) { $comment_author_email = $content_struct['author_email']; } // We've got all the data -- post it: $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url'); $result = nxt_update_comment($comment); if (is_nxt_error($result)) { return new IXR_Error(500, $result->get_error_message()); } if (!$result) { return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.')); } return true; }