コード例 #1
0
ファイル: _blogger.api.php プロジェクト: Ariflaw/b2evolution
/**
 * blogger.editPost changes the contents of a given post.
 *
 * Optionally, will publish the blog the post belongs to after changing the post.
 * (In b2evo, this means the changed post will be moved to published state).
 * On success, it returns a boolean true value.
 * On error, it will return a fault with an error message.
 *
 * @see http://www.blogger.com/developers/api/1_docs/xmlrpc_editPost.html
 * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggereditpost.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 postid (string): Unique identifier of the post to be changed.
 *					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 content (string): New content 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
 *
 * @todo check current status and permission on it
 */
function blogger_editpost($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, 1))) {
        // 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
    }
    $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_edit_item($edited_Item, $params);
}
コード例 #2
0
ファイル: _metaweblog.api.php プロジェクト: LFSF/oras
/**
 * 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  ...");
     		}
    
    }
    */
}
コード例 #3
0
/**
 * 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  ...");
     		}
    
    }
    */
}
コード例 #4
0
ファイル: _blogger.api.php プロジェクト: LFSF/oras
/**
 * blogger.editPost changes the contents of a given post.
 *
 * Optionally, will publish the blog the post belongs to after changing the post.
 * (In b2evo, this means the changed post will be moved to published state).
 * On success, it returns a boolean true value.
 * On error, it will return a fault with an error message.
 *
 * @see http://www.blogger.com/developers/api/1_docs/xmlrpc_editPost.html
 * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggereditpost.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 postid (string): Unique identifier of the post to be changed.
 *					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 content (string): New content 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
 *
 * @todo check current status and permission on it
 */
function blogger_editpost($m)
{
    global $xmlrpcerruser;
    // import user errcode value
    global $DB;
    global $Messages;
    // 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, 1))) {
        // 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:
        $main_cat = $edited_Item->main_cat_ID;
        $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
    }
    $post_date = NULL;
    $post_title = xmlrpc_getposttitle($content);
    $content = xmlrpc_removepostdata($content);
    // COMPLETE VALIDATION & UPDATE:
    return xmlrpcs_edit_item($edited_Item, $post_title, $content, $post_date, $main_cat, $cat_IDs, $status);
}