1 // The Antville Project 2 // http://code.google.com/p/antville 3 // 4 // Copyright 2007-2011 by Tobi Schäfer. 5 // 6 // Copyright 2001–2007 Robert Gaggl, Hannes Wallnöfer, Tobi Schäfer, 7 // Matthias & Michael Platzer, Christoph Lincke. 8 // 9 // Licensed under the Apache License, Version 2.0 (the ``License''); 10 // you may not use this file except in compliance with the License. 11 // You may obtain a copy of the License at 12 // 13 // http://www.apache.org/licenses/LICENSE-2.0 14 // 15 // Unless required by applicable law or agreed to in writing, software 16 // distributed under the License is distributed on an ``AS IS'' BASIS, 17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 // See the License for the specific language governing permissions and 19 // limitations under the License. 20 // 21 // $Revision$ 22 // $Author$ 23 // $Date$ 24 // $URL$ 25 26 /** 27 * @fileOverview Methods that implement Movable Type's XML-RPC API. 28 * See http://www.sixapart.com/pronet/breese/xmlrpc/movable_type_api/ for details. 29 */ 30 31 /** @namespace */ 32 Api.mt = {}; 33 34 /** 35 * 36 * @param {Number} id 37 * @param {String} name 38 * @param {String} password 39 * @param {Number} limit 40 * @throws {Error} 41 * @returns {Object[]} 42 */ 43 Api.mt.getRecentPostTitles = function(id, name, password, limit) { 44 var site = Api.getSite(id); 45 var user = Api.getUser(name, password); 46 47 Api.constrain(site, user); 48 if (!site.stories.getPermission("main")) { 49 throw Error("Permission denied for user " + user.name + 50 " to get recent post titles from site " + site.name); 51 } 52 53 var result = []; 54 var stories = res.handlers.membership.stories; 55 var max = Math.min(stories.size(), Number(limit) || Infinity, 20); 56 for each (var story in stories.list(0, max)) { 57 result.push({ 58 postid: story._id, 59 username: story.creator.name, 60 dateCreated: story.created, 61 title: story.getTitle() 62 }); 63 } 64 return result; 65 } 66 67 /** 68 * 69 * @param {Number} id 70 * @param {String} name 71 * @param {String} password 72 * @throws {Error} 73 * @returns {Object[]} 74 */ 75 Api.mt.getCategoryList = function(id, name, password) { 76 var site = Api.getSite(id); 77 var user = Api.getUser(name, password); 78 79 Api.constrain(site, user); 80 if (!site.stories.getPermission("main")) { 81 throw Error("Permission denied for user " + user.name + 82 " to access site " + site.name); 83 } 84 85 var result = []; 86 var tags = site.getTags("tags", Tags.ALL).list(); 87 for each (var tag in tags) { 88 result.push({ 89 categoryId: tag.name, // FIXME: tag._id, 90 categoryName: tag.name 91 }); 92 } 93 return result; 94 } 95 96 /** 97 * 98 * @param {Number} id 99 * @param {String} name 100 * @param {String} password 101 * @throws {Error} 102 * @returns {Object[]} 103 */ 104 Api.mt.getPostCategories = function(id, name, password) { 105 var story = Api.getStory(id); 106 var user = Api.getUser(name, password); 107 108 Api.constrain(story.site, user); 109 if (!story.getPermission("main")) { 110 throw Error("Permission denied for user " + name + 111 " to access story #" + id); 112 } 113 114 var result = []; 115 for each (var tag in story.getTags()) { 116 result.push({ 117 categoryId: tag, 118 categoryName: tag, 119 isPrimary: true 120 }); 121 } 122 return result; 123 } 124 125 // FIXME: How do I post a new story? 126 /** 127 * 128 * @param {Number} id 129 * @param {String} name 130 * @param {String} password 131 * @throws {Error} 132 * @returns {Boolean} 133 */ 134 Api.mt.publishPost = function(id, name, password) { 135 var story = Api.getStory(id); 136 var user = Api.getUser(name, password); 137 138 Api.constrain(story.site, user); 139 if (!story.getPermission("edit")) { 140 throw Error("Permission denied for user " + name + 141 " to edit story #" + id); 142 } 143 144 story.mode = Story.FEATURED; 145 return true; 146 } 147 148 /** 149 * 150 * @param {Number} id 151 * @param {String} name 152 * @param {String} password 153 * @param {String[]} categories 154 * @throws {Error} 155 * @returns {Boolean} 156 */ 157 Api.mt.setPostCategories = function(id, name, password, categories) { 158 if (!categories || !categories.length) { 159 return; 160 } 161 162 var story = Api.getStory(id); 163 var user = Api.getUser(name, password); 164 165 Api.constrain(story.site, user); 166 if (!story.getPermission("edit")) { 167 throw Error("Permission denied for user " + name + 168 " to edit story #" + id); 169 } 170 171 story.setTags(categories); 172 return true; 173 } 174 175 /** 176 * 177 * @returns {Array} 178 */ 179 Api.mt.supportedTextFilters = function() { 180 return []; 181 } 182 183 /** 184 * 185 * @returns {Array} 186 */ 187 Api.mt.getTrackbackPings = function() { 188 return []; 189 } 190 191 /** 192 * 193 * @returns {String[]} 194 */ 195 Api.mt.supportedMethods = function() { 196 var result = []; 197 for (var method in Api.mt) { 198 result.push(method); 199 } 200 return result.sort(); 201 } 202