(*

    To use:

        1. Make changes to username and userpass to match your own settings. Note that these are not protected or encrypted in any way.

        2. Change all instances of "http://www.fcstest.com/xmlrpc.php" to the path to your xmlrpc application. For WordPress users, it should be "xmlrpc.php" inside wherever you installed WordPress. This does not have to be a php script, just something that accepts xmlrpc calls.

        3. Change the "on run" function so that it matches how you want to use it. This script is created for Considera but can be adapted for any application.

    

    Note that this uses the Blogger API. This is for a few reasons. The metaWeblog API was complicated and I never got it to work right (it required structs to post which aren't available and receiving posts borked more often than they worked). The Blogger API was simple and works with WordPress.

    

    The WP_AssemblePost is a convenience function to turn the Blogger post into something that allows title and category use in WordPress.

*)

property username : "username"

property userpass : "userpass"

on run {}

     tell application "Considera"

         set d to selected document

         set ptitle to name of d

         set ptext to text of d

        

        (* Use this if you use projects as categories *)

        -- set pcategory to name of selected project

         set n to my Blogger_newPost ( my WP_AssemblePost ( ptitle , ptext , "General"))

         set pnotes to ((("Post number: " & n as string ) & return & "Posted on: " & ( current date ) as string ) & return & notes of d )

         set notes of d to pnotes

     end tell

end run

on WP_AssemblePost ( postTitle , postText , postCategory )

     set x to ""

     if postTitle is not "" then set x to x & "<title>" & postTitle & "</title>"

     if postCategory is not "" then set x to x & "<category>" & postCategory & "</category>"

     set x to x & postText

     return x

end WP_AssemblePost

on Blogger_getPosts ()

    -- returns an array

     tell application "http://www.fcstest.com/xmlrpc.php"

         return call xmlrpc { method name :"blogger.getRecentPosts", parameters :{"", "", username , userpass , 10}}

     end tell

end Blogger_getPosts

on Blogger_newPost ( postText )

    -- returns index of post

     tell application "http://www.fcstest.com/xmlrpc.php"

         return call xmlrpc { method name :"blogger.newPost", parameters :{"", "none", username , userpass , postText , true }}

     end tell

end Blogger_newPost

on Blogger_editPost ( postNumber , postText )

     tell application "http://www.fcstest.com/xmlrpc.php"

         return call xmlrpc { method name :"blogger.editPost", parameters :{"", ( postNumber as string ), username , userpass , postText , true }}

     end tell

end Blogger_editPost