2008-06-05 12:08:00 +00:00
|
|
|
//
|
|
|
|
// The Antville Project
|
|
|
|
// http://code.google.com/p/antville
|
|
|
|
//
|
|
|
|
// Copyright 2001-2007 by The Antville People
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the ``License'');
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// $Revision$
|
|
|
|
// $LastChangedBy$
|
|
|
|
// $LastChangedDate$
|
|
|
|
// $URL$
|
|
|
|
//
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
* @fileOverview Methods that implement Movable Type's XML-RPC API.
|
|
|
|
* See http://www.sixapart.com/developers/xmlrpc/movable_type_api for details.
|
|
|
|
*/
|
2008-06-05 12:08:00 +00:00
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/** @namespace */
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt = {};
|
2008-06-05 12:08:00 +00:00
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Number} id
|
|
|
|
* @param {String} name
|
|
|
|
* @param {String} password
|
|
|
|
* @param {Number} limit
|
|
|
|
* @throws {Error}
|
|
|
|
* @returns {Object[]}
|
|
|
|
*/
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt.getRecentPostTitles = function(id, name, password, limit) {
|
2008-06-05 12:08:00 +00:00
|
|
|
var site = Api.getSite(id);
|
2008-06-05 14:47:21 +00:00
|
|
|
var user = Api.getUser(name, password);
|
2008-06-05 12:08:00 +00:00
|
|
|
|
2008-06-05 14:47:21 +00:00
|
|
|
Api.constrain(site, user);
|
2008-06-05 12:08:00 +00:00
|
|
|
if (!site.stories.getPermission("main")) {
|
|
|
|
throw Error("Permission denied for user " + user.name +
|
2008-06-05 14:47:21 +00:00
|
|
|
" to get recent post titles from site " + site.name);
|
2008-06-05 12:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var result = [];
|
|
|
|
var stories = res.handlers.membership.stories;
|
|
|
|
var max = Math.min(stories.size(), Number(limit) || Infinity, 20);
|
|
|
|
for each (var story in stories.list(0, max)) {
|
|
|
|
result.push({
|
|
|
|
postid: story._id,
|
|
|
|
username: story.creator.name,
|
|
|
|
dateCreated: story.created,
|
|
|
|
title: story.getTitle()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Number} id
|
|
|
|
* @param {String} name
|
|
|
|
* @param {String} password
|
|
|
|
* @throws {Error}
|
|
|
|
* @returns {Object[]}
|
|
|
|
*/
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt.getCategoryList = function(id, name, password) {
|
2008-06-05 12:08:00 +00:00
|
|
|
var site = Api.getSite(id);
|
2008-06-05 14:47:21 +00:00
|
|
|
var user = Api.getUser(name, password);
|
2008-06-05 12:08:00 +00:00
|
|
|
|
2008-06-05 14:47:21 +00:00
|
|
|
Api.constrain(site, user);
|
2008-06-05 12:08:00 +00:00
|
|
|
if (!site.stories.getPermission("main")) {
|
|
|
|
throw Error("Permission denied for user " + user.name +
|
|
|
|
" to access site " + site.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = [];
|
|
|
|
var tags = site.getTags("tags", Tags.ALL).list();
|
|
|
|
for each (var tag in tags) {
|
|
|
|
result.push({
|
|
|
|
categoryId: tag.name, // FIXME: tag._id,
|
|
|
|
categoryName: tag.name
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Number} id
|
|
|
|
* @param {String} name
|
|
|
|
* @param {String} password
|
|
|
|
* @throws {Error}
|
|
|
|
* @returns {Object[]}
|
|
|
|
*/
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt.getPostCategories = function(id, name, password) {
|
2008-06-05 14:47:21 +00:00
|
|
|
var story = Api.getStory(id);
|
2008-06-05 12:08:00 +00:00
|
|
|
var user = Api.getUser(name, password);
|
|
|
|
|
2008-06-05 14:47:21 +00:00
|
|
|
Api.constrain(story.site, user);
|
2008-06-05 12:08:00 +00:00
|
|
|
if (!story.getPermission("main")) {
|
|
|
|
throw Error("Permission denied for user " + name +
|
|
|
|
" to access story #" + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = [];
|
|
|
|
for each (var tag in story.getTags()) {
|
|
|
|
result.push({
|
|
|
|
categoryId: tag,
|
|
|
|
categoryName: tag,
|
|
|
|
isPrimary: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: What kind of stupid API is this?
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Number} id
|
|
|
|
* @param {String} name
|
|
|
|
* @param {String} password
|
|
|
|
* @throws {Error}
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt.publishPost = function(id, name, password) {
|
2008-06-05 14:47:21 +00:00
|
|
|
var story = Api.getStory(id);
|
2008-06-05 12:08:00 +00:00
|
|
|
var user = Api.getUser(name, password);
|
|
|
|
|
2008-06-05 14:47:21 +00:00
|
|
|
Api.constrain(story.site, user);
|
2008-06-05 12:08:00 +00:00
|
|
|
if (!story.getPermission("edit")) {
|
|
|
|
throw Error("Permission denied for user " + name +
|
|
|
|
" to edit story #" + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
story.mode = Story.FEATURED;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Number} id
|
|
|
|
* @param {String} name
|
|
|
|
* @param {String} password
|
|
|
|
* @param {String[]} categories
|
|
|
|
* @throws {Error}
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt.setPostCategories = function(id, name, password, categories) {
|
2008-06-05 12:08:00 +00:00
|
|
|
if (!categories || !categories.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-05 14:47:21 +00:00
|
|
|
var story = Api.getStory(id);
|
2008-06-05 12:08:00 +00:00
|
|
|
var user = Api.getUser(name, password);
|
|
|
|
|
2008-06-05 14:47:21 +00:00
|
|
|
Api.constrain(story.site, user);
|
2008-06-05 12:08:00 +00:00
|
|
|
if (!story.getPermission("edit")) {
|
|
|
|
throw Error("Permission denied for user " + name +
|
|
|
|
" to edit story #" + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
story.setTags(categories);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt.supportedTextFilters = function() {
|
2008-06-05 12:08:00 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt.getTrackbackPings = function() {
|
2008-06-05 12:08:00 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {String[]}
|
|
|
|
*/
|
2008-06-12 19:50:02 +00:00
|
|
|
Api.mt.supportedMethods = function() {
|
2008-06-05 12:08:00 +00:00
|
|
|
var result = [];
|
2008-06-12 19:50:02 +00:00
|
|
|
for (var method in Api.mt) {
|
2008-06-05 12:08:00 +00:00
|
|
|
result.push(method);
|
|
|
|
}
|
|
|
|
return result.sort();
|
|
|
|
}
|