/** * wp.getPageStatusList * wp.getPostStatusList * * @see http://codex.wordpress.org/XML-RPC_wp#wp.getPageStatusList * * @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_getpagestatuslist($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(); } $status_list = array(); if ($current_User->check_perm('blog_post!published', 'edit', false, $Blog->ID)) { $status_list[wp_or_b2evo_item_status('published', 'wp')] = new xmlrpcval(T_('Published')); } if ($current_User->check_perm('blog_post!protected', 'edit', false, $Blog->ID)) { // Not supported by WP, maps to 'private' $status_list[wp_or_b2evo_item_status('protected', 'wp')] = new xmlrpcval(T_('Protected')); } if ($current_User->check_perm('blog_post!private', 'edit', false, $Blog->ID)) { $status_list[wp_or_b2evo_item_status('private', 'wp')] = new xmlrpcval(T_('Private')); } if ($current_User->check_perm('blog_post!draft', 'edit', false, $Blog->ID)) { $status_list[wp_or_b2evo_item_status('draft', 'wp')] = new xmlrpcval(T_('Draft')); } if ($current_User->check_perm('blog_post!deprecated', 'edit', false, $Blog->ID)) { $status_list[wp_or_b2evo_item_status('deprecated', 'wp')] = new xmlrpcval(T_('Deprecated')); } if ($current_User->check_perm('blog_post!redirected', 'edit', false, $Blog->ID)) { // Not supported by WP, maps to 'published' $status_list[wp_or_b2evo_item_status('redirected', 'wp')] = new xmlrpcval(T_('Redirected')); } return new xmlrpcresp(new xmlrpcval($status_list, 'struct')); }
/** * Used in these methods * - metaweblog.getPost * - metaWeblog.getRecentPosts * - wp.getPages * - wp.getPage * * Note: a valid Item object must be supplied * */ function _wp_mw_get_item_struct(&$Item) { global $DB; logIO('Item title: ' . $Item->title); if (is_null($Item->extra_cat_IDs)) { // Load extra cats $Item->extra_cat_IDs = postcats_get_byID($Item->ID); } $cat_ids = $Item->extra_cat_IDs; array_unshift($cat_ids, $Item->main_cat_ID); // Move to top $cat_ids = array_unique($cat_ids); $SQL = 'SELECT cat_name FROM T_categories WHERE cat_ID IN (' . $DB->quote($cat_ids) . ')'; $cat_names = array(); if ($categories = $DB->get_col($SQL)) { foreach ($categories as $cat) { $cat_names[] = new xmlrpcval($cat); } logIO('Categories: ' . implode(', ', $categories)); } $tag_names_string = ''; if ($tags = $Item->get_tags()) { $tag_names_string = implode(', ', $tags); logIO('Tags: ' . $tag_names_string); } $SQL = 'SELECT * FROM T_items__item_settings WHERE iset_item_ID = ' . $DB->quote($Item->ID); $item_settings = array(); if ($settings = $DB->get_results($SQL)) { foreach ($settings as $setting) { $item_settings[] = new xmlrpcval(array('id' => new xmlrpcval(0), 'key' => new xmlrpcval($setting->iset_name), 'value' => new xmlrpcval($setting->iset_value)), 'struct'); } } // Split item content on before and after <!--more--> // No tag balancing, no pages, no rendering, just raw text $content_parts = explode('<!--more-->', $Item->content, 2); if (!isset($content_parts[1])) { $content_parts[1] = ''; } $parent_title = ''; if (isset($Item->parent_ID)) { $ItemCache =& get_ItemCache(); if ($parent_Item =& $ItemCache->get_by_ID($Item->parent_ID, false, false)) { } $parent_title = $parent_Item->title; } $item_status = wp_or_b2evo_item_status($Item->status, 'wp'); $url = $Item->get_permanent_url(); $data = array('page_id' => new xmlrpcval($Item->ID, 'int'), 'postid' => new xmlrpcval($Item->ID, 'int'), 'userid' => new xmlrpcval($Item->creator_user_ID, 'int'), 'page_status' => new xmlrpcval($item_status), 'post_status' => new xmlrpcval($item_status), 'description' => new xmlrpcval($content_parts[0]), 'text_more' => new xmlrpcval($content_parts[1]), 'title' => new xmlrpcval($Item->title), 'link' => new xmlrpcval($url), 'permalink' => new xmlrpcval($url), 'permaLink' => new xmlrpcval($url), 'categories' => new xmlrpcval($cat_names, 'array'), 'excerpt' => new xmlrpcval($Item->excerpt), 'mt_excerpt' => new xmlrpcval($Item->excerpt), 'mt_allow_comments' => new xmlrpcval($Item->can_comment(NULL) ? 1 : 0, 'int'), 'mt_text_more' => new xmlrpcval($content_parts[1]), 'mt_keywords' => new xmlrpcval($tag_names_string), 'wp_slug' => new xmlrpcval($Item->urltitle), 'wp_author' => new xmlrpcval($Item->get('t_author')), 'wp_page_parent_id' => new xmlrpcval(isset($Item->parent_ID) ? $Item->parent_ID : 0, 'int'), 'wp_page_parent_title' => new xmlrpcval($parent_title), 'wp_page_order' => new xmlrpcval($Item->order), 'wp_author_id' => new xmlrpcval($Item->creator_user_ID, 'string'), 'wp_author_display_name' => new xmlrpcval($Item->get('t_author')), 'wp_post_format' => new xmlrpcval($Item->ptyp_ID), 'date_created_gmt' => new xmlrpcval(datetime_to_iso8601($Item->issue_date, true), 'dateTime.iso8601'), 'dateCreated' => new xmlrpcval(datetime_to_iso8601($Item->issue_date), 'dateTime.iso8601'), 'custom_fields' => new xmlrpcval($item_settings, 'array'), 'wp_page_template' => new xmlrpcval('default'), 'mt_allow_pings' => new xmlrpcval(0, 'int'), 'wp_password' => new xmlrpcval('')); return $data; }
/** * 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 ..."); } } */ }