antville/code/Api/Api.mt.js

201 lines
4.5 KiB
JavaScript
Raw Normal View History

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$
//
/**
* @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
/** @namespace */
Api.mt = {};
2008-06-05 12:08:00 +00:00
/**
*
* @param {Number} id
* @param {String} name
* @param {String} password
* @param {Number} limit
* @throws {Error}
* @returns {Object[]}
*/
Api.mt.getRecentPostTitles = function(id, name, password, limit) {
2008-06-05 12:08:00 +00:00
var site = Api.getSite(id);
var user = Api.getUser(name, password);
2008-06-05 12:08:00 +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 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;
}
/**
*
* @param {Number} id
* @param {String} name
* @param {String} password
* @throws {Error}
* @returns {Object[]}
*/
Api.mt.getCategoryList = function(id, name, password) {
2008-06-05 12:08:00 +00:00
var site = Api.getSite(id);
var user = Api.getUser(name, password);
2008-06-05 12:08:00 +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;
}
/**
*
* @param {Number} id
* @param {String} name
* @param {String} password
* @throws {Error}
* @returns {Object[]}
*/
Api.mt.getPostCategories = function(id, name, password) {
var story = Api.getStory(id);
2008-06-05 12:08:00 +00:00
var user = Api.getUser(name, password);
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?
/**
*
* @param {Number} id
* @param {String} name
* @param {String} password
* @throws {Error}
* @returns {Boolean}
*/
Api.mt.publishPost = function(id, name, password) {
var story = Api.getStory(id);
2008-06-05 12:08:00 +00:00
var user = Api.getUser(name, password);
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;
}
/**
*
* @param {Number} id
* @param {String} name
* @param {String} password
* @param {String[]} categories
* @throws {Error}
* @returns {Boolean}
*/
Api.mt.setPostCategories = function(id, name, password, categories) {
2008-06-05 12:08:00 +00:00
if (!categories || !categories.length) {
return;
}
var story = Api.getStory(id);
2008-06-05 12:08:00 +00:00
var user = Api.getUser(name, password);
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;
}
/**
*
* @returns {Array}
*/
Api.mt.supportedTextFilters = function() {
2008-06-05 12:08:00 +00:00
return [];
}
/**
*
* @returns {Array}
*/
Api.mt.getTrackbackPings = function() {
2008-06-05 12:08:00 +00:00
return [];
}
/**
*
* @returns {String[]}
*/
Api.mt.supportedMethods = function() {
2008-06-05 12:08:00 +00:00
var result = [];
for (var method in Api.mt) {
2008-06-05 12:08:00 +00:00
result.push(method);
}
return result.sort();
}