4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2013 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)
13 * This file contains definitions for the methods in the Movable Type API
15 * Wouter Demuynck 2003-08-31
18 // mt.supportedMethods
19 $f_mt_supportedMethods_sig = array(array(
21 $xmlrpcArray // array of strings
23 $f_mt_supportedMethods_doc = 'returns an array of supported methods';
24 function f_mt_supportedMethods($m) {
25 $res = new xmlrpcresp(new xmlrpcval(
27 new xmlrpcval('mt.supportedMethods', 'string'),
28 new xmlrpcval('mt.supportedTextFilters', 'string'),
29 new xmlrpcval('mt.publishPost', 'string'),
30 new xmlrpcval('mt.getCategoryList', 'string'),
31 new xmlrpcval('mt.getPostCategories', 'string'),
32 new xmlrpcval('mt.setPostCategories', 'string'),
33 new xmlrpcval('mt.getRecentPostTitles', 'string'),
34 new xmlrpcval('mt.getTrackbackPings','string'),
40 // mt.supportedTextFilters
41 $f_mt_supportedTextFilters_sig = array(array(
43 $xmlrpcArray // array of structs
45 $f_mt_supportedTextFilters_doc = 'returns the supported text filters';
46 function f_mt_supportedTextFilters($m) {
47 $res = new xmlrpcresp(new xmlrpcval(
49 // no text filters in nucleus
56 $f_mt_getCategoryList_sig = array(array(
58 $xmlrpcArray, // array of structs
61 $xmlrpcString, // blogid
62 $xmlrpcString, // username
63 $xmlrpcString // password
66 $f_mt_getCategoryList_doc = 'Returns a list of all categories defined in the weblog';
67 function f_mt_getCategoryList($m) {
68 $blogid = _getScalar($m,0);
69 $username = _getScalar($m,1);
70 $password = _getScalar($m,2);
72 return _mt_categoryList($blogid, $username, $password);
76 $f_mt_publishPost_sig = array(array(
78 $xmlrpcBoolean, // true
81 $xmlrpcString, // itemid
82 $xmlrpcString, // username
83 $xmlrpcString // password
85 $f_mt_publishPost_doc = 'Transfers an item from the "draft" state to the "published" state. For items that were published earlier, does nothing.';
86 function f_mt_publishPost($m) {
87 $itemid = intval(_getScalar($m, 0));
88 $username = _getScalar($m, 1);
89 $password = _getScalar($m, 2);
91 return _mt_publishPost($itemid, $username, $password);
94 // mt.getPostCategories
95 $f_mt_getPostCategories_sig = array(array(
97 $xmlrpcArray, // array of structs
99 $xmlrpcString, // itemid
100 $xmlrpcString, // username
101 $xmlrpcString // password
103 $f_mt_getPostCategories_doc = 'Returns a list of all categories to which the post is assigned.';
104 function f_mt_getPostCategories($m) {
105 $itemid = intval(_getScalar($m, 0));
106 $username = _getScalar($m, 1);
107 $password = _getScalar($m, 2);
109 return _mt_getPostCategories($itemid, $username, $password);
112 // mt.setPostCategories
113 $f_mt_setPostCategories_sig = array(array(
115 $xmlrpcBoolean, // true
117 $xmlrpcString, // itemid
118 $xmlrpcString, // username
119 $xmlrpcString, // password
120 $xmlrpcArray // categories
122 $f_mt_setPostCategories_doc = 'Sets the categories for a post. Only the primary category will be stored';
123 function f_mt_setPostCategories($m) {
124 $itemid = intval(_getScalar($m, 0));
125 $username = _getScalar($m, 1);
126 $password = _getScalar($m, 2);
128 $categories = $m->getParam(3);
129 $iSize = $categories->arraysize();
132 for ($i=0;$i<$iSize;$i++) {
133 $struct = $categories->arraymem($i);
134 $bPrimary = $struct->structmem('isPrimary');
136 $bPrimary = $bPrimary->scalarval();
138 $bPrimary = 1; // "Using isPrimary to set the primary category is optional--
139 // in the absence of this flag, the first struct in the array
140 // will be assigned the primary category for the post." (MT doc)
142 $category = $struct->structmem('categoryId');
143 $category = $category->scalarval();
148 return _mt_setPostCategories($itemid, $username, $password, $category);
151 // mt.getRecentPostTitles
152 $f_mt_getRecentPostTitles_sig = array(array(
154 $xmlrpcArray, // array of structs
156 $xmlrpcString, // blogid
157 $xmlrpcString, // userid
158 $xmlrpcString, // password,
159 $xmlrpcInt // number of posts
161 $f_mt_getRecentPostTitles_doc = 'Returns a bandwidth-friendly list of the most recent posts in the system.';
162 function f_mt_getRecentPostTitles($m) {
163 $blogid = intval(_getScalar($m, 0));
164 $username = _getScalar($m, 1);
165 $password = _getScalar($m, 2);
166 $iAmount = intval(_getScalar($m, 3));
168 return _mt_getRecentPostTitles($blogid, $username, $password, $iAmount);
171 // mt.getTrackbackPings
172 $f_mt_getTrackbackPings_sig = array(array(
174 $xmlrpcArray, // array of structs
176 $xmlrpcString // postid
178 $f_mt_getTrackbackPings_doc = '(this is currently just a placeholder. It returns an empty array.)';
179 function f_mt_getTrackbackPings($m) {
182 $itemid = intval(_getScalar($m, 0));
184 $trackbacks = array ();
185 $tbstruct = array ();
189 'trackbacks' => &$trackbacks
191 $manager->notify('RetrieveTrackback', $param);
193 while (list(,$v) = each ($trackbacks)) {
194 $tbstruct[] = new xmlrpcval(
196 "pingTitle" => new xmlrpcval($v['title'], "string"),
197 "pingURL" => new xmlrpcval($v['url'], "string"),
198 "pingIP" => new xmlrpcval($v['ip'], "string")
203 return new xmlrpcresp(new xmlrpcval( $tbstruct , "array"));
206 $functionDefs = array_merge($functionDefs,
208 "mt.supportedMethods" =>
209 array( "function" => "f_mt_supportedMethods",
210 "signature" => $f_mt_supportedMethods_sig,
211 "docstring" => $f_mt_supportedMethods_doc),
213 "mt.supportedTextFilters" =>
214 array( "function" => "f_mt_supportedTextFilters",
215 "signature" => $f_mt_supportedTextFilters_sig,
216 "docstring" => $f_mt_supportedTextFilters_doc),
218 "mt.getCategoryList" =>
219 array( "function" => "f_mt_getCategoryList",
220 "signature" => $f_mt_getCategoryList_sig,
221 "docstring" => $f_mt_getCategoryList_doc),
224 array( "function" => "f_mt_publishPost",
225 "signature" => $f_mt_publishPost_sig,
226 "docstring" => $f_mt_publishPost_doc),
228 "mt.getPostCategories" =>
229 array( "function" => "f_mt_getPostCategories",
230 "signature" => $f_mt_getPostCategories_sig,
231 "docstring" => $f_mt_getPostCategories_doc),
233 "mt.setPostCategories" =>
234 array( "function" => "f_mt_setPostCategories",
235 "signature" => $f_mt_setPostCategories_sig,
236 "docstring" => $f_mt_setPostCategories_doc),
238 "mt.getRecentPostTitles" =>
239 array( "function" => "f_mt_getRecentPostTitles",
240 "signature" => $f_mt_getRecentPostTitles_sig,
241 "docstring" => $f_mt_getRecentPostTitles_doc),
243 "mt.getTrackbackPings" =>
244 array( "function" => "f_mt_getTrackbackPings",
245 "signature" => $f_mt_getTrackbackPings_sig,
246 "docstring" => $f_mt_getTrackbackPings_doc)
251 function _mt_setPostCategories($itemid, $username, $password, $category) {
256 if (!$mem->login($username, $password))
257 return _error(1,"Could not log in");
259 // check if item exists
260 if (!$manager->existsItem($itemid,1,1))
261 return _error(6,"No such item ($itemid)");
263 $blogid = getBlogIDFromItemID($itemid);
264 $blog = new BLOG($blogid);
266 if (!$mem->canAlterItem($itemid))
267 return _error(7,"Not allowed to alter item");
269 $old =& $manager->getItem($itemid,1,1);
271 $catid = $blog->getCategoryIdFromName($category);
274 if ($old['draft'] && $publish) {
281 return _edititem($itemid, $username, $password, $catid, $old['title'], $old['body'], $old['more'], $wasdraft, $publish, $old['closed']);
285 function _mt_getPostCategories($itemid, $username, $password) {
290 if (!$mem->login($username, $password))
291 return _error(1,"Could not log in");
293 // check if item exists
294 if (!$manager->existsItem($itemid,1,1))
295 return _error(6,"No such item ($itemid)");
297 $blogid = getBlogIDFromItemID($itemid);
298 $blog = new BLOG($blogid);
300 if (!$mem->canAlterItem($itemid))
301 return _error(7, 'You are not allowed to request this information');
303 $info =& $manager->getItem($itemid,1,1);
304 $catName = $blog->getCategoryName($info['catid']);
306 $struct = new xmlrpcval(
308 'categoryId' => new xmlrpcval($catName, 'string'),
309 'categoryName' => new xmlrpcval($catName, 'string'),
310 'isPrimary' => new xmlrpcval(1, 'boolean')
314 return new xmlrpcresp(new xmlrpcval(array($struct), 'array'));
318 function _mt_publishPost($itemid, $username, $password) {
321 if (!$manager->existsItem($itemid,1,1))
322 return _error(6,"No such item ($itemid)");
325 $blogid = getBlogIDFromItemID($itemid);
326 $blog = new BLOG($blogid);
327 $old =& $manager->getItem($itemid,1,1);
329 return _edititem($itemid, $username, $password, $old['catid'], $old['title'], $old['body'], $old['more'], $old['draft'], 1, $old['closed']);
333 function _mt_categoryList($blogid, $username, $password) {
336 if (!$mem->login($username, $password))
337 return _error(1,"Could not log in");
339 // check if on team and blog exists
340 if (!BLOG::existsID($blogid))
341 return _error(2,"No such blog ($blogid)");
342 if (!$mem->teamRights($blogid))
343 return _error(3,"Not a team member");
345 $b = new BLOG($blogid);
347 $categorystruct = array();
349 $query = "SELECT cname, cdesc, catid"
350 . ' FROM '.sql_table('category')
351 . " WHERE cblog=" . intval($blogid)
353 $r = sql_query($query);
355 while ($obj = sql_fetch_object($r)) {
357 $categorystruct[] = new xmlrpcval(
359 "categoryName" => new xmlrpcval($obj->cname,"string"),
360 "categoryId" => new xmlrpcval($obj->cname,"string")
367 return new xmlrpcresp(new xmlrpcval( $categorystruct , "array"));
371 function _mt_getRecentPostTitles($blogid, $username, $password, $iAmount)
373 $blogid = intval($blogid);
374 $iAmount = intval($iAmount);
378 if (!$mem->login($username, $password))
379 return _error(1,"Could not log in");
381 // 2. check if allowed
382 if (!BLOG::existsID($blogid))
383 return _error(2,"No such blog ($blogid)");
384 if (!$mem->teamRights($blogid))
385 return _error(3,"Not a team member");
386 $iAmount = intval($iAmount);
388 return _error(5,"Amount parameter must be positive");
390 // 3. create and return list of recent items
391 // Struct returned has dateCreated, userid, postid and title
393 $blog = new BLOG($blogid);
395 $structarray = array(); // the array in which the structs will be stored
397 $query = "SELECT inumber, ititle as title, itime, iauthor"
398 .' FROM '.sql_table('item')
399 ." WHERE iblog=$blogid"
400 ." ORDER BY itime DESC"
402 $r = sql_query($query);
404 while ($row = sql_fetch_assoc($r)) {
406 $newstruct = new xmlrpcval(array(
407 "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
408 "postid" => new xmlrpcval($row['inumber'],"string"),
409 "title" => new xmlrpcval($row['title'],"string"),
410 "userid" => new xmlrpcval($row['iauthor'],"string")
413 array_push($structarray, $newstruct);
416 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));