/** * metaWeblog.editPost * * @see http://www.xmlrpc.com/metaWeblogApi#basicEntrypoints * * @param xmlrpcmsg XML-RPC Message * 0 postid (string): Unique identifier of the post to edit * 1 username (string): Login for a Blogger user who has permission to edit the given * post (either the user who originally created it or an admin of the blog). * 2 password (string): Password for said username. * 3 struct (struct) * 4 publish (bool) * @param string item type 'post' or 'page' */ function mw_editpost($m, $item_type = 'post') { // CHECK LOGIN: /** * @var User */ if (!($current_User =& xmlrpcs_login($m, 1, 2))) { // Login failed, return (last) error: return xmlrpcs_resperror(); } // GET POST: /** * @var Item */ if (!($edited_Item =& xmlrpcs_get_Item($m, 0))) { // Failed, return (last) error: return xmlrpcs_resperror(); } // We need to be able to edit this post: if (!$current_User->check_perm('item_post!CURSTATUS', 'edit', false, $edited_Item)) { return xmlrpcs_resperror(3); // Permission denied } $xcontent = $m->getParam(3); $contentstruct = xmlrpc_decode_recurse($xcontent); logIO('Decoded xcontent'); if (isset($m->params[4])) { // getParam(4) is a flag for publish or draft $xstatus = $m->getParam(4); $xstatus = $xstatus->scalarval(); $status = $xstatus ? 'published' : 'draft'; // might be overrided later } $cat_IDs = _mw_get_cat_IDs($contentstruct, $edited_Item->get_Blog(), true); $date = _mw_decode_date($contentstruct); if (!empty($contentstruct['post_type']) && $contentstruct['post_type'] != $item_type) { // Overwrite from struct $item_type = $contentstruct['post_type']; } // Don't overwrite if not set $tags = isset($contentstruct['mt_keywords']) ? $contentstruct['mt_keywords'] : NULL; $content = isset($contentstruct['description']) ? $contentstruct['description'] : NULL; $excerpt = isset($contentstruct['mt_excerpt']) ? $contentstruct['mt_excerpt'] : NULL; $urltitle = isset($contentstruct['wp_slug']) ? $contentstruct['wp_slug'] : NULL; $parent_ID = isset($contentstruct['wp_page_parent_id']) ? $contentstruct['wp_page_parent_id'] : NULL; $author_ID = isset($contentstruct['wp_author_id']) ? $contentstruct['wp_author_id'] : NULL; $featured = isset($contentstruct['sticky']) ? $contentstruct['sticky'] : NULL; $order = isset($contentstruct['wp_page_order']) ? $contentstruct['wp_page_order'] : NULL; $custom_fields = isset($contentstruct['custom_fields']) ? $contentstruct['custom_fields'] : NULL; $item_typ_ID = isset($contentstruct['wp_post_format']) ? $contentstruct['wp_post_format'] : NULL; if (isset($contentstruct[$item_type . '_status'])) { $status = wp_or_b2evo_item_status($contentstruct[$item_type . '_status'], 'b2evo'); } if (isset($content_struct['mt_text_more'])) { // Add content extension $content .= '<!--more-->' . $content_struct['mt_text_more']; } //logIO( "Item content:\n".$content ); if (!empty($content_struct['enclosure']) && is_array($content_struct['enclosure'])) { // Add content extension $enclosure = $content_struct['enclosure']; if (isset($enclosure['url']) && isset($enclosure['length']) && isset($enclosure['type'])) { logIO("Item enclosure\n" . var_export($enclosure, true)); // TODO: sam2kb> Handle enclosures } } $comment_status = ''; // Don't overwrite if not set if (isset($contentstruct['mt_allow_comments'])) { if (!$contentstruct['mt_allow_comments'] || in_array($contentstruct['mt_allow_comments'], array(2, 'closed'))) { // Comments disabled $comment_status = 'disabled'; } else { $comment_status = 'open'; } } $params = array('title' => $contentstruct['title'], 'content' => $content, 'cat_IDs' => $cat_IDs, 'status' => $status, 'date' => $date, 'tags' => $tags, 'excerpt' => $excerpt, 'item_typ_ID' => $item_typ_ID, 'comment_status' => $comment_status, 'urltitle' => $urltitle, 'parent_ID' => $parent_ID, 'author_ID' => $author_ID, 'featured' => $featured, 'order' => $order, 'custom_fields' => $custom_fields); // COMPLETE VALIDATION & INSERT: return xmlrpcs_edit_item($edited_Item, $params); /* // Time to perform trackbacks NB NOT WORKING YET // // NB Requires a change to the _trackback library // // function trackbacks( $post_trackbacks, $content, $post_title, $post_ID ) // first extract these from posting as post_trackbacks array, then rest is easy // <member> // <name>mt_tb_ping_urls</name> // <value><array><data> // <value><string>http://archive.scripting.com/2005/04/17</string></value> // </data></array></value> // </member> // First check that trackbacks are allowed - mt_allow_pings $trackback_ok = 0; $trackbacks = array(); $trackback_ok = $contentstruct['mt_allow_pings']; logIO("Trackback OK ...".$trackback_ok); if ($trackback_ok == 1) { $trackbacks = $contentstruct['mt_tb_ping_urls']; logIO("Trackback url 0 ...".$trackbacks[0]); $no_of_trackbacks = count($trackbacks); logIO("Number of Trackbacks ...".$no_of_trackbacks); if ($no_of_trackbacks > 0) { logIO("Calling Trackbacks ..."); load_funcs('comments/_trackback.funcs.php'); $result = trackbacks( $trackbacks, $content, $post_title, $post_ID ); logIO("Returned from Trackbacks ..."); } } */ }
/** * metaWeblog.editPost (metaWeblog.editPost) * * @see http://www.xmlrpc.com/metaWeblogApi#basicEntrypoints * * @todo Tor - TODO * - Sort out sql select with blog ID * - screws up posts with multiple categories * partly due to the fact that Movable Type calls to this API are different to Metaweblog API calls when handling categories. * * @param xmlrpcmsg XML-RPC Message * 0 postid (string): Unique identifier of the post to edit * Currently ignored in b2evo, in favor of the category. * 1 username (string): Login for a Blogger user who has permission to edit the given * post (either the user who originally created it or an admin of the blog). * 2 password (string): Password for said username. * 3 struct (struct) */ function mw_editpost($m) { global $xmlrpcerruser; // import user errcode value global $DB; global $Settings; global $Messages; // CHECK LOGIN: /** * @var User */ if (!($current_User =& xmlrpcs_login($m, 1, 2))) { // Login failed, return (last) error: return xmlrpcs_resperror(); } // GET POST: /** * @var Item */ if (!($edited_Item =& xmlrpcs_get_Item($m, 0))) { // Failed, return (last) error: return xmlrpcs_resperror(); } $xstatus = $m->getParam(4); $xstatus = $xstatus->scalarval(); $status = $xstatus ? 'published' : 'draft'; logIO("Publish: {$xstatus} -> Status: {$status}"); $xcontent = $m->getParam(3); $contentstruct = xmlrpc_decode_recurse($xcontent); logIO("Decoded xcontent"); // Categories: $cat_IDs = _mw_get_cat_IDs($contentstruct, $edited_Item->blog_ID, true); if (!is_array($cat_IDs)) { // error: return $cat_IDs; } if (empty($cat_IDs)) { // TODO: make this finer // CHECK PERMISSION: (we need perm on current status) if (!$current_User->check_perm('blog_post!' . $status, 'edit', false, $edited_Item->blog_ID)) { // Permission denied return xmlrpcs_resperror(3); // User error 3 } $main_cat = NULL; } else { // CHECK PERMISSION: (we need perm on all categories, especially if they are in different blogs) if (!$current_User->check_perm('cats_post!' . $status, 'edit', false, $cat_IDs)) { // Permission denied return xmlrpcs_resperror(3); // User error 3 } $main_cat = $cat_IDs[0]; } logIO('Permission granted.'); $post_date = _mw_decode_postdate($contentstruct, false); $post_title = $contentstruct['title']; $content = $contentstruct['description']; // COMPLETE VALIDATION & UPDATE: return xmlrpcs_edit_item($edited_Item, $post_title, $content, $post_date, $main_cat, $cat_IDs, $status); /* // Time to perform trackbacks NB NOT WORKING YET // // NB Requires a change to the _trackback library // // function trackbacks( $post_trackbacks, $content, $post_title, $post_ID ) // first extract these from posting as post_trackbacks array, then rest is easy // <member> // <name>mt_tb_ping_urls</name> // <value><array><data> // <value><string>http://archive.scripting.com/2005/04/17</string></value> // </data></array></value> // </member> // First check that trackbacks are allowed - mt_allow_pings $trackback_ok = 0; $trackbacks = array(); $trackback_ok = $contentstruct['mt_allow_pings']; logIO("Trackback OK ...".$trackback_ok); if ($trackback_ok == 1) { $trackbacks = $contentstruct['mt_tb_ping_urls']; logIO("Trackback url 0 ...".$trackbacks[0]); $no_of_trackbacks = count($trackbacks); logIO("Number of Trackbacks ...".$no_of_trackbacks); if ($no_of_trackbacks > 0) { logIO("Calling Trackbacks ..."); load_funcs('comments/_trackback.funcs.php'); $result = trackbacks( $trackbacks, $content, $post_title, $post_ID ); logIO("Returned from Trackbacks ..."); } } */ }