function mw_editPost($args) { global $wpdb, $post_default_category; $this->escape($args); $post_ID = $args[0]; $user_login = $args[1]; $user_pass = $args[2]; $content_struct = $args[3]; $publish = $args[4]; if (!$this->login_pass_ok($user_login, $user_pass)) { return $this->error; } $user_data = get_userdatabylogin($user_login); if (!user_can_edit_post($user_data->ID, $post_ID)) { return new IXR_Error(401, 'Sorry, you can not edit this post.'); } $postdata = wp_get_single_post($post_ID, ARRAY_A); extract($postdata); $this->escape($postdata); $post_title = $content_struct['title']; $post_content = apply_filters( 'content_save_pre', $content_struct['description'] ); $catnames = $content_struct['categories']; $post_category = array(); if (is_array($catnames)) { foreach ($catnames as $cat) { $post_category[] = get_cat_ID($cat); } } else if ( !empty($catnames) ) { $post_category = array(get_cat_ID($catnames)); } $post_excerpt = $content_struct['mt_excerpt']; $post_more = $content_struct['mt_text_more']; $post_status = $publish ? 'publish' : 'draft'; if ($post_more) { $post_content = $post_content . "\n<!--more-->\n" . $post_more; } $to_ping = $content_struct['mt_tb_ping_urls']; $comment_status = (empty($content_struct['mt_allow_comments'])) ? get_settings('default_comment_status') : $content_struct['mt_allow_comments']; $ping_status = (empty($content_struct['mt_allow_pings'])) ? get_settings('default_ping_status') : $content_struct['mt_allow_pings']; // Do some timestamp voodoo $dateCreatedd = $content_struct['dateCreated']; if (!empty($dateCreatedd)) { $dateCreated = $dateCreatedd->getIso(); $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); $post_date_gmt = iso8601_to_datetime($dateCreated, GMT); } else { $post_date = $postdata['post_date']; $post_date_gmt = $postdata['post_date_gmt']; } // We've got all the data -- post it: $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping'); $result = wp_update_post($newpost); if (!$result) { return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.'); } logIO('O',"(MW) Edited ! ID: $post_ID"); // FIXME: do we pingback always? pingback($content, $post_ID); trackback_url_list($content_struct['mt_tb_ping_urls'], $post_ID); return true; }
function mweditpost($params) { // ($postid, $user, $pass, $content, $publish) global $xmlrpcerruser; $xpostid = $params->getParam(0); $xuser = $params->getParam(1); $xpass = $params->getParam(2); $xcontent = $params->getParam(3); $xpublish = $params->getParam(4); $ID = $xpostid->scalarval(); $username = $xuser->scalarval(); $password = $xpass->scalarval(); $contentstruct = xmlrpc_decode1($xcontent); $postdata = wp_get_single_post($ID); if (!$postdata) { return new xmlrpcresp(0, $xmlrpcerruser + 2, "No such post {$ID}."); } $userdata = get_userdatabylogin($username); $user_ID = $userdata->ID; $user_level = $userdata->user_level; $post_author_ID = $postdata->post_author; $post_authordata = get_userdata($post_author_ID); if ($user_ID != $post_author_ID && $user_level <= $post_authordata->user_level) { return new xmlrpcresp(0, $xmlrpcerruser + 1, "Sorry, you do not have the right to edit this post."); } // Check login if (user_pass_ok($username, $password)) { if ($user_level < 1) { return new xmlrpcresp(0, $xmlrpcerruser + 1, "Sorry, level 0 users cannot edit posts"); } extract($postdata); $post_title = $contentstruct['title']; $post_content = format_to_post($contentstruct['description']); $catnames = $contentstruct['categories']; logIO("O", "Cat Count" . count($catnames)); foreach ($catnames as $cat) { $post_category[] = get_cat_ID($cat); } $post_excerpt = $contentstruct['mt_excerpt']; $post_more = $contentstruct['mt_text_more']; $post_status = $xpublish->scalarval() ? 'publish' : 'draft'; if ($post_more) { $post_content = $post_content . "\n<!--more-->\n" . $post_more; } $comment_status = 1 == $contentstruct['mt_allow_comments'] ? 'open' : 'closed'; $ping_status = $contentstruct['mt_allow_pings'] ? 'open' : 'closed'; $time_difference = get_settings("time_difference"); $dateCreated = $contentstruct['dateCreated']; $dateCreated = $dateCreated ? iso8601_decode($contentstruct['dateCreated']) : time() + $time_difference * 3600; $post_date = date("Y-m-d H:i:s", $dateCreated); // We've got all the data -- post it: $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date'); $newpost_ID = wp_update_post($newpost); if (!$newpost_ID) { return new xmlrpcresp(0, $xmlrpcerruser + 2, "For some strange yet very annoying reason, your entry could not be posted."); } if (!isset($blog_ID)) { $blog_ID = 1; } if (isset($sleep_after_edit) && $sleep_after_edit > 0) { sleep($sleep_after_edit); } pingWeblogs($blog_ID); pingCafelog($cafelogID, $post_title, $post_ID); pingBlogs($blog_ID); pingback($content, $post_ID); trackback_url_list($content_struct['mt_tb_ping_urls'], $post_ID); logIO("O", "(MW) Edited ! ID: {$post_ID}"); $myResp = new xmlrpcval($ID, "string"); return new xmlrpcresp($myResp); } else { logIO("O", "(MW) Wrong username/password combination <b>{$username} / {$password}</b>"); return new xmlrpcresp(0, $xmlrpcerruser + 3, 'Wrong username/password combination ' . $username . ' / ' . starify($password)); } }
function mweditpost($params) { // ($postid, $user, $pass, $content, $publish) $xpostid = $params->getParam(0); $xuser = $params->getParam(1); $xpass = $params->getParam(2); $xcontent = $params->getParam(3); $xpublish = $params->getParam(4); $ID = intval($xpostid->scalarval()); $username = $xuser->scalarval(); $password = $xpass->scalarval(); $contentstruct = php_xmlrpc_decode($xcontent); $postarr['post_status'] = $xpublish->scalarval() ? 'publish' : 'draft'; // Check login if (user_pass_ok($username, $password)) { $postdata = wp_get_single_post($ID, ARRAY_A); if (!$postdata) { return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 2, "No such post '{$ID}'."); } $userdata = get_userdatabylogin($username); if ($userdata->user_level < 1) { return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 1, 'Sorry, level 0 users can not edit posts'); } if ($userdata->ID != $postdata['post_author'] && $userdata->user_level != 10) { $authordata = get_userdata($postdata['post_author']); if ($userdata->user_level <= $authordata->user_level) { return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 1, 'Sorry, you do not have the right to edit this post'); } } $postarr['ID'] = $ID; if (array_key_exists('title', $contentstruct)) { $postarr['post_title'] = $contentstruct['title']; logIO('O', $contentstruct['title']); } if (array_key_exists('description', $contentstruct)) { $postarr['post_content'] = format_to_post($contentstruct['description']); logIO('O', $contentstruct['description']); } if (array_key_exists('mt_excerpt', $contentstruct)) { $postarr['post_excerpt'] = $contentstruct['mt_excerpt']; } if (array_key_exists('mt_text_more', $contentstruct)) { if (trim(format_to_post($contentstruct['mt_text_more']))) { $postarr['post_content'] .= "\n<!--more-->\n" . format_to_post($contentstruct['mt_text_more']); } } if (array_key_exists('mt_allow_comments', $contentstruct)) { $postarr['comment_status'] = $contentstruct['mt_allow_comments'] ? 'open' : 'closed'; } if (array_key_exists('mt_allow_pings', $contentstruct)) { $postarr['ping_status'] = $contentstruct['mt_allow_pings'] ? 'open' : 'closed'; } if (!empty($contentstruct['dateCreated'])) { $dateCreated = preg_split('/([+\\-Z])/', $contentstruct['dateCreated'], -1, PREG_SPLIT_DELIM_CAPTURE); if (count($dateCreated) == 3) { $dateCreated[2] = str_replace(':', '', $dateCreated[2]); } if ($dateCreated[1] == '+') { $dateoffset = intval($dateCreated[2]) * 36; } else { if ($dateCreated[1] == '-') { $dateoffset = -intval($dateCreated[2]) * 36; } else { $dateoffset = 0; } } $dateCreated = iso8601_decode($dateCreated[0], 1) - $dateoffset + get_settings('time_difference') * 3600; } else { $dateCreated = current_time('timestamp', 0); } $postarr['post_date'] = date('Y-m-d H:i:s', $dateCreated); $postarr['post_category'] = array(); if (array_key_exists('categories', $contentstruct) && is_array($contentstruct['categories'])) { foreach ($contentstruct['categories'] as $cat) { $postarr['post_category'][] = get_cat_ID(mb_conv($cat), 'EUC-JP', 'auto'); } } else { $postarr['post_category'][] = $GLOBALS['post_default_category']; } $post_ID = wp_update_post($postarr); if (!$post_ID) { return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 2, 'For some strange yet very annoying reason, your entry could not be posted.'); } if (empty($GLOBALS['blog_ID'])) { $GLOBALS['blog_ID'] = 1; } pingWeblogs($GLOBALS['blog_ID']); pingback($postarr['post_content'], $post_ID); if (array_key_exists('mt_tb_ping_urls', $contentstruct)) { trackback_url_list($content_struct['mt_tb_ping_urls'], $post_ID); } logIO('O', "(MW) Edited ! ID: {$post_ID}"); $myResp = new xmlrpcval(true, 'boolean'); return new xmlrpcresp($myResp); } else { logIO('O', "(MW) Wrong username/password combination <b>{$username} / {$password}</b>"); return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 3, 'Wrong username/password combination ' . $username . ' / ' . starify($password)); } }