コード例 #1
0
ファイル: _blogger.api.php プロジェクト: Ariflaw/b2evolution
/**
 * blogger.newPost makes a new post to a designated blog.
 *
 * Optionally, will publish the blog after making the post. (In b2evo, this means the
 * new post will be in 'published' state).
 * On success, it returns the unique ID of the new post (usually a seven-digit number
 * at this time).
 * On error, it will return some error message.
 *
 * @see http://www.blogger.com/developers/api/1_docs/xmlrpc_newPost.html
 * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggernewpost.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 post to the blog.
 *					3 password (string): Password for said username.
 *					4 content (string): Contents of the post.
 *					5 publish (boolean): If true, the blog will be published immediately after the
 *						post is made. (In b2evo,this means, the new post will be in 'published' state,
 *						otherwise it would be in draft state).
 * @return xmlrpcresp XML-RPC Response
 */
function blogger_newpost($m)
{
    global $Settings;
    // 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();
    }
    $content = $m->getParam(4);
    $content = $content->scalarval();
    $publish = $m->getParam(5);
    $publish = $publish->scalarval();
    $status = $publish ? 'published' : 'draft';
    logIO("Publish: {$publish} -> Status: {$status}");
    $title = xmlrpc_getposttitle($content);
    $cat_IDs = xmlrpc_getpostcategories($content);
    // Cleanup content from extra tags like <category> and <title>:
    $content = xmlrpc_removepostdata($content);
    $params = array('title' => $title, 'content' => $content, 'cat_IDs' => $cat_IDs, 'status' => $status);
    // COMPLETE VALIDATION & INSERT:
    return xmlrpcs_new_item($params, $Blog);
}
コード例 #2
0
ファイル: _b2.api.php プロジェクト: LFSF/oras
/**
 * b2.newPost. Adds a post, blogger-api like, +title +category +postdate.
 *
 * b2 API
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 ?
 *					1 ?
 *					2 username (string): Login for a Blogger user who is member of the blog.
 *					3 password (string): Password for said username.
 *					4 content (string): The content of the post.
 *					5 publish (boolean): If set to true, the post will be published immediately.
 *					6 title (string): The title of the post.
 *					7 category (string): The internal name of the category you want to post the post into.
 *					8 date (string): This is the date that will be shown in the post, give "" for current date.
 * @return xmlrpcresp XML-RPC Response
 */
function b2_newpost($m)
{
    global $xmlrpcerruser;
    // import user errcode value
    global $DB;
    global $Settings, $Messages;
    // CHECK LOGIN:
    /**
     * @var User
     */
    if (!($current_User =& xmlrpcs_login($m, 2, 3))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    $publish = $m->getParam(5);
    $publish = $publish->scalarval();
    $status = $publish ? 'published' : 'draft';
    $main_cat = $m->getParam(7);
    $main_cat = $main_cat->scalarval();
    // 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, array($main_cat))) {
        // Permission denied
        return xmlrpcs_resperror(3);
        // User error 3
    }
    logIO('Permission granted.');
    // Check if category exists
    if (get_the_category_by_ID($main_cat, false) === false) {
        // Cat does not exist:
        return xmlrpcs_resperror(11);
        // User error 11
    }
    $cat_IDs = array($main_cat);
    $postdate = $m->getParam(8);
    $postdate = $postdate->scalarval();
    if ($postdate != '') {
        $post_date = $postdate;
    } else {
        $post_date = date('Y-m-d H:i:s', time() + $Settings->get('time_difference'));
    }
    $post_title = $m->getParam(6);
    $post_title = $post_title->scalarval();
    $content = $m->getParam(4);
    $content = $content->scalarval();
    // COMPLETE VALIDATION & INSERT:
    return xmlrpcs_new_item($post_title, $content, $post_date, $main_cat, $cat_IDs, $status);
}
コード例 #3
0
ファイル: _b2.api.php プロジェクト: Ariflaw/b2evolution
/**
 * b2.newPost. Adds a post, blogger-api like, +title +category +postdate.
 *
 * b2 API
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 ?
 *					1 ?
 *					2 username (string): Login for a Blogger user who is member of the blog.
 *					3 password (string): Password for said username.
 *					4 content (string): The content of the post.
 *					5 publish (boolean): If set to true, the post will be published immediately.
 *					6 title (string): The title of the post.
 *					7 category (string): The internal name of the category you want to post the post into.
 *					8 date (string): This is the date that will be shown in the post, give "" for current date.
 * @return xmlrpcresp XML-RPC Response
 */
function b2_newpost($m)
{
    // CHECK LOGIN:
    /**
     * @var User
     */
    if (!($current_User =& xmlrpcs_login($m, 2, 3))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    $publish = $m->getParam(5);
    $publish = $publish->scalarval();
    $status = $publish ? 'published' : 'draft';
    $content = $m->getParam(4);
    $title = $m->getParam(6);
    $main_cat = $m->getParam(7);
    $date = $m->getParam(8);
    $params = array('title' => $title->scalarval(), 'content' => $content->scalarval(), 'main_cat_ID' => $main_cat->scalarval(), 'date' => $date->scalarval(), 'status' => $status);
    // COMPLETE VALIDATION & INSERT:
    return xmlrpcs_new_item($params);
}
コード例 #4
0
/**
 * metaWeblog.newPost
 *
 * @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 struct (struct)
 * 					4 publish (bool)
 * @param string item type 'post' or 'page'
 */
function mw_newpost($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 BLOG:
    /**
     * @var Blog
     */
    if (!($Blog =& xmlrpcs_get_Blog($m, 0))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    $xcontent = $m->getParam(3);
    $contentstruct = xmlrpc_decode_recurse($xcontent);
    logIO('Decoded xcontent');
    $status = 'published';
    if (isset($m->params[4])) {
        // getParam(4) is a flag for publish or draft
        $xstatus = $m->getParam(4);
        $xstatus->scalarval();
        $status = $xstatus ? 'published' : 'draft';
        // might be overrided later
    }
    $cat_IDs = _mw_get_cat_IDs($contentstruct, $Blog);
    $date = _mw_decode_date($contentstruct);
    if (!empty($contentstruct['post_type']) && $contentstruct['post_type'] != $item_type) {
        // Overwrite from struct
        $item_type = $contentstruct['post_type'];
    }
    $tags = isset($contentstruct['mt_keywords']) ? $contentstruct['mt_keywords'] : '';
    $content = isset($contentstruct['description']) ? $contentstruct['description'] : '';
    $excerpt = isset($contentstruct['mt_excerpt']) ? $contentstruct['mt_excerpt'] : '';
    $urltitle = isset($contentstruct['wp_slug']) ? $contentstruct['wp_slug'] : '';
    $featured = isset($contentstruct['sticky']) ? $contentstruct['sticky'] : 0;
    $order = isset($contentstruct['wp_page_order']) ? $contentstruct['wp_page_order'] : 0;
    $custom_fields = isset($contentstruct['custom_fields']) ? $contentstruct['custom_fields'] : '';
    $parent_ID = isset($contentstruct['wp_page_parent_id']) ? $contentstruct['wp_page_parent_id'] : '';
    $item_typ_ID = isset($contentstruct['wp_post_format']) ? $contentstruct['wp_post_format'] : 1;
    if ($item_type == 'page') {
        // Force item type 'page'
        $item_typ_ID = 1000;
    }
    if (!empty($contentstruct[$item_type . '_status'])) {
        // Use WP status
        $status = wp_or_b2evo_item_status($contentstruct[$item_type . '_status'], 'b2evo');
    }
    if (!empty($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 = 'open';
    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';
        }
    }
    $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, 'featured' => $featured, 'order' => $order, 'parent_ID' => $parent_ID, 'custom_fields' => $custom_fields);
    // COMPLETE VALIDATION & INSERT:
    return xmlrpcs_new_item($params, $Blog);
}
コード例 #5
0
ファイル: _metaweblog.api.php プロジェクト: LFSF/oras
/**
 * metaWeblog.newPost
 *
 * mw API
 * Tor 2004
 *
 * NB! (Tor Feb 2005) status in metaweblog API speak dictates whether static html files are generated or not, so fairly misleading
 *
 * @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 struct (struct)
 */
function mw_newpost($m)
{
    global $xmlrpcerruser;
    // import user errcode value
    global $DB;
    global $Settings, $Messages;
    // 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();
    }
    // getParam(4) should now be a flag for publish or draft
    $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, $Blog->ID);
    if (!is_array($cat_IDs)) {
        // error:
        return $cat_IDs;
        // This can be a preformatted error message
    }
    $main_cat = $cat_IDs[0];
    // 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
    }
    logIO('Permission granted.');
    $post_date = _mw_decode_postdate($contentstruct, true);
    $post_title = $contentstruct['title'];
    $content = $contentstruct['description'];
    // COMPLETE VALIDATION & INSERT:
    return xmlrpcs_new_item($post_title, $content, $post_date, $main_cat, $cat_IDs, $status);
}
コード例 #6
0
ファイル: _blogger.api.php プロジェクト: LFSF/oras
/**
 * blogger.newPost makes a new post to a designated blog.
 *
 * Optionally, will publish the blog after making the post. (In b2evo, this means the
 * new post will be in 'published' state).
 * On success, it returns the unique ID of the new post (usually a seven-digit number
 * at this time).
 * On error, it will return some error message.
 *
 * @see http://www.blogger.com/developers/api/1_docs/xmlrpc_newPost.html
 * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggernewpost.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 post to the blog.
 *					3 password (string): Password for said username.
 *					4 content (string): Contents of the post.
 *					5 publish (boolean): If true, the blog will be published immediately after the
 *						post is made. (In b2evo,this means, the new post will be in 'published' state,
 *						otherwise it would be in draft state).
 * @return xmlrpcresp XML-RPC Response
 */
function blogger_newpost($m)
{
    global $xmlrpcerruser;
    // import user errcode value
    global $DB;
    global $Settings, $Messages;
    // 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();
    }
    $content = $m->getParam(4);
    $content = $content->scalarval();
    $publish = $m->getParam(5);
    $publish = $publish->scalarval();
    $status = $publish ? 'published' : 'draft';
    logIO("Publish: {$publish} -> Status: {$status}");
    $cat_IDs = xmlrpc_getpostcategories($content);
    if (empty($cat_IDs)) {
        // There were no categories passed in the content:
        if (!($main_cat = $Blog->get_default_cat_ID())) {
            // No default category found for requested blog.
            return xmlrpcs_resperror(12);
            // User error 12
        }
        $cat_IDs = array($main_cat);
    } else {
        $main_cat = $cat_IDs[0];
    }
    // 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
    }
    logIO('Permission granted.');
    logIO('Main cat: ' . $main_cat);
    // Check if category exists
    if (get_the_category_by_ID($main_cat, false) === false) {
        // Cat does not exist:
        // fp> TODO use $Blog->get_default_cat_ID();
        return xmlrpcs_resperror(11);
        // User error 11
    }
    if (get_catblog($main_cat) != $Blog->ID) {
        // The category does not match the blog!
        return xmlrpcs_resperror(11);
        // User error 11
    }
    $post_date = date('Y-m-d H:i:s', time() + $Settings->get('time_difference'));
    // Extract <title> from content
    $post_title = xmlrpc_getposttitle($content);
    // cleanup content from extra tags like <category> and <title>:
    $content = xmlrpc_removepostdata($content);
    // COMPLETE VALIDATION & INSERT:
    return xmlrpcs_new_item($post_title, $content, $post_date, $main_cat, $cat_IDs, $status);
}