/** * Helper for {@link b2_getcategories()} and {@link mt_getPostCategories()}, because they differ * only in the "categoryId" case ("categoryId" (b2) vs "categoryID" (MT)) * * @param string Type, either "b2" or "mt" * @param xmlrpcmsg XML-RPC Message * 0 blogid (string): Unique identifier of the blog to query * 1 username (string): Login for a Blogger user who is member of the blog. * 2 password (string): Password for said username. * @return xmlrpcresp XML-RPC Response */ function _b2_or_mt_get_categories($type, $m) { global $xmlrpcerruser, $DB; // 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(); } // CHECK PERMISSION: (we need at least one post/edit status) if (!$current_User->check_perm('blog_post_statuses', 1, false, $Blog->ID)) { // Permission denied return xmlrpcs_resperror(3); // User error 3 } logIO('Permission granted.'); $sql = 'SELECT * FROM T_categories '; $BlogCache =& get_Cache('BlogCache'); $current_Blog = $BlogCache->get_by_ID($Blog->ID); $aggregate_coll_IDs = $current_Blog->get_setting('aggregate_coll_IDs'); if (empty($aggregate_coll_IDs)) { // We only want posts from the current blog: $sql .= 'WHERE cat_blog_ID =' . $current_Blog->ID; } else { // We are aggregating posts from several blogs: $sql .= 'WHERE cat_blog_ID IN (' . $aggregate_coll_IDs . ')'; } $sql .= " ORDER BY cat_name ASC"; $rows = $DB->get_results($sql); if ($DB->error) { // DB error return new xmlrpcresp(0, $xmlrpcerruser + 9, 'DB error: ' . $DB->last_error); // user error 9 } xmlrpc_debugmsg('Categories:' . count($rows)); $categoryIdName = $type == 'b2' ? 'categoryID' : 'categoryId'; $data = array(); foreach ($rows as $row) { $data[] = new xmlrpcval(array($categoryIdName => new xmlrpcval($row->cat_ID), 'categoryName' => new xmlrpcval($row->cat_name)), 'struct'); } logIO('OK.'); return new xmlrpcresp(new xmlrpcval($data, "array")); }
/** * metaWeblog.getCategories * * @see http://www.xmlrpc.com/metaWeblogApi#metawebloggetcategories * * @param xmlrpcmsg XML-RPC Message * 0 blogid (string): Unique identifier of the blog the post will be added to. * 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. * @param array of params to narrow category selection */ function _wp_mw_getcategories($m, $params = array()) { global $DB, $Settings; // 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(); } $SQL = new SQL(); $SQL->SELECT('cat_ID, cat_name, cat_order'); $SQL->FROM('T_categories'); $SQL->WHERE($Blog->get_sql_where_aggregate_coll_IDs('cat_blog_ID')); if (!empty($params['search'])) { // Category name starts with 'search' $SQL->WHERE_and('cat_name LIKE "' . $DB->like_escape($params['search']) . '%"'); } if ($Settings->get('chapter_ordering') == 'manual') { // Manual order $SQL->ORDER_BY('cat_order'); } else { // Alphabetic order $SQL->ORDER_BY('cat_name'); } $rows = $DB->get_results($SQL->get()); if ($DB->error) { // DB error return xmlrpcs_resperror(99, 'DB error: ' . $DB->last_error); // user error 9 } $total_rows = count($rows); logIO('Categories: ' . $total_rows); $ChapterCache =& get_ChapterCache(); $data = array(); for ($i = 0; $i < $total_rows; $i++) { if (!empty($params['limit']) && $i >= $params['limit']) { // We found enough, exit the loop break; } $Chapter =& $ChapterCache->get_by_ID($rows[$i]->cat_ID, false, false); if (!$Chapter) { continue; } if (isset($params['search'])) { // wp.suggestCategories $data[] = new xmlrpcval(array('category_id' => new xmlrpcval(intval($Chapter->ID)), 'category_name' => new xmlrpcval($Chapter->name)), 'struct'); } else { $data[] = new xmlrpcval(array('categoryId' => new xmlrpcval(intval($Chapter->ID)), 'parentId' => new xmlrpcval(intval($Chapter->parent_ID)), 'description' => new xmlrpcval($Chapter->name), 'categoryDescription' => new xmlrpcval($Chapter->description), 'categoryName' => new xmlrpcval($Chapter->name), 'htmlUrl' => new xmlrpcval($Chapter->get_permanent_url()), 'rssUrl' => new xmlrpcval(url_add_param($Chapter->get_permanent_url(), 'tempskin=_rss2'))), 'struct'); } } logIO('OK.'); return new xmlrpcresp(new xmlrpcval($data, 'array')); }
/** * blogger.getRecentPosts retieves X most recent posts. * * This API call is not documented on * {@link http://www.blogger.com/developers/api/1_docs/} * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggergetrecentposts.html * * @param xmlrpcmsg XML-RPC Message * 0 appkey (string): Unique identifier/passcode of the application sending the post. * (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .) * 1 blogid (string): Unique identifier of the blog the post will be added to. * Currently ignored in b2evo, in favor of the category. * 2 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). * 3 password (string): Password for said username. * 4 numposts (integer): number of posts to retrieve. * @return xmlrpcresp XML-RPC Response */ function blogger_getrecentposts($m) { global $xmlrpcerruser, $DB; // CHECK LOGIN: /** * @var User */ if (!($current_User =& xmlrpcs_login($m, 2, 3))) { // Login failed, return (last) error: return xmlrpcs_resperror(); } // GET BLOG: /** * @var Blog */ if (!($Blog =& xmlrpcs_get_Blog($m, 1))) { // Login failed, return (last) error: return xmlrpcs_resperror(); } $numposts = $m->getParam(4); $numposts = $numposts->scalarval(); // Get the posts to display: load_class('items/model/_itemlist.class.php', 'ItemList'); $MainList = new ItemList2($Blog, NULL, NULL, $numposts); // Protected and private get checked by statuses_where_clause(). $statuses = array('published', 'redirected', 'protected', 'private'); if ($current_User->check_perm('blog_ismember', 'view', false, $Blog->ID)) { // These statuses require member status: $statuses = array_merge($statuses, array('draft', 'deprecated')); } logIO('Statuses: ' . implode(', ', $statuses)); $MainList->set_filters(array('visibility_array' => $statuses, 'order' => 'DESC', 'unit' => 'posts')); // Run the query: $MainList->query(); logIO('Items:' . $MainList->result_num_rows); $data = array(); while ($Item =& $MainList->get_item()) { logIO('Item:' . $Item->title . ' - Issued: ' . $Item->issue_date . ' - Modified: ' . $Item->datemodified); $post_date = mysql2date('U', $Item->issue_date); $post_date = gmdate('Ymd', $post_date) . 'T' . gmdate('H:i:s', $post_date); $content = '<title>' . $Item->title . '</title>'; $content .= '<category>' . $Item->main_cat_ID . '</category>'; $content .= $Item->content; // Load Item's creator User: $Item->get_creator_User(); $authorname = $Item->creator_User->get('preferredname'); $data[] = new xmlrpcval(array('authorName' => new xmlrpcval($authorname), 'userid' => new xmlrpcval($Item->creator_user_ID), 'dateCreated' => new xmlrpcval($post_date, 'dateTime.iso8601'), 'content' => new xmlrpcval($content), 'postid' => new xmlrpcval($Item->ID)), 'struct'); } $resp = new xmlrpcval($data, 'array'); logIO('OK.'); return new xmlrpcresp($resp); }
/** * wp.getOptions * * @see http://codex.wordpress.org/XML-RPC_wp#wp.getOptions * * Note: If passing in a struct, search for options listed within it. * * @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 options (struct) */ function wp_getoptions($m) { global $Settings; // 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(); } if (isset($m->params[3])) { $options = $m->getParam(3); $options = xmlrpc_decode_recurse($options); } $defaults = array('software_name' => array('desc' => 'Software Name', 'value' => 'WordPress'), 'software_version' => array('desc' => 'Software Version', 'value' => '3.3.2'), 'blog_url' => array('desc' => 'Site URL', 'value' => $Blog->gen_blogurl()), 'blog_title' => array('desc' => 'Site TitleL', 'value' => $Blog->get('name')), 'blog_tagline' => array('desc' => 'Site Tagline', 'value' => $Blog->get('tagline')), 'date_format' => array('desc' => 'Date Format', 'value' => locale_datefmt()), 'time_format' => array('desc' => 'Time Format', 'value' => locale_timefmt()), 'users_can_register' => array('desc' => 'Allow new users to sign up', 'value' => $Settings->get('newusers_canregister')), 'thumbnail_crop' => array('desc' => 'Crop thumbnail to exact dimensions', 'value' => false), 'thumbnail_size_w' => array('desc' => 'Thumbnail Width', 'value' => '160'), 'thumbnail_size_h' => array('desc' => 'Thumbnail Height', 'value' => '160'), 'medium_size_w' => array('desc' => 'Medium size image width', 'value' => '320'), 'medium_size_h' => array('desc' => 'Medium size image height', 'value' => '320'), 'large_size_w' => array('desc' => 'Large size image width', 'value' => '720'), 'large_size_h' => array('desc' => 'Large size image height', 'value' => '500')); $data = array(); if (empty($options)) { // No specific options where asked for, return all of them foreach ($defaults as $k => $opt) { $data[$k] = new xmlrpcval(array('desc' => new xmlrpcval($opt['desc']), 'readonly' => new xmlrpcval(true, 'boolean'), 'value' => new xmlrpcval($opt['value'])), 'struct'); } logIO('Retrieving all options'); } else { foreach ($options as $k) { if (!isset($defaults[$k])) { continue; } $data[$k] = new xmlrpcval(array('desc' => new xmlrpcval($defaults[$k]['desc']), 'readonly' => new xmlrpcval(true, 'boolean'), 'value' => new xmlrpcval($defaults[$k]['value'])), 'struct'); logIO('Retrieving option: ' . $k); } } logIO('OK.'); return new xmlrpcresp(new xmlrpcval($data, 'struct')); }
/** * metaWeblog.getRecentPosts * * @see http://xmlrpc.scripting.com/metaWeblogApi.html#metawebloggetrecentposts * * @param xmlrpcmsg XML-RPC Message * 0 blogid (string): Unique identifier of the blog the post will be added to. * 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 numposts (integer): number of posts to retrieve. */ function mw_getrecentposts($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(); } $limit = $m->getParam(3); $limit = abs($limit->scalarval()); $items = xmlrpc_get_items(array('limit' => $limit), $Blog); if (empty($items)) { return new xmlrpcresp(new xmlrpcval(array(), 'array')); } $data = array(); foreach ($items as $item) { $data[] = new xmlrpcval($item, 'struct'); } logIO('OK.'); return new xmlrpcresp(new xmlrpcval($data, 'array')); }
/** * metaWeblog.getRecentPosts * * @see http://www.xmlrpc.com/metaWeblogApi#metawebloggetrecentposts * * @param xmlrpcmsg XML-RPC Message * 0 blogid (string): Unique identifier of the blog the post will be added to. * 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. */ function mw_getrecentposts($m) { global $xmlrpcerruser, $DB; // 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(); } // CHECK PERMISSION: (we need at least one post/edit status) if (!$current_User->check_perm('blog_post_statuses', 1, false, $Blog->ID)) { // Permission denied return xmlrpcs_resperror(3); // User error 3 } logIO('Permission granted.'); $numposts = $m->getParam(3); $numposts = $numposts->scalarval(); logIO("In mw_getrecentposts, current numposts is ..." . $numposts); // Get the posts to display: load_class('items/model/_itemlist.class.php'); $MainList =& new ItemList2($Blog, NULL, NULL, $numposts); $MainList->set_filters(array('visibility_array' => array('published', 'protected', 'private', 'draft', 'deprecated', 'redirected'), 'order' => 'DESC', 'unit' => 'posts')); // Run the query: $MainList->query(); xmlrpc_debugmsg('Items:' . $MainList->result_num_rows); $data = array(); /** * @var Item */ while ($Item =& $MainList->get_item()) { xmlrpc_debugmsg('Item:' . $Item->title . ' - Issued: ' . $Item->issue_date . ' - Modified: ' . $Item->mod_date); $post_date = mysql2date("U", $Item->issue_date); $post_date = gmdate("Ymd", $post_date) . "T" . gmdate("H:i:s", $post_date); $content = $Item->content; $content = str_replace("\n", '', $content); // Tor - kludge to fix bug in xmlrpc libraries // Load Item's creator User: $Item->get_creator_User(); $authorname = $Item->creator_User->get('preferredname'); // need a loop here to extract all categoy names // $extra_cat_IDs is the variable for the rest of the IDs $hope_cat_name = get_the_category_by_ID($Item->main_cat_ID); $test = $Item->extra_cat_IDs[0]; xmlrpc_debugmsg('postcats:' . $hope_cat_name["cat_name"]); xmlrpc_debugmsg('test:' . $test); $data[] = new xmlrpcval(array("dateCreated" => new xmlrpcval($post_date, "dateTime.iso8601"), "userid" => new xmlrpcval($Item->creator_user_ID), "postid" => new xmlrpcval($Item->ID), "categories" => new xmlrpcval(array(new xmlrpcval($hope_cat_name["cat_name"])), 'array'), "title" => new xmlrpcval($Item->title), "description" => new xmlrpcval($content), "link" => new xmlrpcval($Item->url), 'publish' => new xmlrpcval($Item->status == 'published', 'boolean')), "struct"); } $resp = new xmlrpcval($data, "array"); logIO('OK.'); return new xmlrpcresp($resp); }
/** * blogger.getRecentPosts retieves X most recent posts. * * This API call is not documented on * {@link http://www.blogger.com/developers/api/1_docs/} * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggergetrecentposts.html * * @param xmlrpcmsg XML-RPC Message * 0 appkey (string): Unique identifier/passcode of the application sending the post. * (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .) * 1 blogid (string): Unique identifier of the blog the post will be added to. * Currently ignored in b2evo, in favor of the category. * 2 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). * 3 password (string): Password for said username. * 4 numposts (integer): number of posts to retrieve. * @return xmlrpcresp XML-RPC Response */ function blogger_getrecentposts($m) { global $xmlrpcerruser, $DB; // CHECK LOGIN: /** * @var User */ if (!($current_User =& xmlrpcs_login($m, 2, 3))) { // Login failed, return (last) error: return xmlrpcs_resperror(); } // GET BLOG: /** * @var Blog */ if (!($Blog =& xmlrpcs_get_Blog($m, 1))) { // Login failed, return (last) error: return xmlrpcs_resperror(); } // CHECK PERMISSION: (we need at least one post/edit status) // (we should be able to see all even if we cannot edit the particular status of a post) if (!$current_User->check_perm('blog_post_statuses', 1, false, $Blog->ID)) { // Permission denied return xmlrpcs_resperror(3); // User error 3 } logIO('Permission granted.'); $numposts = $m->getParam(4); $numposts = $numposts->scalarval(); // Get the posts to display: load_class('items/model/_itemlist.class.php'); $MainList =& new ItemList2($Blog, NULL, NULL, $numposts); $MainList->set_filters(array('visibility_array' => array('published', 'protected', 'private', 'draft', 'deprecated', 'redirected'), 'order' => 'DESC', 'unit' => 'posts')); // Run the query: $MainList->query(); xmlrpc_debugmsg('Items:' . $MainList->result_num_rows); $data = array(); while ($Item =& $MainList->get_item()) { xmlrpc_debugmsg('Item:' . $Item->title . ' - Issued: ' . $Item->issue_date . ' - Modified: ' . $Item->mod_date); $post_date = mysql2date("U", $Item->issue_date); $post_date = gmdate("Ymd", $post_date) . "T" . gmdate("H:i:s", $post_date); $content = '<title>' . $Item->title . '</title>'; $content .= '<category>' . $Item->main_cat_ID . '</category>'; $content .= $Item->content; // Load Item's creator User: $Item->get_creator_User(); $authorname = $Item->creator_User->get('preferredname'); $data[] = new xmlrpcval(array("authorName" => new xmlrpcval($authorname), "userid" => new xmlrpcval($Item->creator_user_ID), "dateCreated" => new xmlrpcval($post_date, "dateTime.iso8601"), "content" => new xmlrpcval($content), "postid" => new xmlrpcval($Item->ID)), "struct"); } $resp = new xmlrpcval($data, "array"); logIO('OK.'); return new xmlrpcresp($resp); }