Example #1
0
/**
 * Deletes given Item
 *
 * @return xmlrpcresp XML-RPC Response (bool)
 */
function xmlrpcs_delete_item(&$edited_Item)
{
    global $current_User, $DB;
    // CHECK PERMISSION:
    if (!$current_User->check_perm('item_post!CURSTATUS', 'delete', false, $edited_Item)) {
        // Permission denied
        return xmlrpcs_resperror(3);
        // User error 3
    }
    logIO('Permission granted.');
    // DELETE POST FROM DB:
    $edited_Item->dbdelete();
    if ($DB->error) {
        return xmlrpcs_resperror(99, 'DB error: ' . $DB->last_error);
        // user error 9
    }
    logIO('OK.');
    return new xmlrpcresp(new xmlrpcval(1, 'boolean'));
}
Example #2
0
/**
 * mt.publishPost
 *
 * @see http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtpublishpost.html
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 postid (string): Unique identifier of the post to publish
 *					1 username (string): Login for a user who is member of the blog.
 *					2 password (string): Password for said username.
 */
function mt_publishPost($m)
{
    global $localtimenow, $DB;
    // CHECK LOGIN:
    /**
     * @var User
     */
    if (!($current_User =& xmlrpcs_login($m, 1, 2))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    logIO('mt_publishPost: Login OK');
    // GET POST:
    /**
     * @var Item
     */
    if (!($edited_Item =& xmlrpcs_get_Item($m, 0))) {
        // Failed, return (last) error:
        return xmlrpcs_resperror();
    }
    if (!$current_User->check_perm('item_post!published', 'edit', false, $edited_Item)) {
        return xmlrpcs_resperror(3);
        // Permission denied
    }
    logIO('mt_publishPost: Permission granted');
    logIO('mt_publishPost: Old post status: ' . $edited_Item->status);
    $edited_Item->set('status', 'published');
    //$edited_Item->set( 'datestart', date('Y-m-d H:i:s', $localtimenow) );
    if ($edited_Item->dbupdate() === false) {
        // Could not update item...
        return xmlrpcs_resperror(99, 'Database error: ' . $DB->last_error);
        // DB error
    }
    logIO('mt_publishPost: Item published.');
    // Execute or schedule notifications & pings:
    logIO('mt_publishPost: Handling notifications...');
    $edited_Item->handle_post_processing(false, false);
    logIO('mt_publishPost: OK.');
    return new xmlrpcresp(new xmlrpcval(1, 'boolean'));
}
Example #3
0
/**
 * 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);
}
Example #4
0
/**
 * Edit an Item and return an XML-RPC response
 *
 * @param Item
 * @param string HTML
 * @param string HTML
 * @param string date
 * @param integer main category
 * @param array of integers : extra categories
 * @param string status
 * @return xmlrpcmsg
 */
function xmlrpcs_edit_item(&$edited_Item, $post_title, $content, $post_date, $main_cat, $cat_IDs, $status)
{
    /**
     * @var User
     */
    global $current_User;
    global $Messages;
    global $DB;
    // CHECK HTML SANITY:
    if (($post_title = check_html_sanity($post_title, 'xmlrpc_posting')) === false) {
        return xmlrpcs_resperror(21, $Messages->get_string('Invalid post title, please correct these errors:', ''));
    }
    if (($content = check_html_sanity($content, 'xmlrpc_posting')) === false) {
        return xmlrpcs_resperror(22, $Messages->get_string('Invalid post contents, please correct these errors:' . "\n", '', NULL, "  //  \n", 'xmlrpc'));
    }
    // UPDATE POST IN DB:
    $edited_Item->set('title', $post_title);
    $edited_Item->set('content', $content);
    $edited_Item->set('status', $status);
    if (!empty($post_date)) {
        $edited_Item->set('issue_date', $post_date);
    }
    if (!empty($main_cat)) {
        // Update cats:
        $edited_Item->set('main_cat_ID', $main_cat);
    }
    if (!empty($cat_IDs)) {
        // Extra-Cats:
        $edited_Item->set('extra_cat_IDs', $cat_IDs);
    }
    $edited_Item->dbupdate();
    if ($DB->error) {
        // DB error
        return xmlrpcs_resperror(99, 'Error while updating item: ' . $DB->last_error);
    }
    // Execute or schedule notifications & pings:
    logIO('Handling notifications...');
    $edited_Item->handle_post_processing();
    logIO('OK.');
    return new xmlrpcresp(new xmlrpcval(1, 'boolean'));
}
Example #5
0
/**
 * mt.getPostCategories : Get the categories for a given post.
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 postid (string): Unique identifier of the post to query
 *					1 username (string): Login for a Blogger user who is member of the blog.
 *					2 password (string): Password for said username.
 */
function mt_getPostCategories($m)
{
    global $xmlrpcerruser;
    global $DB;
    // 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();
    }
    // CHECK PERMISSION: (we need at least one post/edit status)
    if (!$current_User->check_perm('blog_post_statuses', 1, false, $edited_Item->blog_ID)) {
        // Permission denied
        return xmlrpcs_resperror(3);
        // User error 3
    }
    logIO('Permission granted.');
    $categories = postcats_get_byID($edited_Item->ID);
    // Secondary categories
    $iSize = count($categories);
    // The number of objects ie categories
    logIO("mt_getgategorylist  no of categories..." . $iSize);
    // works
    $struct = array();
    for ($i = 0; $i < $iSize; $i++) {
        logIO("mt_getPostCategories categories  ..." . $categories[$i]);
        // In database cat_ID and cat_name from tablecategories
        $sql = "SELECT * FROM T_categories WHERE  cat_ID = {$categories[$i]} ";
        logIO("mt_getgategorylist  sql..." . $sql);
        $rows = $DB->get_results($sql);
        foreach ($rows as $row) {
            $Categoryname = $row->cat_name;
            logIO("mt_getPostCategories Categoryname  ..." . $Categoryname);
        }
        // Is this the primary cat?
        $isPrimary = $categories[$i] == $edited_Item->main_cat_ID ? 1 : 0;
        $struct[$i] = new xmlrpcval(array("categoryId" => new xmlrpcval($categories[$i]), "categoryName" => new xmlrpcval($Categoryname), "isPrimary" => new xmlrpcval($isPrimary)), "struct");
    }
    logIO('OK.');
    return new xmlrpcresp(new xmlrpcval($struct, "array"));
}
Example #6
0
/**
 * 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'));
}
Example #7
0
/**
 * b2.getPostURL
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 ? NO LONGER USED (was: blogid (string): Unique identifier of the blog to query)
 *					1 ? (string)
 *					2 username (string): Login for a Blogger user who is member of the blog.
 *					3 password (string): Password for said username.193
 *
 *					4 post_ID (string): Post to query
 * @return xmlrpcresp XML-RPC Response
 */
function b2_getposturl($m)
{
    global $xmlrpcerruser;
    global $siteurl;
    // CHECK LOGIN:
    /**
     * @var User
     */
    if (!($current_User =& xmlrpcs_login($m, 2, 3))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    // GET POST:
    /**
     * @var Item
     */
    if (!($edited_Item =& xmlrpcs_get_Item($m, 4))) {
        // 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, $edited_Item->blog_ID)) {
        // Permission denied
        return xmlrpcs_resperror(3);
        // User error 3
    }
    logIO('Permission granted.');
    logIO('OK.');
    return new xmlrpcresp(new xmlrpcval($edited_Item->get_permanent_url()));
}
Example #8
0
/**
 * b2.getPostURL
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 ? NO LONGER USED (was: blogid (string): Unique identifier of the blog to query)
 *					1 ? (string)
 *					2 username (string): Login for a Blogger user who is member of the blog.
 *					3 password (string): Password for said username.193
 *
 *					4 post_ID (string): Post to query
 * @return xmlrpcresp XML-RPC Response
 */
function b2_getposturl($m)
{
    // CHECK LOGIN:
    /**
     * @var User
     */
    if (!($current_User =& xmlrpcs_login($m, 2, 3))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    // GET POST:
    /**
     * @var Item
     */
    if (!($edited_Item =& xmlrpcs_get_Item($m, 4))) {
        // Failed, return (last) error:
        return xmlrpcs_resperror();
    }
    // CHECK PERMISSION: (user needs to be able to view the item)
    if (!xmlrpcs_can_view_item($edited_Item, $User)) {
        // Permission denied
        return xmlrpcs_resperror(3);
        // User error 3
    }
    logIO('OK.');
    return new xmlrpcresp(new xmlrpcval($edited_Item->get_permanent_url()));
}
Example #9
0
/**
 * metaWeblog.deletePost deletes a given post.
 *
 * This API call is not documented on
 * {@link http://www.blogger.com/developers/api/1_docs/}
 * @see http://www.xmlrpc.com/stories/storyReader$2460
 *
 * @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 postid (string): Unique identifier of the post to be deleted.
 *					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.
 * @return xmlrpcresp XML-RPC Response
 */
function mw_deletepost($m)
{
    // CHECK LOGIN:
    if (!($current_User =& xmlrpcs_login($m, 2, 3))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    // GET POST:
    /**
     * @var Item
     */
    if (!($edited_Item =& xmlrpcs_get_Item($m, 1))) {
        // Failed, return (last) error:
        return xmlrpcs_resperror();
    }
    return xmlrpcs_delete_item($edited_Item);
}
Example #10
0
/**
 * metaweblog.getPost retieves a given post.
 *
 * @see http://www.xmlrpc.com/metaWeblogApi#basicEntrypoints
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 postid (string): Unique identifier of the post
 *					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.
 * @return xmlrpcresp XML-RPC Response
 */
function mw_getpost($m)
{
    global $xmlrpcerruser;
    // 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();
    }
    // CHECK PERMISSION: (we need at least one post/edit status)
    if (!$current_User->check_perm('blog_post_statuses', 1, false, $edited_Item->blog_ID)) {
        // Permission denied
        return xmlrpcs_resperror(3);
        // User error 3
    }
    logIO('Permission granted.');
    $post_date = mysql2date("U", $edited_Item->issue_date);
    $post_date = gmdate("Ymd", $post_date) . "T" . gmdate("H:i:s", $post_date);
    $struct = new xmlrpcval(array('link' => new xmlrpcval($edited_Item->get_permanent_url()), 'title' => new xmlrpcval($edited_Item->title), 'description' => new xmlrpcval($edited_Item->content), 'dateCreated' => new xmlrpcval($post_date, "dateTime.iso8601"), 'userid' => new xmlrpcval($edited_Item->creator_user_ID), 'postid' => new xmlrpcval($edited_Item->ID), 'content' => new xmlrpcval($edited_Item->content), 'permalink' => new xmlrpcval($edited_Item->get_permanent_url()), 'categories' => new xmlrpcval($edited_Item->main_cat_ID)), "struct");
    $resp = $struct;
    logIO('OK.');
    return new xmlrpcresp($resp);
}
Example #11
0
/**
 * 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);
}