4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2005 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
13 * $Id: api_mt.inc.php,v 1.3 2005-03-12 06:19:06 kimitake Exp $
\r
18 * This file contains definitions for the methods in the Movable Type API
\r
20 * Wouter Demuynck 2003-08-31
\r
24 // mt.supportedMethods
\r
25 $f_mt_supportedMethods_sig = array(array(
\r
27 $xmlrpcArray // array of strings
\r
29 $f_mt_supportedMethods_doc = 'returns an array of supported methods';
\r
30 function f_mt_supportedMethods($m) {
\r
31 $res = new xmlrpcresp(new xmlrpcval(
\r
33 new xmlrpcval('mt.supportedMethods', 'string'),
\r
34 new xmlrpcval('mt.supportedTextFilters', 'string'),
\r
35 new xmlrpcval('mt.publishPost', 'string'),
\r
36 new xmlrpcval('mt.getCategoryList', 'string'),
\r
37 new xmlrpcval('mt.getPostCategories', 'string'),
\r
38 new xmlrpcval('mt.setPostCategories', 'string'),
\r
39 new xmlrpcval('mt.getRecentPostTitles', 'string'),
\r
40 new xmlrpcval('mt.getTrackbackPings','string'),
\r
46 // mt.supportedTextFilters
\r
47 $f_mt_supportedTextFilters_sig = array(array(
\r
49 $xmlrpcArray // array of structs
\r
51 $f_mt_supportedTextFilters_doc = 'returns the supported text filters';
\r
52 function f_mt_supportedTextFilters($m) {
\r
53 $res = new xmlrpcresp(new xmlrpcval(
\r
55 // no text filters in nucleus
\r
61 // mt.getCategoryList
\r
62 $f_mt_getCategoryList_sig = array(array(
\r
64 $xmlrpcArray, // array of structs
\r
67 $xmlrpcString, // blogid
\r
68 $xmlrpcString, // username
\r
69 $xmlrpcString // password
\r
72 $f_mt_getCategoryList_doc = 'Returns a list of all categories defined in the weblog';
\r
73 function f_mt_getCategoryList($m) {
\r
74 $blogid = _getScalar($m,0);
\r
75 $username = _getScalar($m,1);
\r
76 $password = _getScalar($m,2);
\r
78 return _mt_categoryList($blogid, $username, $password);
\r
82 $f_mt_publishPost_sig = array(array(
\r
84 $xmlrpcBoolean, // true
\r
87 $xmlrpcString, // itemid
\r
88 $xmlrpcString, // username
\r
89 $xmlrpcString // password
\r
91 $f_mt_publishPost_doc = 'Transfers an item from the "draft" state to the "published" state. For items that were published earlier, does nothing.';
\r
92 function f_mt_publishPost($m) {
\r
93 $itemid = intval(_getScalar($m, 0));
\r
94 $username = _getScalar($m, 1);
\r
95 $password = _getScalar($m, 2);
\r
97 return _mt_publishPost($itemid, $username, $password);
\r
100 // mt.getPostCategories
\r
101 $f_mt_getPostCategories_sig = array(array(
\r
103 $xmlrpcArray, // array of structs
\r
105 $xmlrpcString, // itemid
\r
106 $xmlrpcString, // username
\r
107 $xmlrpcString // password
\r
109 $f_mt_getPostCategories_doc = 'Returns a list of all categories to which the post is assigned.';
\r
110 function f_mt_getPostCategories($m) {
\r
111 $itemid = intval(_getScalar($m, 0));
\r
112 $username = _getScalar($m, 1);
\r
113 $password = _getScalar($m, 2);
\r
115 return _mt_getPostCategories($itemid, $username, $password);
\r
118 // mt.setPostCategories
\r
119 $f_mt_setPostCategories_sig = array(array(
\r
121 $xmlrpcBoolean, // true
\r
123 $xmlrpcString, // itemid
\r
124 $xmlrpcString, // username
\r
125 $xmlrpcString, // password
\r
126 $xmlrpcArray // categories
\r
128 $f_mt_setPostCategories_doc = 'Sets the categories for a post. Only the primary category will be stored';
\r
129 function f_mt_setPostCategories($m) {
\r
130 $itemid = intval(_getScalar($m, 0));
\r
131 $username = _getScalar($m, 1);
\r
132 $password = _getScalar($m, 2);
\r
134 $categories = $m->getParam(3);
\r
135 $iSize = $categories->arraysize();
\r
138 for ($i=0;$i<$iSize;$i++) {
\r
139 $struct = $categories->arraymem($i);
\r
140 $bPrimary = $struct->structmem('isPrimary');
\r
142 $bPrimary = $bPrimary->scalarval();
\r
143 else if (!$category)
\r
144 $bPrimary = 1; // "Using isPrimary to set the primary category is optional--
\r
145 // in the absence of this flag, the first struct in the array
\r
146 // will be assigned the primary category for the post." (MT doc)
\r
148 $category = $struct->structmem('categoryId');
\r
149 $category = $category->scalarval();
\r
154 return _mt_setPostCategories($itemid, $username, $password, $category);
\r
157 // mt.getRecentPostTitles
\r
158 $f_mt_getRecentPostTitles_sig = array(array(
\r
160 $xmlrpcArray, // array of structs
\r
162 $xmlrpcString, // blogid
\r
163 $xmlrpcString, // userid
\r
164 $xmlrpcString, // password,
\r
165 $xmlrpcInt // number of posts
\r
167 $f_mt_getRecentPostTitles_doc = 'Returns a bandwidth-friendly list of the most recent posts in the system.';
\r
168 function f_mt_getRecentPostTitles($m) {
\r
169 $blogid = intval(_getScalar($m, 0));
\r
170 $username = _getScalar($m, 1);
\r
171 $password = _getScalar($m, 2);
\r
172 $iAmount = intval(_getScalar($m, 3));
\r
174 return _mt_getRecentPostTitles($blogid, $username, $password, $iAmount);
\r
177 // mt.getTrackbackPings
\r
178 $f_mt_getTrackbackPings_sig = array(array(
\r
180 $xmlrpcArray, // array of structs
\r
182 $xmlrpcString // postid
\r
184 $f_mt_getTrackbackPings_doc = '(this is currently just a placeholder. It returns an empty array.)';
\r
185 function f_mt_getTrackbackPings($m) {
\r
186 $itemid = intval(_getScalar($m, 0));
\r
188 return new xmlrpcresp(new xmlrpcval(array(), 'array'));
\r
191 $functionDefs = array_merge($functionDefs,
\r
193 "mt.supportedMethods" =>
\r
194 array( "function" => "f_mt_supportedMethods",
\r
195 "signature" => $f_mt_supportedMethods_sig,
\r
196 "docstring" => $f_mt_supportedMethods_doc),
\r
198 "mt.supportedTextFilters" =>
\r
199 array( "function" => "f_mt_supportedTextFilters",
\r
200 "signature" => $f_mt_supportedTextFilters_sig,
\r
201 "docstring" => $f_mt_supportedTextFilters_doc),
\r
203 "mt.getCategoryList" =>
\r
204 array( "function" => "f_mt_getCategoryList",
\r
205 "signature" => $f_mt_getCategoryList_sig,
\r
206 "docstring" => $f_mt_getCategoryList_doc),
\r
208 "mt.publishPost" =>
\r
209 array( "function" => "f_mt_publishPost",
\r
210 "signature" => $f_mt_publishPost_sig,
\r
211 "docstring" => $f_mt_publishPost_doc),
\r
213 "mt.getPostCategories" =>
\r
214 array( "function" => "f_mt_getPostCategories",
\r
215 "signature" => $f_mt_getPostCategories_sig,
\r
216 "docstring" => $f_mt_getPostCategories_doc),
\r
218 "mt.setPostCategories" =>
\r
219 array( "function" => "f_mt_setPostCategories",
\r
220 "signature" => $f_mt_setPostCategories_sig,
\r
221 "docstring" => $f_mt_setPostCategories_doc),
\r
223 "mt.getRecentPostTitles" =>
\r
224 array( "function" => "f_mt_getRecentPostTitles",
\r
225 "signature" => $f_mt_getRecentPostTitles_sig,
\r
226 "docstring" => $f_mt_getRecentPostTitles_doc),
\r
228 "mt.getTrackbackPings" =>
\r
229 array( "function" => "f_mt_getTrackbackPings",
\r
230 "signature" => $f_mt_getTrackbackPings_sig,
\r
231 "docstring" => $f_mt_getTrackbackPings_doc)
\r
236 function _mt_setPostCategories($itemid, $username, $password, $category) {
\r
240 $mem = new MEMBER();
\r
241 if (!$mem->login($username, $password))
\r
242 return _error(1,"Could not log in");
\r
244 // check if item exists
\r
245 if (!$manager->existsItem($itemid,1,1))
\r
246 return _error(6,"No such item ($itemid)");
\r
248 $blogid = getBlogIDFromItemID($itemid);
\r
249 $blog = new BLOG($blogid);
\r
251 if (!$mem->canAlterItem($itemid))
\r
252 return _error(7,"Not allowed to alter item");
\r
254 $old =& $manager->getItem($itemid,1,1);
\r
256 $catid = $blog->getCategoryIdFromName($category);
\r
259 if ($old['draft'] && $publish) {
\r
266 return _edititem($itemid, $username, $password, $catid, $old['title'], $old['body'], $old['more'], $wasdraft, $publish, $old['closed']);
\r
270 function _mt_getPostCategories($itemid, $username, $password) {
\r
274 $mem = new MEMBER();
\r
275 if (!$mem->login($username, $password))
\r
276 return _error(1,"Could not log in");
\r
278 // check if item exists
\r
279 if (!$manager->existsItem($itemid,1,1))
\r
280 return _error(6,"No such item ($itemid)");
\r
282 $blogid = getBlogIDFromItemID($itemid);
\r
283 $blog = new BLOG($blogid);
\r
285 if (!$mem->canAlterItem($itemid))
\r
286 return _error(7, 'You are not allowed to request this information');
\r
288 $info =& $manager->getItem($itemid,1,1);
\r
289 $catName = $blog->getCategoryName($info['catid']);
\r
291 $struct = new xmlrpcval(
\r
293 'categoryId' => new xmlrpcval($catName, 'string'),
\r
294 'categoryName' => new xmlrpcval($catName, 'string'),
\r
295 'isPrimary' => new xmlrpcval(1, 'boolean')
\r
299 return new xmlrpcresp(new xmlrpcval(array($struct), 'array'));
\r
303 function _mt_publishPost($itemid, $username, $password) {
\r
306 if (!$manager->existsItem($itemid,1,1))
\r
307 return _error(6,"No such item ($itemid)");
\r
310 $blogid = getBlogIDFromItemID($itemid);
\r
311 $blog = new BLOG($blogid);
\r
312 $old =& $manager->getItem($itemid,1,1);
\r
314 return _edititem($itemid, $username, $password, $old['catid'], $old['title'], $old['body'], $old['more'], $old['draft'], 1, $old['closed']);
\r
318 function _mt_categoryList($blogid, $username, $password) {
\r
320 $mem = new MEMBER();
\r
321 if (!$mem->login($username, $password))
\r
322 return _error(1,"Could not log in");
\r
324 // check if on team and blog exists
\r
325 if (!BLOG::existsID($blogid))
\r
326 return _error(2,"No such blog ($blogid)");
\r
327 if (!$mem->teamRights($blogid))
\r
328 return _error(3,"Not a team member");
\r
330 $b = new BLOG($blogid);
\r
332 $categorystruct = array();
\r
334 $query = "SELECT cname, cdesc, catid"
\r
335 . ' FROM '.sql_table('category')
\r
336 . " WHERE cblog=" . intval($blogid)
\r
337 . " ORDER BY cname";
\r
338 $r = sql_query($query);
\r
340 while ($obj = mysql_fetch_object($r)) {
\r
342 $categorystruct[] = new xmlrpcval(
\r
344 "categoryName" => new xmlrpcval($obj->cname,"string"),
\r
345 "categoryId" => new xmlrpcval($obj->cname,"string")
\r
352 return new xmlrpcresp(new xmlrpcval( $categorystruct , "array"));
\r
356 function _mt_getRecentPostTitles($blogid, $username, $password, $iAmount)
\r
358 $blogid = intval($blogid);
\r
359 $iAmount = intval($iAmount);
\r
362 $mem = new MEMBER();
\r
363 if (!$mem->login($username, $password))
\r
364 return _error(1,"Could not log in");
\r
366 // 2. check if allowed
\r
367 if (!BLOG::existsID($blogid))
\r
368 return _error(2,"No such blog ($blogid)");
\r
369 if (!$mem->teamRights($blogid))
\r
370 return _error(3,"Not a team member");
\r
371 $iAmount = intval($iAmount);
\r
373 return _error(5,"Amount parameter must be positive");
\r
375 // 3. create and return list of recent items
\r
376 // Struct returned has dateCreated, userid, postid and title
\r
378 $blog = new BLOG($blogid);
\r
380 $structarray = array(); // the array in which the structs will be stored
\r
382 $query = "SELECT inumber, ititle as title, itime, iauthor"
\r
383 .' FROM '.sql_table('item')
\r
384 ." WHERE iblog=$blogid"
\r
385 ." ORDER BY itime DESC"
\r
386 ." LIMIT $iAmount";
\r
387 $r = sql_query($query);
\r
389 while ($row = mysql_fetch_assoc($r)) {
\r
391 $newstruct = new xmlrpcval(array(
\r
392 "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
\r
393 "postid" => new xmlrpcval($row['inumber'],"string"),
\r
394 "title" => new xmlrpcval($row['title'],"string"),
\r
395 "userid" => new xmlrpcval($row['iauthor'],"string")
\r
398 array_push($structarray, $newstruct);
\r
401 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
\r