4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2009 The Nucleus Group
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * (see nucleus/documentation/index.html#license for more info)
14 * This file contains definitions for the methods in the Movable Type API
16 * Wouter Demuynck 2003-08-31
18 * @license http://nucleuscms.org/license.txt GNU General Public License
19 * @copyright Copyright (C) 2002-2009 The Nucleus Group
20 * @version $Id: api_mt.inc.php 1860 2012-05-19 03:47:59Z sakamocchi $
23 // mt.supportedMethods
24 $f_mt_supportedMethods_sig = array(array(
26 $xmlrpcArray // array of strings
28 $f_mt_supportedMethods_doc = 'returns an array of supported methods';
29 function f_mt_supportedMethods($m) {
30 $res = new xmlrpcresp(new xmlrpcval(
32 new xmlrpcval('mt.supportedMethods', 'string'),
33 new xmlrpcval('mt.supportedTextFilters', 'string'),
34 new xmlrpcval('mt.publishPost', 'string'),
35 new xmlrpcval('mt.getCategoryList', 'string'),
36 new xmlrpcval('mt.getPostCategories', 'string'),
37 new xmlrpcval('mt.setPostCategories', 'string'),
38 new xmlrpcval('mt.getRecentPostTitles', 'string'),
39 new xmlrpcval('mt.getTrackbackPings','string'),
45 // mt.supportedTextFilters
46 $f_mt_supportedTextFilters_sig = array(array(
48 $xmlrpcArray // array of structs
50 $f_mt_supportedTextFilters_doc = 'returns the supported text filters';
51 function f_mt_supportedTextFilters($m) {
52 $res = new xmlrpcresp(new xmlrpcval(
54 // no text filters in nucleus
61 $f_mt_getCategoryList_sig = array(array(
63 $xmlrpcArray, // array of structs
66 $xmlrpcString, // blogid
67 $xmlrpcString, // username
68 $xmlrpcString // password
71 $f_mt_getCategoryList_doc = 'Returns a list of all categories defined in the weblog';
72 function f_mt_getCategoryList($m) {
73 $blogid = _getScalar($m,0);
74 $username = _getScalar($m,1);
75 $password = _getScalar($m,2);
77 return _mt_categoryList($blogid, $username, $password);
81 $f_mt_publishPost_sig = array(array(
83 $xmlrpcBoolean, // true
86 $xmlrpcString, // itemid
87 $xmlrpcString, // username
88 $xmlrpcString // password
90 $f_mt_publishPost_doc = 'Transfers an item from the "draft" state to the "published" state. For items that were published earlier, does nothing.';
91 function f_mt_publishPost($m) {
92 $itemid = intval(_getScalar($m, 0));
93 $username = _getScalar($m, 1);
94 $password = _getScalar($m, 2);
96 return _mt_publishPost($itemid, $username, $password);
99 // mt.getPostCategories
100 $f_mt_getPostCategories_sig = array(array(
102 $xmlrpcArray, // array of structs
104 $xmlrpcString, // itemid
105 $xmlrpcString, // username
106 $xmlrpcString // password
108 $f_mt_getPostCategories_doc = 'Returns a list of all categories to which the post is assigned.';
109 function f_mt_getPostCategories($m) {
110 $itemid = intval(_getScalar($m, 0));
111 $username = _getScalar($m, 1);
112 $password = _getScalar($m, 2);
114 return _mt_getPostCategories($itemid, $username, $password);
117 // mt.setPostCategories
118 $f_mt_setPostCategories_sig = array(array(
120 $xmlrpcBoolean, // true
122 $xmlrpcString, // itemid
123 $xmlrpcString, // username
124 $xmlrpcString, // password
125 $xmlrpcArray // categories
127 $f_mt_setPostCategories_doc = 'Sets the categories for a post. Only the primary category will be stored';
128 function f_mt_setPostCategories($m) {
129 $itemid = intval(_getScalar($m, 0));
130 $username = _getScalar($m, 1);
131 $password = _getScalar($m, 2);
133 $categories = $m->getParam(3);
134 $iSize = $categories->arraysize();
137 for ($i=0;$i<$iSize;$i++) {
138 $struct = $categories->arraymem($i);
139 $bPrimary = $struct->structmem('isPrimary');
141 $bPrimary = $bPrimary->scalarval();
143 $bPrimary = 1; // "Using isPrimary to set the primary category is optional--
144 // in the absence of this flag, the first struct in the array
145 // will be assigned the primary category for the post." (MT doc)
147 $category = $struct->structmem('categoryId');
148 $category = $category->scalarval();
153 return _mt_setPostCategories($itemid, $username, $password, $category);
156 // mt.getRecentPostTitles
157 $f_mt_getRecentPostTitles_sig = array(array(
159 $xmlrpcArray, // array of structs
161 $xmlrpcString, // blogid
162 $xmlrpcString, // userid
163 $xmlrpcString, // password,
164 $xmlrpcInt // number of posts
166 $f_mt_getRecentPostTitles_doc = 'Returns a bandwidth-friendly list of the most recent posts in the system.';
167 function f_mt_getRecentPostTitles($m) {
168 $blogid = intval(_getScalar($m, 0));
169 $username = _getScalar($m, 1);
170 $password = _getScalar($m, 2);
171 $iAmount = intval(_getScalar($m, 3));
173 return _mt_getRecentPostTitles($blogid, $username, $password, $iAmount);
176 // mt.getTrackbackPings
177 $f_mt_getTrackbackPings_sig = array(array(
179 $xmlrpcArray, // array of structs
181 $xmlrpcString // postid
183 $f_mt_getTrackbackPings_doc = '(this is currently just a placeholder. It returns an empty array.)';
184 function f_mt_getTrackbackPings($m) {
187 $itemid = intval(_getScalar($m, 0));
189 $trackbacks = array ();
190 $tbstruct = array ();
192 $data = array('tb_id' => $itemid, 'trackbacks' => &$trackbacks);
193 $manager->notify('RetrieveTrackback', $data);
195 while (list(,$v) = each ($trackbacks)) {
196 $tbstruct[] = new xmlrpcval(
198 "pingTitle" => new xmlrpcval($v['title'], "string"),
199 "pingURL" => new xmlrpcval($v['url'], "string"),
200 "pingIP" => new xmlrpcval($v['ip'], "string")
205 return new xmlrpcresp(new xmlrpcval( $tbstruct , "array"));
208 $functionDefs = array_merge($functionDefs,
210 "mt.supportedMethods" =>
211 array( "function" => "f_mt_supportedMethods",
212 "signature" => $f_mt_supportedMethods_sig,
213 "docstring" => $f_mt_supportedMethods_doc),
215 "mt.supportedTextFilters" =>
216 array( "function" => "f_mt_supportedTextFilters",
217 "signature" => $f_mt_supportedTextFilters_sig,
218 "docstring" => $f_mt_supportedTextFilters_doc),
220 "mt.getCategoryList" =>
221 array( "function" => "f_mt_getCategoryList",
222 "signature" => $f_mt_getCategoryList_sig,
223 "docstring" => $f_mt_getCategoryList_doc),
226 array( "function" => "f_mt_publishPost",
227 "signature" => $f_mt_publishPost_sig,
228 "docstring" => $f_mt_publishPost_doc),
230 "mt.getPostCategories" =>
231 array( "function" => "f_mt_getPostCategories",
232 "signature" => $f_mt_getPostCategories_sig,
233 "docstring" => $f_mt_getPostCategories_doc),
235 "mt.setPostCategories" =>
236 array( "function" => "f_mt_setPostCategories",
237 "signature" => $f_mt_setPostCategories_sig,
238 "docstring" => $f_mt_setPostCategories_doc),
240 "mt.getRecentPostTitles" =>
241 array( "function" => "f_mt_getRecentPostTitles",
242 "signature" => $f_mt_getRecentPostTitles_sig,
243 "docstring" => $f_mt_getRecentPostTitles_doc),
245 "mt.getTrackbackPings" =>
246 array( "function" => "f_mt_getTrackbackPings",
247 "signature" => $f_mt_getTrackbackPings_sig,
248 "docstring" => $f_mt_getTrackbackPings_doc)
253 function _mt_setPostCategories($itemid, $username, $password, $category) {
258 if (!$mem->login($username, $password))
259 return _error(1,"Could not log in");
261 // check if item exists
262 if (!$manager->existsItem($itemid,1,1))
263 return _error(6,"No such item ($itemid)");
265 $blogid = getBlogIDFromItemID($itemid);
266 $blog =& $manager->getBlog($blogid);
268 if (!$mem->canAlterItem($itemid))
269 return _error(7,"Not allowed to alter item");
271 $old =& $manager->getItem($itemid,1,1);
273 $catid = $blog->getCategoryIdFromName($category);
276 if ($old['draft'] && $publish) {
283 return _edititem($itemid, $username, $password, $catid, $old['title'], $old['body'], $old['more'], $wasdraft, $publish, $old['closed']);
287 function _mt_getPostCategories($itemid, $username, $password) {
292 if (!$mem->login($username, $password))
293 return _error(1,"Could not log in");
295 // check if item exists
296 if (!$manager->existsItem($itemid,1,1))
297 return _error(6,"No such item ($itemid)");
299 $blogid = getBlogIDFromItemID($itemid);
300 $blog =& $manager->getBlog($blogid);
302 if (!$mem->canAlterItem($itemid))
303 return _error(7, 'You are not allowed to request this information');
305 $info =& $manager->getItem($itemid,1,1);
306 $catName = $blog->getCategoryName($info['catid']);
308 $struct = new xmlrpcval(
310 'categoryId' => new xmlrpcval($catName, 'string'),
311 'categoryName' => new xmlrpcval($catName, 'string'),
312 'isPrimary' => new xmlrpcval(1, 'boolean')
316 return new xmlrpcresp(new xmlrpcval(array($struct), 'array'));
320 function _mt_publishPost($itemid, $username, $password) {
323 if (!$manager->existsItem($itemid,1,1))
324 return _error(6,"No such item ($itemid)");
327 $blogid = getBlogIDFromItemID($itemid);
328 $blog =& $manager->getBlog($blogid);
329 $old =& $manager->getItem($itemid,1,1);
331 return _edititem($itemid, $username, $password, $old['catid'], $old['title'], $old['body'], $old['more'], $old['draft'], 1, $old['closed']);
335 function _mt_categoryList($blogid, $username, $password) {
339 if (!$mem->login($username, $password))
340 return _error(1,"Could not log in");
342 // check if on team and blog exists
343 if (!Blog::existsID($blogid))
344 return _error(2,"No such blog ($blogid)");
345 if (!$mem->teamRights($blogid))
346 return _error(3,"Not a team member");
348 $b =& $manager->getBlog($blogid);
350 $categorystruct = array();
352 $query = "SELECT cname, cdesc, catid"
353 . ' FROM '.sql_table('category')
354 . " WHERE cblog=" . intval($blogid)
356 $r = DB::getResult($query);
358 foreach ( $r as $row ) {
360 $categorystruct[] = new xmlrpcval(
362 "categoryName" => new xmlrpcval($row['cname'],"string"),
363 "categoryId" => new xmlrpcval($row['cname'],"string")
370 return new xmlrpcresp(new xmlrpcval( $categorystruct , "array"));
374 function _mt_getRecentPostTitles($blogid, $username, $password, $iAmount)
378 $blogid = intval($blogid);
379 $iAmount = intval($iAmount);
383 if (!$mem->login($username, $password))
384 return _error(1,"Could not log in");
386 // 2. check if allowed
387 if (!Blog::existsID($blogid))
388 return _error(2,"No such blog ($blogid)");
389 if (!$mem->teamRights($blogid))
390 return _error(3,"Not a team member");
391 $iAmount = intval($iAmount);
393 return _error(5,"Amount parameter must be positive");
395 // 3. create and return list of recent items
396 // Struct returned has dateCreated, userid, postid and title
398 $blog =& $manager->getBlog($blogid);
400 $structarray = array(); // the array in which the structs will be stored
402 $query = "SELECT inumber, ititle as title, itime, iauthor"
403 .' FROM '.sql_table('item')
404 ." WHERE iblog=$blogid"
405 ." ORDER BY itime DESC"
407 $r = DB::getResult($query);
409 foreach ( $r as $row ) {
411 $newstruct = new xmlrpcval(array(
412 "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
413 "postid" => new xmlrpcval($row['inumber'],"string"),
414 "title" => new xmlrpcval($row['title'],"string"),
415 "userid" => new xmlrpcval($row['iauthor'],"string")
418 array_push($structarray, $newstruct);
421 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));