/chrome/scribefire/apis.js
JavaScript | 3042 lines | 2236 code | 514 blank | 292 comment | 445 complexity | 8a63a0690a08ee6f0146ec3e8c8f9294 MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- var blogApis = {
- };
- function getBlogAPI(type, apiUrl) {
- if (apiUrl in blogApis) {
- return blogApis[apiUrl];
- }
-
- var api = null;
-
- switch (type) {
- case "wordpress":
- api = new wordpressAPI();
- break;
- case "blogger":
- api = new bloggerAPI();
- break;
- case "tumblr":
- api = new tumblrAPI();
- break;
- case "metaweblog":
- api = new genericMetaWeblogAPI();
- break;
- case "movabletype":
- case "movable type":
- api = new genericMovableTypeAPI();
- break;
- case "atom":
- api = new genericAtomAPI();
- break;
- case "posterous":
- api = new posterousAPI();
- break;
- case "livejournal":
- api = new livejournalAPI();
- break;
- default:
- SCRIBEFIRE.error(scribefire_string("error_api_invalid", type));
- break;
- }
-
- if (api) {
- api.apiUrl = apiUrl;
- blogApis[apiUrl] = api;
- return api;
- }
- }
- var blogAPI = function () {
- this.ui = {};
- this.ui.categories = true;
- this.ui["add-category"] = true;
- this.ui.tags = true;
- this.ui.draft = false;
- this.ui.deleteEntry = true;
- this.ui.timestamp = true;
- this.ui.slug = false;
- this.ui.private = false;
- this.ui["text-content_wp_more"] = false;
- this.ui.upload = false;
- this.ui["custom-fields"] = false;
- this.ui.excerpt = false;
- this.ui.pages = false;
- this.ui.getPosts = true;
- this.ui.oauth = false;
- this.ui.nooauth = true;
-
- this.oauthToken = null
- this.accessToken = null;
-
- /*
- this.ui["featured-image"] = false;
- */
- };
- blogAPI.prototype = {
- init : function (blogObject) {
- for (x in blogObject) {
- this[x] = blogObject[x];
- }
-
- this.postInit();
-
- return this;
- },
-
- postInit : function () { },
-
- getBlogs : function (params, success, failure) {
- /**
- * params = { "apiUrl" : "http://...", "username": "john", "password" : "secret123" }
- */
-
- /**
- * success(params) = [ {"url" : "http://...", "id" : "123", "name": "My Blog",
- * "apiUrl" : "http://...", "type": "wordpress", "username": "john",
- * "password": "secret123"}, ... ]
- */
- },
-
- getPosts : function (params, success, failure) {
- /**
- * params = { "limit": <int> }
- */
-
- /**
- * success(params) = [ { "id": <int>, "title": <string>, "content": <string>, "published": <bool>, "tags": <string>, "categories": <string>[] } ]
- */
-
- success([]);
- },
-
- publish : function (params, success, failure) {
- /**
- * params = { "title": <string>, "content": <string>,
- * "categories": <int>[], "tags": <string>,
- * "draft": <bool>, "id": <int> }
- */
-
- /**
- * success(params) = { "id": "123" }
- */
-
- failure({"status": 0, "msg": scribefire_string("error_api_noBlog")});
- },
-
- deletePost : function (params, success, failure) {
- /**
- * params = { "id" : <int> }
- */
-
- /**
- * success(params) = true
- */
- },
- getCategories : function (params, success, failure) {
- /**
- * params = { }
- */
-
- /**
- * success(params) = [ { "id": 1, "name": "Category 1" }, ... ]
- */
-
- success([]);
- },
-
- addCategory : function (params, success, failure) {
- /**
- * params = { "id": 1, "name": "Category" }
- */
-
- /**
- * success(params) = { "id": 1, "name": "Category" }
- */
-
- if (failure) {
- failure({ "status": 0, "msg": scribefire_string("error_api_noCategorySupport")});
- }
- else {
- success(false);
- }
- },
-
- upload : function () {
- failure({ "status": 0, "msg": scribefire_string("error_api_noUploadSupport")});
- },
-
- getPostCategories : function (params, success, failure) {
- success($("#list-entries option[value='"+params.id+"']:first").data("categories"), "value");
- }
- };
- var genericMetaWeblogAPI = function () {
- var newUi = {};
- for (var x in this.ui) newUi[x] = this.ui[x];
- this.ui = newUi;
- this.ui.categories = false;
- this.ui.timestamp = true;
- this.ui.tags = false;
- this.ui.upload = !!((platform == 'gecko') || (window.File && window.FileReader && window.FileList && window.Blob));
- this.ui.draft = true;
-
- this.postInit = function () {
- this.ui.timestamp = !(this.apiUrl.indexOf("http://api.xanga.com/") == 0 || this.apiUrl.indexOf("http://my.opera.com/") == 0);
- this.ui.draft = !(this.apiUrl.indexOf("http://my.opera.com/") == 0);
- };
-
- this.getBlogs = function (params, success, failure) {
- // How safe is it to assume that MetaWeblog APIs implement the blogger_ methods?
-
- if (!params.id || !("id" in params)) {
- params.id = "0";
- }
-
- var args = [params.id, params.username, params.password];
- var xml = performancingAPICalls.blogger_getUsersBlogs(args);
-
- XMLRPC_LIB.doCommand(
- params.apiUrl,
- xml,
- function (rv) {
- if (success) {
- if (rv.length) {
- var blogs = [];
-
- for (var i = 0, _len = rv.length; i < _len; i++) {
- var blog = {};
- blog.url = resolveHref(params.apiUrl, rv[i].url);
- blog.id = rv[i].blogid;
- blog.name = rv[i].blogName;
- blog.apiUrl = params.apiUrl;
- blog.type = params.type;
- blog.username = params.username;
- blog.password = params.password;
-
- blogs.push(blog);
- }
-
- success(blogs);
- }
- else {
- if (failure) {
- failure( {"status" : 200, "msg" : scribefire_string("error_api_cannotConnect")});
- }
- }
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- },
- this.oauthToken
- );
- };
-
- this.getPosts = function (params, success, failure) {
- var self = this;
-
- if (!("limit" in params)) params.limit = 100;
-
- var args = [this.id, this.username, this.password, params.limit];
-
- var xml = performancingAPICalls.metaWeblog_getRecentPosts(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- for (var i = 0; i < rv.length; i++) {
- rv[i].id = rv[i].postid;
- rv[i].tags = rv[i].mt_keywords;
- rv[i].published = (rv[i].post_status != "draft");
- rv[i].private = (rv[i].post_status == "private");
- rv[i].content = rv[i].description;
-
- if (("mt_text_more" in rv[i]) && rv[i].mt_text_more) {
- rv[i].content += '<!--more-->';
- rv[i].content += rv[i].mt_text_more;
- }
-
- if (!("categories" in rv[i])){
- rv[i].categories = [];
- }
-
- if ("wp_slug" in rv[i]) {
- rv[i].slug = rv[i].wp_slug;
- delete rv[i].wp_slug;
- }
-
- if ("mt_excerpt" in rv[i]) {
- rv[i].excerpt = rv[i].mt_excerpt;
- delete rv[i].mt_excerpt;
- }
-
- rv[i].permalink = rv[i].permaLink;
-
- if ("date_created_gmt" in rv[i]) {
- rv[i].timestamp = rv[i].date_created_gmt;
- delete rv[i].date_created_gmt;
- }
- else if ("dateCreated" in rv[i]) {
- rv[i].timestamp = rv[i].dateCreated;
- delete rv[i].dateCreated;
- }
-
- /*
- if ("wp_featured_image" in rv[i]) {
- rv[i].featured_image = rv[i].wp_featured_image;
- delete rv[i].wp_featured_image;
- }
- */
-
- delete rv[i].postid;
- delete rv[i].mt_keywords;
- delete rv[i].post_status;
- delete rv[i].mt_text_more;
- delete rv[i].description;
- delete rv[i].permaLink;
- }
-
- // success(rv);
-
- if (self.ui.pages) {
- var args = [self.id, self.username, self.password, params.limit];
- var xml = performancingAPICalls.wp_getPages(args);
-
- XMLRPC_LIB.doCommand(
- self.apiUrl,
- xml,
- function (pages_rv) {
- // @todo Localize
- var true_rv = { "Posts" : rv, "Pages" : [] };
-
- for (var j = 0; j < pages_rv.length; j++) {
- var i = true_rv.Pages.length;
-
- true_rv.Pages[i] = pages_rv[j];
-
- if ("page_id" in true_rv.Pages[i]) {
- true_rv.Pages[i].id = true_rv.Pages[i].page_id;
- delete true_rv.Pages[i].page_id;
- }
-
- true_rv.Pages[i].published = (true_rv.Pages[i].page_status != "draft");
- true_rv.Pages[i].private = (true_rv.Pages[i].page_status == "private");
- delete true_rv.Pages[i].page_status;
-
- true_rv.Pages[i].content = true_rv.Pages[i].description;
- delete true_rv.Pages[i].description;
- if (("text_more" in true_rv.Pages[i]) && true_rv.Pages[i].text_more) {
- true_rv.Pages[i].content += '<!--more-->';
- true_rv.Pages[i].content += true_rv.Pages[i].text_more;
- }
-
- delete true_rv.Pages[i].text_more;
- if (!("categories" in true_rv.Pages[i])){
- true_rv.Pages[i].categories = [];
- }
- if ("wp_slug" in true_rv.Pages[i]) {
- true_rv.Pages[i].slug = true_rv.Pages[i].wp_slug;
- delete true_rv.Pages[i].wp_slug;
- }
-
- true_rv.Pages[i].permalink = true_rv.Pages[i].permaLink;
- delete true_rv.Pages[i].permaLink;
-
- if ("date_created_gmt" in true_rv.Pages[i]) {
- true_rv.Pages[i].timestamp = true_rv.Pages[i].date_created_gmt;
- delete true_rv.Pages[i].date_created_gmt;
- }
- else if ("dateCreated" in true_rv.Pages[i]) {
- true_rv.Pages[i].timestamp = true_rv.Pages[i].dateCreated;
- delete true_rv.Pages[i].dateCreated;
- }
- }
-
- success(true_rv);
- },
- function (status, msg) {
- success(rv);
- /*
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- */
- },
- self.oauthToken
- );
- }
- else {
- success(rv);
- }
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- },
- this.oauthToken
- );
- };
- this.publish = function (params, success, failure) {
- this.doPublish(params, success, failure);
- };
-
- this.doPublish = function (params, success, failure) {
- var contentStruct = { };
- if ("title" in params) {
- contentStruct.title = params.title;
- }
- if ("content" in params) {
- contentStruct.description = params.content;
- }
- if ("categories" in params) {
- contentStruct.categories = params.categories;
- }
- if ("tags" in params) {
- contentStruct.mt_keywords = params.tags;
- }
-
- if ("timestamp" in params && params.timestamp) {
- // It's converted to UTC in the conversion to XML Step.
- contentStruct.date_created_gmt = params.timestamp;
- // contentStruct.dateCreated = params.timestamp;
- }
-
- if ("private" in params && params.private) {
- contentStruct.post_status = "private";
- }
-
- if ("slug" in params && params.slug) {
- contentStruct.wp_slug = params.slug;
- }
- if ("draft" in params) {
- var publish = params.draft ? "bool0" : "bool1";
-
- if (params.draft) {
- // At least in Wordpress, a private post marked as a draft will just be published.
- if ("private" in params && params.private) {
- if (confirm(scribefire_string("confirm_private_status"))) {
- delete contentStruct.post_status;
- }
- else {
- failure({"status" : -1, "msg" : scribefire_string("cancel_private_status") });
- return;
- }
- }
- }
- }
- else {
- var publish = "bool1";
- }
-
- if ("custom_fields" in params) {
- contentStruct.custom_fields = params.custom_fields;
- }
-
- if (this.ui.excerpt) {
- if ("excerpt" in params) {
- contentStruct.mt_excerpt = params.excerpt;
- }
- }
-
- /*
- if (this.ui["featured-image"] && "featured_image" in params) {
- contentStruct.wp_featured_image = params.wp_featured_image;
- }
- */
-
- if (("id" in params) && params.id) {
- var args = [params.id, this.username, this.password, contentStruct, publish];
- var xml = performancingAPICalls.metaWeblog_editPost(args);
- }
- else {
- var args = [this.id, this.username, this.password, contentStruct, publish];
- var xml = performancingAPICalls.metaWeblog_newPost(args);
- }
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- if (("id" in params) && params.id) {
- success({ "id" : params.id });
- }
- else {
- success({ "id": rv });
- }
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- },
- this.oauthToken
- );
- };
-
- this.deletePost = function (params, success, failure) {
- this.doDeletePost(params, success, failure);
- };
-
- this.doDeletePost = function (params, success, failure) {
- var args = ["0123456789ABCDEF", params.id, this.username, this.password, "bool1"];
- var xml = performancingAPICalls.blogger_deletePost(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- success(rv);
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- },
- this.oauthToken
- );
- };
-
- this.upload = function (fileName, fileType, fileData, success, failure) {
- var bits = btoa(fileData);
-
- var args = [this.id, this.username, this.password, { name : fileName, type : fileType, bits : bits } ];
- var xml = performancingAPICalls.metaWeblog_newMediaObject(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- success( { "url" : rv.url } );
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- },
- this.oauthToken
- );
- }
- };
- genericMetaWeblogAPI.prototype = new blogAPI();
- var genericMovableTypeAPI = function () {
- var newUi = {};
- for (var x in this.ui) newUi[x] = this.ui[x];
- this.ui = newUi;
-
- this.ui.categories = true;
- this.ui["add-category"] = false;
- this.ui.draft = false;
- this.ui.excerpt = true;
-
- this.publish = function (params, success, failure) {
- /*
- // MovableType is hacky about publishing and categories.
-
- // MT supposedly uses the "draft" setting to determine whether
- // to rebuild static pages, not whether it's actually a draft.
- var trueDraft = params.draft;
- params.draft = false;
- */
-
- var self = this;
-
- this.doPublish(params,
- function newSuccess(rv) {
- if (("id" in rv) && rv.id) {
- var postId = rv.id;
- }
- else {
- var postId = rv;
- }
-
- var categories = [];
-
- $("#list-categories option").each(function () {
- var value = $(this).attr("value");
- var categoryId = $(this).attr("categoryId");
-
- for (var i = 0; i < params.categories.length; i++) {
- if (params.categories[i] == value) {
- categories.push( categoryId );
- break;
- }
- }
- });
-
- var newParams = {
- "id": postId,
- "categories": categories
- };
-
- self.setCategories(newParams,
- function categorySuccess(rv) {
- self.publishPost(
- newParams,
- function publishSuccess(rv) {
- success({ "id": postId });
- },
- function publishFailure(status, msg) {
- failure({"status": status, "msg": msg});
- }
- );
- },
- function categoryFailure(rv) {
- failure(rv);
- }
- );
- },
- function newFailure(status, msg) {
- failure({"status": status, "msg": msg});
- }
- );
- };
-
- this.getCategories = function (params, success, failure) {
- var args = [this.id, this.username, this.password];
- var xml = performancingAPICalls.mt_getCategoryList(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- for (var i = 0; i < rv.length; i++) {
- rv[i].id = rv[i].categoryId;
- rv[i].name = rv[i].categoryName;
-
- delete rv[i].categoryId;
- delete rv[i].categoryName;
- }
-
- success(rv);
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- }
- );
- };
-
- this.setCategories = function (params, success, failure) {
- var categories = [];
-
- for (var i = 0; i < params.categories.length; i++) {
- categories.push({"categoryId" : params.categories[i]});
- }
-
- var args = [params.id, this.username, this.password, categories];
-
- var xml = performancingAPICalls.mt_setPostCategories(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function privateCategorySuccess (rv) {
- // rv == true
- if (success) {
- success(rv);
- }
- },
- function privateCategoryFailure (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- }
- );
- };
-
- this.getPostCategories = function (params, success, failure) {
- var args = [params.id, this.username, this.password];
- var xml = performancingAPICalls.mt_getPostCategories(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- var categories = [];
-
- for (var i = 0; i < rv.length; i++) {
- categories.push(rv[i].categoryId);
- }
-
- success(categories, "categoryId");
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- }
- );
- };
-
- this.publishPost = function (params, success, failure) {
- var args = [params.id, this.username, this.password];
-
- var xml = performancingAPICalls.mt_publishPost(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- // rv == true
- if (success) {
- success(rv);
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- }
- );
- };
- };
- genericMovableTypeAPI.prototype = new genericMetaWeblogAPI();
- genericMovableTypeAPI.prototype.parent = genericMetaWeblogAPI.prototype;
- var wordpressAPI = function () {
- var newUi = {};
- for (var x in this.ui) newUi[x] = this.ui[x];
- this.ui = newUi;
-
- this.ui.categories = { "posts" : true, "pages" : false, "default": true };
- this.ui.slug = true;
- this.ui.private = { "posts" : true, "pages" : false, "default": true };
- this.ui["text-content_wp_more"] = true;
- this.ui["custom-fields"] = true;
- this.ui["tags"] = { "posts" : true, "pages" : false, "default": true };
- this.ui.excerpt = true;
- this.ui.pages = true;
-
- this.oauthToken = null;
-
- this.oauth = {
- clientId : 13,
- clientSecret : "JejQPQMRkqLsOcwphSUxyGBtuNO7njtLXehgv0atRTNfCO9hjg6uPnnK1kwq57MB",
- redirectUri : "http://www.scribefire.com/oauth2/",
- endpoints : {
- authorizationUrl : function (metaData) {
- return "https://public-api.wordpress.com/oauth2/authorize?client_id=13&redirect_uri=" + encodeURIComponent("http://www.scribefire.com/oauth2/") + "&response_type=code&blog=" + encodeURIComponent(metaData.blogUrl || metaData.url);
- }
- }
- };
-
- /*
- this.ui["featured-image"] = (this.ui.upload);
- */
-
- this.postInit = function () {
- /*
- if (this.oauthToken) {
- this.id = null;
- this.username = null;
- this.password = null;
-
- this.ui.oauth = true;
- this.ui.nooauth = false;
- }
- */
- };
-
- this.getAuthToken = function (code, callback) {
- var req = new XMLHttpRequest();
- req.open("POST", "https://public-api.wordpress.com/oauth2/token", true);
- req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- var text = req.responseText;
- var json = JSON.parse(text);
-
- var token = json.access_token;
- callback(token);
- }
- };
-
- var argString = "client_id=" + encodeURIComponent(this.oauth.clientId) + "&redirect_uri=" + encodeURIComponent(this.oauth.redirectUri) + "&client_secret=" + encodeURIComponent(this.oauth.clientSecret) + "&code=" + encodeURIComponent(code) + "&grant_type=authorization_code";
-
- req.send(argString);
- };
-
- this.publish = function (params, success, failure) {
- // Some Wordpress plugins apparently rely on linebreaks being \n and not <br />. This is dumb.
- params.content = params.content.replace(/<br\s*\/?>/g, "\n");
- params.content = params.content.replace(/<\/p>\s*<p>/g, "\n\n");
-
- if (params.type == "posts") {
- /*
- if ("featured_image" in params) {
- params.wp_featured_image = parseInt(params.featured_image.id, 10);
- }
- */
-
- this.doPublish(params, success, failure);
- }
- else {
- var contentStruct = { };
- if ("title" in params) {
- contentStruct.title = params.title;
- }
- if ("content" in params) {
- contentStruct.description = params.content;
- }
- if ("timestamp" in params && params.timestamp) {
- contentStruct.dateCreated = params.timestamp;
- }
-
- if ("slug" in params && params.slug) {
- contentStruct.wp_slug = params.slug;
- }
- if ("draft" in params) {
- var publish = params.draft ? "bool0" : "bool1";
- }
- else {
- var publish = "bool1";
- }
-
- if ("custom_fields" in params) {
- contentStruct.custom_fields = params.custom_fields;
- }
-
- if (this.ui.excerpt) {
- if ("excerpt" in params) {
- contentStruct.mt_excerpt = params.excerpt;
- }
- }
-
- if (("id" in params) && params.id) {
- var args = [params.id, this.username, this.password, contentStruct, publish];
- var xml = performancingAPICalls.metaWeblog_editPost(args);
- }
- else {
- var args = [this.id, this.username, this.password, contentStruct, publish];
- var xml = performancingAPICalls.wp_newPage(args);
- }
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- if (("id" in params) && params.id) {
- success({ "id" : params.id });
- }
- else {
- success({ "id": rv });
- }
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- },
- this.oauthToken
- );
- }
- };
-
- this.getBlogs = function (params, success, failure) {
- var args = [params.username, params.password];
- var xml = performancingAPICalls.wp_getUsersBlogs(args);
-
- var self = this;
-
- XMLRPC_LIB.doCommand(
- params.apiUrl,
- xml,
- function (rv) {
- if (success) {
- if (rv.length) {
- var blogs = [];
-
- for (var i = 0, _len = rv.length; i < _len; i++) {
- if (rv[i].xmlrpc == params.apiUrl) {
- var blog = {};
- blog.url = rv[i].url;
- blog.id = rv[i].blogid;
- blog.name = rv[i].blogName;
- blog.apiUrl = rv[i].xmlrpc;
- blog.type = params.type;
- blog.username = params.username;
- blog.password = params.password;
-
- blogs.push(blog);
- }
- }
-
- success(blogs);
- }
- else {
- if (failure) {
- failure( {"status" : 200, "msg" : scribefire_string("error_api_cannotConnect")});
- }
- }
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- },
- this.oauthToken
- );
- };
-
- this.getCategories = function (params, success, failure) {
- var args = [this.id, this.username, this.password];
- var xml = performancingAPICalls.mt_getCategoryList(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- for (var i = 0; i < rv.length; i++) {
- rv[i].id = rv[i].categoryId;
- rv[i].name = rv[i].categoryName;
-
- delete rv[i].categoryId;
- delete rv[i].categoryName;
- }
-
- success(rv);
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- },
- this.oauthToken
- );
- };
-
- this.addCategory = function (params, success, failure) {
- var args = [this.id, this.username, this.password, { name : params.name } ];
- var xml = performancingAPICalls.wp_newCategory(args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- success({ "id": rv, "name": params.name });
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- } ,
- this.oauthToken
- );
- }
-
- this.deletePost = function (params, success, failure) {
- if (params.type == "posts") {
- this.doDeletePost(params, success, failure);
- }
- else {
- var args = [params.id, this.username, this.password, params.id];
- var xml = performancingAPICalls.wp_deletePage(args);
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- success(rv);
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- } ,
- this.oauthToken
- );
- }
- }
-
- this.getMediaLibrary = function (params, success, failure) {
- var args = [params.id, this.username, this.password, { number : 1 } ];
- var xml = performancingAPICalls.wp_getMediaLibrary(args);
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- success(rv);
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- } ,
- this.oauthToken
- );
- };
- };
- wordpressAPI.prototype = new genericMetaWeblogAPI();
- var livejournalAPI = function () {
- // LiveJournal doesn't actually use this anymore. It uses Atom.
- // But some other blogs still use this interface.
-
- this.ui.private = true;
- this.ui.categories = false;
- this.ui["add-category"] = false;
- this.ui.tags = false;
- this.ui.timestamp = false;
- this.ui["text-content_wp_more"] = true;
-
- this.getBlogs = function (params, success, failure) {
- var self = this;
-
- var args = [ { username : params.username, password : params.password } ];
- var xml = XMLRPC_LIB.makeXML("LJ.XMLRPC.login", args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- var blogs = [];
-
- var blog = {};
- blog.name = params.username;
- blog.url = self.apiUrl.replace("www.", params.username + ".").replace("interface/xmlrpc", "");
- blog.id = rv.userid;
- blog.apiUrl = self.apiUrl;
- blog.type = "livejournal";
- blog.username = params.username;
- blog.password = params.password;
-
- blogs.push(blog);
-
- success(blogs);
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- }
- );
- };
-
- this.getPosts = function (params, success, failure) {
- var self = this;
- var args = [ { username : this.username, password : this.password, selecttype : "lastn", howmany : 50, ver : 1 } ];
- var xml = XMLRPC_LIB.makeXML("LJ.XMLRPC.getevents", args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- var posts = [];
-
- for (var i = 0, _len = rv.events.length; i < _len; i++) {
- var event = rv.events[i];
-
- var post = {};
-
- post.content = event.event;
-
- post.content = post.content
- .replace(/<a name=.cutid1.><\/a>/, '<!--more-->')
- .replace(/<a name=.cutid1-end.><\/a>/, '<!--endmore-->');
-
- post.title = event.subject;
-
- var val = event.eventtime;
-
- // Check for a timezone offset
- var possibleOffset = val.substr(-6);
- var hasTimezone = false;
- var minutes = null;
-
- if (possibleOffset.charAt(0) == "-" || possibleOffset.charAt(0) == "+") {
- var hours = parseInt(possibleOffset.substr(1,2), 10);
- var minutes = (hours * 60) + parseInt(possibleOffset.substr(4,2), 10);
-
- if (possibleOffset.charAt(0) == "+") {
- minutes *= -1;
- }
-
- hasTimezone = true;
- }
-
- val = val.replace(/-/gi, "");
-
- var year = parseInt(val.substring(0, 4), 10);
- var month = parseInt(val.substring(4, 6), 10) - 1
- var day = parseInt(val.substring(6, 8), 10);
- var hour = parseInt(val.substring(9, 11), 10);
- var minute = parseInt(val.substring(12, 14), 10);
- var second = parseInt(val.substring(15, 17), 10);
-
- var dateutc = Date.UTC(year, month, day, hour, minute, second);
- dateutc = new Date(dateutc);
-
- if (!hasTimezone) {
- minutes = new Date(dateutc).getTimezoneOffset();
- }
-
- var offsetDate = dateutc.getTime();
- offsetDate += (1000 * 60 * minutes);
- dateutc.setTime(offsetDate);
-
- post.timestamp = dateutc;
-
- post.categories = [];
- post.url = event.url;
- post.id = event.itemid;
- post.published = true;
- post.private = false;
-
- if ("security" in event && event.security == "private") {
- post.private = true;
- }
- posts.push(post);
- }
-
- success(posts);
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- }
- );
- };
-
- this.publish = function (params, success, failure) {
- var contentStruct = { };
- contentStruct.username = this.username;
- contentStruct.password = this.password;
- contentStruct.ver = 1;
- contentStruct.subject = params.title;
-
- if (params.content.indexOf('<!--more-->') != -1) {
- params.content = params.content.replace('<!--more-->', '<lj-cut text="Read more...">');
-
- if (params.content.indexOf('<!--endmore-->') == -1) {
- params.content += '</lj-cut>';
- }
- else {
- params.content = params.content.replace('<!--endmore-->', '</lj-cut>');
- }
- }
-
- contentStruct.event = params.content;
-
- if ("private" in params && params.private) {
- contentStruct.security = "private";
- }
-
- var now = new Date();
-
- contentStruct.year = now.getFullYear();
- contentStruct.mon = now.getMonth() + 1;
- contentStruct.day = now.getDate();
- contentStruct.hour = now.getHours();
- contentStruct.min = now.getMinutes();
-
- var args = [ contentStruct ];
-
- if ("id" in params && params.id) {
- contentStruct.itemid = params.id;
-
- var xml = XMLRPC_LIB.makeXML("LJ.XMLRPC.editevent", [ contentStruct ] );
- }
- else {
- var xml = XMLRPC_LIB.makeXML("LJ.XMLRPC.postevent", [ contentStruct ]);
- }
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- if (("itemid" in rv) && rv.itemid) {
- success({ "id" : rv.itemid });
- }
- else if ("id" in params && params.id) {
- success({ "id" : params.id });
- }
- else {
- success({ "id" : rv });
- }
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- }
- );
- };
-
- this.deletePost = function (params, success, failure) {
- var args = [ { username : this.username, password : this.password, ver : 1, itemid : params.id, event : "" } ];
- var xml = XMLRPC_LIB.makeXML("LJ.XMLRPC.editevent", args);
-
- XMLRPC_LIB.doCommand(
- this.apiUrl,
- xml,
- function (rv) {
- if (success) {
- success(rv);
- }
- },
- function (status, msg) {
- if (failure) {
- failure({"status": status, "msg": msg});
- }
- }
- );
-
- };
- };
- livejournalAPI.prototype = new blogAPI();
- var genericAtomAPI = function () {
- var newUi = {};
- for (var x in this.ui) newUi[x] = this.ui[x];
- this.ui = newUi;
- this.ui.tags = false;
- this.ui.categories = false;
- this.ui["text-content_wp_more"] = true;
-
- this.processResponse = function (req, callback, failure) {
- callback(false);
- };
-
- this.getBlogs = function (params, success, failure) {
- this.init(params);
-
- var self = this;
-
- this.buildRequest(
- "GET",
- this.apiUrl,
- function (req) {
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- self.processResponse(req, function (redo) {
- if (redo) {
- self.getBlogs(params, success, failure);
- }
- else {
- if (req.status < 300) {
- var xml = xmlFromRequest(req);
-
- if (!xml) {
- if (failure) {
- failure({"status": req.status, "msg": req.responseText});
- }
- }
- else {
- var jxml = $(xml);
-
- var blogs = [];
-
- var blog = {};
- blog.url = jxml.find("link[rel='alternate']:first").attr("href");
- blog.name = jxml.find("title:first").text();
- blog.id = jxml.find("id:first").text().split(":blog-")[1];
- blog.apiUrl = params.apiUrl;
- blog.type = params.type;
- blog.username = params.username;
- blog.password = params.password;
-
- blog.atomAPIs = self.atomAPIs;
-
- blogs.push(blog);
-
- success(blogs);
- }
- }
- else {
- if (failure) {
- failure({"status": req.status, "msg": req.responseText});
- }
- }
- }
- }, failure);
- }
- };
-
- req.send(null);
- }
- );
- };
-
- this.getPosts = function (params, success, failure) {
- var self = this;
-
- this.buildRequest(
- "GET",
- this.atomAPIs["service.feed"],
- function (req) {
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- self.processResponse(req, function (redo) {
- if (redo) {
- self.getPosts(params, success, failure);
- }
- else {
- if (req.status < 300) {
- // Firefox doesn't do well with namespaced elements
- var fakeReq = {};
- fakeReq.responseText = req.responseText.replace(/<(\/)?app:/g, "<$1app_");
-
- var xml = xmlFromRequest(fakeReq);
-
- var jxml = $(xml);
-
- var posts = [];
-
- jxml.find("entry").each(function () {
- var post = {};
-
- post.content = $(this).find("content:first").text();
- post.content = post.content
- .replace(/<a name=.cutid1.><\/a>/, '<!--more-->')
- .replace(/<a name=.cutid1-end.><\/a>/, '<!--endmore-->');
-
- post.title = $(this).find("title:first").text();
-
- var val = $(this).find("published:first").text();
-
- // Check for a timezone offset
- var possibleOffset = val.substr(-6);
- var hasTimezone = false;
- var minutes = null;
-
- if (possibleOffset.charAt(0) == "-" || possibleOffset.charAt(0) == "+") {
- var hours = parseInt(possibleOffset.substr(1,2), 10);
- var minutes = (hours * 60) + parseInt(possibleOffset.substr(4,2), 10);
-
- if (possibleOffset.charAt(0) == "+") {
- minutes *= -1;
- }
-
- hasTimezone = true;
- }
-
- val = val.replace(/-/gi, "");
-
- var year = parseInt(val.substring(0, 4), 10);
- var month = parseInt(val.substring(4, 6), 10) - 1
- var day = parseInt(val.substring(6, 8), 10);
- var hour = parseInt(val.substring(9, 11), 10);
- var minute = parseInt(val.substring(12, 14), 10);
- var second = parseInt(val.substring(15, 17), 10);
-
- var dateutc = Date.UTC(year, month, day, hour, minute, second);
- dateutc = new Date(dateutc);
-
- if (!hasTimezone) {
- minutes = new Date(dateutc).getTimezoneOffset();
- }
-
- var offsetDate = dateutc.getTime();
- offsetDate += (1000 * 60 * minutes);
- dateutc.setTime(offsetDate);
-
- post.timestamp = dateutc;
-
- post.categories = [];
-
- $(this).find("category").each(function () {
- post.categories.push($(this).attr("term"));
- });
-
- $(this).find("link").each(function () {
- if ($(this).attr("rel") == "alternate") {
- post.url = $(this).attr("href");
- }
- });
-
- //var postUrl = $(this).find("id:first").text();
-
- post.id = $(this).find("id:first").text();//postUrl.match( /(?:\/|post-)(\d{5,})(?!\d*\/)/)[1];
-
- if ($(this).find("link[rel='service.edit']:first").length > 0) {
- post["service.edit"] = $(this).find("link[rel='service.edit']:first").attr("href");
- }
- else {
- post["service.edit"] = $(this).find("link[rel='edit']:first").attr("href");
- }
-
- post.published = true;
-
- $(this).find("app_draft").each(function () {
- if ($(this).text() == "yes") {
- post.published = false;
- }
- });
-
- posts.push(post);
- });
-
- success(posts);
- }
- else {
- failure({ "status": req.status, "msg": req.responseText });
- }
- }
- }, failure);
- }
- };
-
- req.send(null);
- }
- );
- };
-
- this.publish = function (params, success, failure) {
- var self = this;
-
- var method = "POST";
- var apiUrl = this.atomAPIs["service.post"];
-
- var body = "";
- body += '<?xml version="1.0" encoding="UTF-8" ?>';
- body += '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#">';
- if ("id" in params && params.id) {
- method = "PUT";
-
- apiUrl = params["service.edit"];
-
- // Apparently LiveJournal requires this, but Blogger overlooks it.
- body += '<id>'+params.id+'</id>';
- }
-
- if ("title" in params) {
- body += '<title><![CDATA[' + params.title + ']]></title>';
- }
-
- if ("categories" in params) {
- for (var i = 0; i < params.categories.length; i++) {
- // Not all Atom APIs will respect this.
- body += '<category scheme="http://www.blogger.com/atom/ns#" term="'+params.categories[i].replace(/&/g,'&')+'"/>';
- }
- }
-
- if ("timestamp" in params && params.timestamp) {
- var date = params.timestamp;
-
- body += '<published>' + date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + "T" + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":00.000Z" + '</published>';
- }
-
- if ("content" in params) {
- if (params.content.indexOf('<!--more-->') != -1) {
- params.content = params.content.replace('<!--more-->', '<lj-cut text="Read more...">');
-
- if (params.content.indexOf('<!--endmore-->') == -1) {
- params.content += '</lj-cut>';
- }
- else {
- params.content = params.content.replace('<!--endmore-->', '</lj-cut>');
- }
- }
-
- body += '<content type="html"><![CDATA[' + params.content + ']]></content>';
- }
- if ("draft" in params && params.draft) {
- body += '<app:control>';
- body += '<app:draft>yes</app:draft>';
- body += '</app:control>';
- }
-
- body += '</entry>';
-
- this.buildRequest(
- method,
- apiUrl,
- function (req) {
- /**
- * If any Atom implementations actually respected it, this is how we would
- * set the post slug.
- */
-
- /*
- if ("slug" in params) {
- req.setRequestHeader("Slug", params.slug);
- }
- */
-
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- self.processResponse(req, function (redo) {
- if (redo) {
- self.publish(params, success, failure);
- }
- else {
- if (req.status < 300) {
- var xml = xmlFromRequest(req);
- var jxml = $(xml);
- var postId = jxml.find("id:first").text();//.split(".post-")[1];
- if (!postId && params.id) {
- postId = params.id;
- }
- success({ "id": postId });
- }
- else {
- failure({ "status": req.status, "msg": req.responseText });
- }
- }
- }, failure);
- }
- };
-
- req.send(body);
- }
- );
- };
-
- /*
-
- // You would think that if the list of categories is made available, it would be possible to add
- // a category to an entry, but noooooo.
-
- this.getCategories = function (params, success, failure) {
- // This API is checked for exposure the first time that categories need to be loaded.
- if ("service.categories" in this.atomAPIs) {
- if (this.atomAPIs["service.categories"]) {
- this.buildRequest(
- "GET",
- this.atomAPIs["service.categories"],
- function (req) {
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- if (req.status < 300) {
- var xml = xmlFromRequest(req);
- var jxml = $(xml);
-
- var categories = [];
-
- jxml.find("subject").each(function () {
- var cat = $(this).text();
-
- categories.push({ "id": cat, "name": cat });
- });
-
- success(categories);
-
- }
- else {
- failure({ "status": req.status, "msg": req.responseText });
- }
- }
- };
-
- req.send(null);
- }
- );
- }
- else {
- this.ui.categories = false;
-
- SCRIBEFIRE.updateOptionalUI();
-
- success([]);
- }
- }
- else {
- var self = this;
-
- this.buildRequest(
- "GET",
- this.atomAPIs["service.feed"],
- function (req) {
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- if (req.status < 300) {
- var xml = xmlFromRequest(req);
- var jxml = $(xml);
-
- var interfaceUrl = jxml.find("entry:first link[rel='self']:first").attr("href");
-
- self.buildRequest(
- "GET",
- interfaceUrl,
- function (creq) {
- creq.onreadystatechange = function () {
- if (creq.readyState == 4) {
- if (creq.status < 300) {
- var cxml = xmlFromRequest(creq);
- var cjxml = $(cxml);
-
- var categoryLink = cjxml.find("link[rel='service.categories']:first");
-
- if (categoryLink) {
- self.atomAPIs["service.categories"] = categoryLink.attr("href");
- }
- else {
- self.atomAPIs["service.categories"] = false;
- }
- }
- else {
- self.atomAPIs["service.categories"] = false;
- }
-
- SCRIBEFIRE.setBlogProperty(self.url, self.username, "atomAPIs", self.atomAPIs);
- self.getCategories(params, success, failure);
- }
- };
-
- creq.send(null);
- }
- );
- }
- else {
- self.atomAPIs["service.categories"] = false;
- SCRIBEFIRE.setBlogProperty(self.url, self.username, "atomAPIs", self.atomAPIs);
- self.getCategories(params, success, failure);
- }
- }
- };
-
- req.send(null);
- }
- );
- }
- };
-
- this.addCategory = function (params, success, failure) {
- success({ "id": params.name, "name": params.name });
- };
-
- */
-
- this.deletePost = function (params, success, failure) {
- var self = this;
-
- this.buildRequest(
- "DELETE",
- params["service.edit"],
- function (req) {
- req.onreadystatechange = function () {
- if (req.readyState == 4){
- self.processResponse(req, function (redo) {
- if (redo) {
- self.deletePost(params, success, failure);
- }
- else {
- if (req.status < 300) {
- success(true);
- }
- else {
- failure({ "status": req.status, "msg": req.responseText });
- }
- }
- }, failure);
- }
- };
-
- req.send(null);
- }
- );
- };
- this.buildRequest = function (method, url, callback) {
- var req = new XMLHttpRequest();
- var urlParts = url.split("://");
- url = urlParts[0] + "://" + encodeURIComponent(this.username) + ":" + encodeURIComponent(this.password) + "@" + urlParts[1];
- req.open(method, url, true);
-
- req.setRequestHeader("Content-Type", "application/atom+xml");
-
- callback(req);
- };
- };
- genericAtomAPI.prototype = new blogAPI();
- var bloggerAPI = function () {
- var newUi = {};
- for (var x in this.ui) newUi[x] = this.ui[x];
- this.ui = newUi;
-
- this.ui.categories = true;
- this.ui.upload = (!!(((platform == 'gecko') || (window.File && window.FileReader && window.FileList && window.Blob)))) && (platform != 'presto');
- this.ui.draft = true;
-
- // this.oauthToken is the complete JSON response, containing access_token, expires_on, refresh_token.
- this.oauthToken = null;
- // this.accessToken gets set to this.oauthToken.access_token
- this.accessToken = null;
-
- this.oauth = {
- clientId : "116375103348.apps.googleusercontent.com",
- clientSecret : "ZV6urYYje-6AaTcjoya3RW7Y",
- redirectUri : "urn:ietf:wg:oauth:2.0:oob",
- endpoints : {
- authorizationUrl : function (metaData) {
- return "https://accounts.google.com/o/oauth2/auth?client_id=" + encodeURIComponent("116375103348.apps.googleusercontent.com") + "&redirect_uri=" + encodeURIComponent("urn:ietf:wg:oauth:2.0:oob") + "&scope=" + encodeURIComponent("https://www.blogger.com/feeds/ http://picasaweb.google.com/data/") + "&response_type=code";
- }
- }
- };
-
- this.postInit = function () {
- /*
- if (this.oauthToken) {
- this.id = null;
- this.username = null;
- this.password = null;
-
- this.ui.oauth = true;
- this.ui.nooauth = false;
-
- this.accessToken = this.oauthToken.access_token;
- }
- */
- };
-
- this.getAuthToken = function (code, callback) {
- var req = new XMLHttpRequest();
- req.open("POST", "https://accounts.google.com/o/oauth2/token", true);
- req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- var json = JSON.parse(req.responseText);
- callback(json);
- }
- };
-
- var argString = "client_id=" + encodeURIComponent(this.oauth.clientId) + "&redirect_uri=" + encodeURIComponent(this.oauth.redirectUri) + "&client_secret=" + encodeURIComponent(this.oauth.clientSecret) + "&code=" + encodeURIComponent(code) + "&grant_type=authorization_code";
-
- req.send(argString);
- };
-
- this.refreshAuthToken = function (success, failure) {
- var self = this;
-
- var req = new XMLHttpRequest();
- req.open("POST", "https://accounts.google.com/o/oauth2/token", true);
- req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- if (req.status < 300) {
- var json = JSON.parse(req.responseText);
- var blog = SCRIBEFIRE.getBlog();
- blog.oauthToken = json;
- self.oauthToken = json;
- self.accessToken = self.oauthToken.access_token;
- SCRIBEFIRE.setBlog(blog);
-
- success(true);
- }
- else {
- failure({ status : req.status, "msg" : req.responseText });
- }
- }
- };
-
- var codeJson = self.oauthToken;
- var argString = "client_id=" + encodeURIComponent(this.oauth.clientId) + "&client_secret=" + encodeURIComponent(this.oauth.clientSecret) + "&refresh_token=" + encodeURIComponent(codeJson.refresh_token) + "&grant_type=refresh_token";
- req.send(argString);
- };
-
- this.processResponse = function (req, callback, failure) {
- if (!this.accessToken) {
- callback(false);
- }
- else if (req.status != 401) {
- callback(false);
- }
- else {
- this.refreshAuthToken(callback, failure);
- }
- };
-
- this.authToken = null;
-
- this.getCategories = function (params, success, failure) {
- var self = this;
-
- this.getPosts(
- params,
- function (posts) {
- var categories = {};
-
- for (var i = 0; i < posts.length; i++) {
- for (var j = 0; j < posts[i].categories.length; j++) {
- categories[posts[i].categories[j]] = true;
- }
- }
-
- var rv = [];
-
- for (var i in categories) {
- rv.push(i);
- }
-
- rv.sort();
-
- for (var i = 0; i < rv.length; i++) {
- var categoryName = rv[i];
- rv[i] = { "id" : rv[i], "name": rv[i] };
- }
-
- success(rv);
- },
- failure
- );
- };
-
- this.addCategory = function (params, success, failure) {
- success({ "id": params.name, "name": params.name });
- };
-
- this.doAuth = function (callback, params) {
- if (this.authToken) {
- callback(this.authToken);
- }
- else {
- var self = this;
-
- var req = new XMLHttpRequest();
- req.open("POST", "https://www.google.com/accounts/ClientLogin", true);
- req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-
- var argString = "Email="+encodeURIComponent(this.username)+"&Passwd="+encodeURIComponent(this.password)+"&service=blogger&source=scribefire";
-
- if (params) {
- for (var i in params) {
- argString += "&"+i+"="+encodeURIComponent(params[i]);
- }
- }
-
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- var lines = req.responseText.split("\n");
-
- var returnValues = {};
-
- for (var i = 0; i < lines.length; i++) {
- var parts = lines[i].split("=");
- var key = parts.shift();
- var value = parts.join("=");
-
- returnValues[key] = value;
- }
-
- if (req.status < 300) {
- self.authToken = returnValues["Auth"];
-
- callback(self.authToken);
- }
- else {
- switch (returnValues["Error"]) {
- case 'BadAuthentication':
- SCRIBEFIRE.error(scribefire_string("error_api_blogger_authentication"), "BadAuthentication");
- return;
- break;
- case 'NotVerified':
- SCRIBEFIRE.error(scribefire_string("error_api_blogger_verify"));
- return;
- break;
- case 'TermsNotAgreed':
- SCRIBEFIRE.error(scribefire_string("error_api_blogger_tos"));
- return;
- break;
- case 'AccountDeleted':
- SCRIBEFIRE.error(scribefire_string("error_api_blogger_deleted"));
- return;
- break;
- case 'ServiceDisabled':
- SCRIBEFIRE.error(scribefire_string("error_api_blogger_disabled"));
- return;
- break;
- case 'ServiceUnavailable':
- SCRIBEFIRE.error(scribefire_string("error_api_blogger_unavailable"));
- return;
- break;
- case 'CaptchaRequired':
- var imgUrl = "https://www.google.com/accounts/" + returnValues["CaptchaUrl"];
-
- var container = $("<div/>");
-
- var header = $("<h4/>");
- header.text(scribefire_string("error_api_blogger_captcha"));
- container.append(header);
-
- var message = $("<p/>");
- container.append(message);
-
- var image = $("<img/>");
- image.attr("src", imgUrl);
- message.append(image);
-
- var textbox = $("<input/>");
- textbox.attr("type", "text");
- textbox.attr("id", "google-captcha");
- container.append(textbox);
-
- var submit = $("<input />");
- submit.attr("type", "submit");
- submit.val(scribefire_string("continue"));
- submit.attr("id", "captcha-continue");
- container.append(submit);
-
- $.facebox(container);
-
- $("#captcha-continue").live("click", function (e) {
- var captcha = $("#google-captcha").val();
-
- $(document).trigger("close.facebox");
-
- if (captcha) {
- self.doAuth(callback, {"logintoken": returnValues["CaptchaToken"], "logincaptcha": captcha });
- return;
- }
- });
-
- …
Large files files are truncated, but you can click here to view the full file