//{{{
// Blog macro
// v0.2
// 09th October 2007
//
// Author: Craig Cook, craig [dot] cook [at] bt [dot] com
//
// Not quite sure how to do this at the moment
// ============================================
// Adapted: 2008-11-22 W. Hibma, http://whitehat-marketer.com/blog
// Change: Added the possibility to update a post.
//Need to add the following into the main TiddlyWiki://config.commands.publishBlog: {}, - FIXED
//and to the div 'ViewTemplate' in the 'toolbar' class add publishBlog - CHANGED:
// blogViewTemplate created, active when TaggedTemplateTweak plugin is installed
//Add the publishBlog option into TiddlyWiki
// set some default values for blog variables
if(!config.options.txtBlogID) config.options.txtBlogID = "your blog id";
if(!config.options.txtBlogUserName) config.options.txtBlogUserName = "your username";
if(!config.options.pasBlogPassWord) config.options.pasBlogPassWord = "password";
var _subject="";
var _method = "";
var _blogid = "";
config.commands.publishBlog = {};
merge(config.commands.publishBlog,{
text: "publish",
tooltip: "This will publish to you online blog"});
config.commands.publishBlog.handler = function(event,src,title) {
var pubTiddler = store.getTiddler(title);
var blog = new Blog();
blog.setSubject(pubTiddler.title);
_subject = pubTiddler.title;
blog.setTags(pubTiddler.tags);
var tiddlerElem = store.getTiddler(_subject);
var theText = tiddlerElem.text;
// Change the post
if (theText.indexOf("[#")>0)
{
blog.method = "metaWeblog.editPost";
var index=0;
var index2=0;
index = theText.indexOf("[#", index+1);
index2 = theText.indexOf("#]", index+1);
_blogid = theText.substring(index+2,index2);
blog.blogid = _blogid;
theText = theText.replace("[#"+ _blogid +"#]","");
}
// New post
else
{
blog.method = "metaWeblog.newPost";
blog.blogid = config.options.txtBlogID; // get the full name of the blog, i.e. site.com
}
_method = blog.method;
blog.setContent(theText);
blog.publish();
};
function Blog() {
this.appkey = "0123456789ABCDEF";
this.username = config.options.txtBlogUserName;
this.password = config.options.pasBlogPassWord;
this.blogid = config.options.txtBlogID; //i.e. site.com
this.content = "";
this.subject = "";
this.tags = "";
this.blogURL = "http://"+config.options.txtBlogID+"/xmlrpc.php"; //This is for wordpress, will need to be changed for others
}
Blog.prototype.publish = function(){
var xmlMsg = new XMLRPCMessage();
xmlMsg.setMethod(this.method);
xmlMsg.addStringXML(this.blogid);
xmlMsg.addStringXML(this.username);
xmlMsg.addStringXML(this.password);
// Make real hyperlinks from the tiddly links,
// [[Tiddly Link]] becomes Tiddly Link
var m = this.content.match(/\[\[.*?\]\]/g);
if (m != null && m.length>=1)
{
for(var i=0;i" + link + "";
this.content = this.content.replace(m[i],hyperlink);
}
}
xmlMsg.addItemXML("description" + this.content.htmlEncode() + "title" + this.subject + "categories" + this.tags + "");
xmlMsg.addBoolXML(true);
var xmlText = xmlMsg.xml();
this.makeAjaxCall(this.blogURL, xmlText);
};
Blog.prototype.makeAjaxCall = function(url, postdata) {
// with callback
var loginCallback = function(status,params,responseText,url,xhr) {
if (status) {
displayMessage("completed...");
alert(responseText);
var theId = "";
var tiddlerElem = store.getTiddler(_subject);
// change post
if (_method == "metaWeblog.editPost")
{
tiddlerElem.text.replace(/\[#.*?#\]/mg,"[#"+ _blogid + "#]");
}
else // new post
{
var index=0;
var index2=0;
index = responseText.indexOf("", index+1);
index2 = responseText.indexOf("", index+1);
theId = responseText.substring(index+8,index2);
if(tiddlerElem.text.contains("