3
* XML-RPC : Movable Type API (partial)
5
* @see http://manual.b2evolution.net/MovableType_API
7
* b2evolution - {@link http://b2evolution.net/}
8
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
9
* @copyright (c)2003-2008 by Francois PLANQUE - {@link http://fplanque.net/}
15
* @version $Id: _mt.api.php,v 1.1 2008/01/14 07:22:07 fplanque Exp $
17
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
21
$mt_setPostCategories_sig = array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcArray));
22
$mt_setPostCategories_doc = "Sets the categories for a post.";
24
* mt.setPostCategories : set cats for a post
26
* @param xmlrpcmsg XML-RPC Message
27
* 0 postid (string): Unique identifier of the post to edit
28
* 1 username (string): Login for a Blogger user who is member of the blog.
29
* 2 password (string): Password for said username.
31
function mt_setPostCategories($m)
33
global $xmlrpcerruser,$Settings;
34
global $DB, $Messages;
40
if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
41
{ // Login failed, return (last) error:
42
return xmlrpcs_resperror();
49
if( ! $edited_Item = & xmlrpcs_get_Item( $m, 0 ) )
50
{ // Failed, return (last) error:
51
return xmlrpcs_resperror();
54
$xcontent = $m->getParam(3); // This is now an array of structs
55
$contentstruct = xmlrpc_decode_recurse($xcontent);
56
logIO("Decoded xcontent");
58
$categories = array();
60
foreach( $contentstruct as $catstruct )
62
logIO( 'Category ID: '.$catstruct['categoryId'] ) ;
63
if( !empty($catstruct['isPrimary']) )
65
logIO("got primary category and there should only be one...".$tempcat);
66
$category = $catstruct['categoryId'];
68
$categories[] = $catstruct['categoryId'];
71
if( empty( $categories ) )
73
return new xmlrpcresp(0, $xmlrpcerruser+4, // user error 4
74
'No categories specified.');
77
// CHECK PERMISSION: (we need perm on all categories, especially if they are in different blogs)
78
if( ! $current_User->check_perm( 'cats_post!'.$edited_Item->status, 'edit', false, $categories ) )
79
{ // Permission denied
80
return xmlrpcs_resperror( 3 ); // User error 3
82
logIO( 'Permission granted.' );
85
if( empty( $category ) )
86
{ // Use first one as default:
87
$category = $categories[0];
90
logIO( 'Main Cat: '.$category.' - Other: '.implode(',',$categories) );
92
// UPDATE POST CATEGORIES IN DB:
93
$edited_Item->set( 'main_cat_ID', $category );
94
$edited_Item->set( 'extra_cat_IDs', $categories );
96
if( $edited_Item->dbupdate() === false )
98
logIO( 'Update failed.' );
99
return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
104
return new xmlrpcresp(new xmlrpcval(1));
109
$mt_getPostCategories_sig = array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString));
110
$mt_getPostCategories_doc = "Returns a list of all categories to which the post is assigned.";
112
* mt.getPostCategories : Get the categories for a given post.
114
* @param xmlrpcmsg XML-RPC Message
115
* 0 postid (string): Unique identifier of the post to query
116
* 1 username (string): Login for a Blogger user who is member of the blog.
117
* 2 password (string): Password for said username.
119
function mt_getPostCategories($m)
121
global $xmlrpcerruser;
128
if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
129
{ // Login failed, return (last) error:
130
return xmlrpcs_resperror();
137
if( ! $edited_Item = & xmlrpcs_get_Item( $m, 0 ) )
138
{ // Failed, return (last) error:
139
return xmlrpcs_resperror();
142
// CHECK PERMISSION: (we need at least one post/edit status)
143
if( ! $current_User->check_perm( 'blog_post_statuses', 1, false, $edited_Item->blog_ID ) )
144
{ // Permission denied
145
return xmlrpcs_resperror( 3 ); // User error 3
147
logIO( 'Permission granted.' );
150
$categories = postcats_get_byID( $edited_Item->ID ); // Secondary categories
151
$iSize = count($categories); // The number of objects ie categories
152
logIO("mt_getgategorylist no of categories...".$iSize);// works
154
for( $i=0; $i<$iSize; $i++)
156
logIO("mt_getPostCategories categories ...".$categories[$i]);
157
// In database cat_ID and cat_name from tablecategories
158
$sql = "SELECT * FROM T_categories WHERE cat_ID = $categories[$i] ";
159
logIO("mt_getgategorylist sql...".$sql);
160
$rows = $DB->get_results( $sql );
161
foreach( $rows as $row )
163
$Categoryname = $row->cat_name;
164
logIO("mt_getPostCategories Categoryname ...".$Categoryname);
167
// Is this the primary cat?
168
$isPrimary = ($categories[$i] == $edited_Item->main_cat_ID) ? 1 : 0;
170
$struct[$i] = new xmlrpcval(array("categoryId" => new xmlrpcval($categories[$i]), // Look up name from ID separately
171
"categoryName" => new xmlrpcval($Categoryname),
172
"isPrimary" => new xmlrpcval($isPrimary)
177
return new xmlrpcresp(new xmlrpcval($struct, "array") );
182
$mt_getCategoryList_sig = array(array($xmlrpcArray,$xmlrpcString,$xmlrpcString,$xmlrpcString));
183
$mt_getCategoryList_doc = 'Get category list';
187
* @see http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetcategorylist.html
189
* @param xmlrpcmsg XML-RPC Message
190
* 0 blogid (string): Unique identifier of the blog to query
191
* 1 username (string): Login for a Blogger user who is member of the blog.
192
* 2 password (string): Password for said username.
194
function mt_getCategoryList($m)
196
logIO("mt_getCategoryList start");
197
return _b2_or_mt_get_categories('mt', $m);
202
* mt.supportedMethods
203
* mt.supportedTextFilters
205
* *mt.getCategoryList
206
* *mt.getPostCategories
207
* *mt.setPostCategories
208
* mt.getRecentPostTitles
209
* mt.getTrackbackPings
212
$xmlrpc_procs["mt.getCategoryList"] = array(
213
"function" => "mt_getCategoryList",
214
"signature" => $mt_getCategoryList_sig,
215
"docstring" => $mt_getCategoryList_doc );
217
$xmlrpc_procs["mt.setPostCategories"] = array(
218
"function" => "mt_setPostCategories",
219
"signature" => $mt_setPostCategories_sig,
220
"docstring" => $mt_setPostCategories_doc );
222
$xmlrpc_procs["mt.getPostCategories"] = array(
223
"function" => "mt_getPostCategories",
224
"signature" => $mt_getPostCategories_sig,
225
"docstring" => $mt_getPostCategories_doc );
231
- mt.supportedTextFilters
232
- mt.supportedMethods
234
- mt.getTrackbackPings
235
- mt.getRecentPostTitles
237
http://www.sixapart.com/developers/xmlrpc/movable_type_api/
242
* $Log: _mt.api.php,v $
243
* Revision 1.1 2008/01/14 07:22:07 fplanque
246
* Revision 1.5 2008/01/13 19:43:26 fplanque
249
* Revision 1.4 2008/01/13 03:12:06 fplanque
250
* XML-RPC API debugging
252
* Revision 1.3 2008/01/12 22:51:11 fplanque
255
* Revision 1.2 2008/01/12 08:06:15 fplanque
b'\\ No newline at end of file'