~edb/quam-plures/item_show_attachments

« back to all changes in this revision

Viewing changes to blogs/inc/xmlrpc/apis/_mt.api.php

  • Committer: fplanque
  • Date: 2008-01-14 06:22:06 UTC
  • Revision ID: cvs-1:fplanque-20080114062206-qipq1knxpvphnpz7
Refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * XML-RPC : Movable Type API (partial)
 
4
 *
 
5
 * @see http://manual.b2evolution.net/MovableType_API
 
6
 *
 
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/}
 
10
 *
 
11
 * @author tor
 
12
 *
 
13
 * @package xmlsrv
 
14
 *
 
15
 * @version $Id: _mt.api.php,v 1.1 2008/01/14 07:22:07 fplanque Exp $
 
16
 */
 
17
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
 
18
 
 
19
 
 
20
 
 
21
$mt_setPostCategories_sig = array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcArray));
 
22
$mt_setPostCategories_doc = "Sets the categories for a post.";
 
23
/**
 
24
 * mt.setPostCategories : set cats for a post
 
25
 *
 
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.
 
30
 */
 
31
function mt_setPostCategories($m)
 
32
{
 
33
        global $xmlrpcerruser,$Settings;
 
34
        global $DB, $Messages;
 
35
 
 
36
        // CHECK LOGIN:
 
37
  /**
 
38
         * @var User
 
39
         */
 
40
        if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 
41
        {       // Login failed, return (last) error:
 
42
                return xmlrpcs_resperror();
 
43
        }
 
44
 
 
45
        // GET POST:
 
46
  /**
 
47
         * @var Item
 
48
         */
 
49
        if( ! $edited_Item = & xmlrpcs_get_Item( $m, 0 ) )
 
50
        {       // Failed, return (last) error:
 
51
                return xmlrpcs_resperror();
 
52
        }
 
53
 
 
54
        $xcontent = $m->getParam(3); // This is now an array of structs
 
55
        $contentstruct = xmlrpc_decode_recurse($xcontent);
 
56
        logIO("Decoded xcontent");
 
57
 
 
58
        $categories = array();
 
59
        $category = NULL;
 
60
        foreach( $contentstruct as $catstruct )
 
61
        {
 
62
                logIO( 'Category ID: '.$catstruct['categoryId'] ) ;
 
63
                if( !empty($catstruct['isPrimary']) )
 
64
                {
 
65
                        logIO("got primary category and there should only be one...".$tempcat);
 
66
                        $category = $catstruct['categoryId'];
 
67
                }
 
68
                $categories[] = $catstruct['categoryId'];
 
69
        }
 
70
 
 
71
        if( empty( $categories ) )
 
72
        {
 
73
                return new xmlrpcresp(0, $xmlrpcerruser+4, // user error 4
 
74
                                         'No categories specified.');
 
75
        }
 
76
 
 
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
 
81
        }
 
82
        logIO( 'Permission granted.' );
 
83
 
 
84
 
 
85
        if( empty( $category ) )
 
86
        {       // Use first one as default:
 
87
                $category = $categories[0];
 
88
        }
 
89
 
 
90
        logIO( 'Main Cat: '.$category.' - Other: '.implode(',',$categories) );
 
91
 
 
92
        // UPDATE POST CATEGORIES IN DB:
 
93
        $edited_Item->set( 'main_cat_ID', $category );
 
94
        $edited_Item->set( 'extra_cat_IDs', $categories );
 
95
 
 
96
        if( $edited_Item->dbupdate() === false )
 
97
        {
 
98
                logIO( 'Update failed.' );
 
99
                return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
 
100
                                         'Update failed.');
 
101
        }
 
102
 
 
103
        logIO( 'OK.' );
 
104
        return new xmlrpcresp(new xmlrpcval(1));
 
105
}
 
106
 
 
107
 
 
108
 
 
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.";
 
111
/**
 
112
 * mt.getPostCategories : Get the categories for a given post.
 
113
 *
 
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.
 
118
 */
 
119
function mt_getPostCategories($m)
 
120
{
 
121
        global $xmlrpcerruser;
 
122
        global $DB;
 
123
 
 
124
        // CHECK LOGIN:
 
125
  /**
 
126
         * @var User
 
127
         */
 
128
        if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 
129
        {       // Login failed, return (last) error:
 
130
                return xmlrpcs_resperror();
 
131
        }
 
132
 
 
133
        // GET POST:
 
134
  /**
 
135
         * @var Item
 
136
         */
 
137
        if( ! $edited_Item = & xmlrpcs_get_Item( $m, 0 ) )
 
138
        {       // Failed, return (last) error:
 
139
                return xmlrpcs_resperror();
 
140
        }
 
141
 
 
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
 
146
        }
 
147
        logIO( 'Permission granted.' );
 
148
 
 
149
 
 
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
 
153
        $struct = array();
 
154
        for( $i=0; $i<$iSize; $i++)
 
155
        {
 
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 )
 
162
                {
 
163
                        $Categoryname =  $row->cat_name;
 
164
                        logIO("mt_getPostCategories Categoryname  ...".$Categoryname);
 
165
                }
 
166
 
 
167
                // Is this the primary cat?
 
168
                $isPrimary = ($categories[$i] == $edited_Item->main_cat_ID) ? 1 : 0;
 
169
 
 
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)
 
173
                                                                                ),"struct");
 
174
        }
 
175
 
 
176
        logIO( 'OK.' );
 
177
        return new xmlrpcresp(new xmlrpcval($struct, "array") );
 
178
}
 
179
 
 
180
 
 
181
 
 
182
$mt_getCategoryList_sig =  array(array($xmlrpcArray,$xmlrpcString,$xmlrpcString,$xmlrpcString));
 
183
$mt_getCategoryList_doc = 'Get category list';
 
184
/**
 
185
 * mt.getCategoryList
 
186
 *
 
187
 * @see http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetcategorylist.html
 
188
 *
 
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.
 
193
 */
 
194
function mt_getCategoryList($m)
 
195
{
 
196
        logIO("mt_getCategoryList start");
 
197
        return _b2_or_mt_get_categories('mt', $m);
 
198
}
 
199
 
 
200
 
 
201
/*
 
202
 *  mt.supportedMethods
 
203
 *  mt.supportedTextFilters
 
204
 *  mt.publishPost
 
205
 * *mt.getCategoryList
 
206
 * *mt.getPostCategories
 
207
 * *mt.setPostCategories
 
208
 *  mt.getRecentPostTitles
 
209
 *  mt.getTrackbackPings
 
210
 */
 
211
 
 
212
$xmlrpc_procs["mt.getCategoryList"] = array(
 
213
                                "function" => "mt_getCategoryList",
 
214
                                "signature" => $mt_getCategoryList_sig,
 
215
                                "docstring" => $mt_getCategoryList_doc );
 
216
 
 
217
$xmlrpc_procs["mt.setPostCategories"] = array(
 
218
                                "function" => "mt_setPostCategories",
 
219
                                "signature" => $mt_setPostCategories_sig,
 
220
                                "docstring" => $mt_setPostCategories_doc );
 
221
 
 
222
$xmlrpc_procs["mt.getPostCategories"] = array(
 
223
                                "function" => "mt_getPostCategories",
 
224
                                "signature" => $mt_getPostCategories_sig,
 
225
                                "docstring" => $mt_getPostCategories_doc );
 
226
 
 
227
 
 
228
/*
 
229
        Missing:
 
230
 
 
231
        - mt.supportedTextFilters
 
232
        - mt.supportedMethods
 
233
  - mt.publishPost
 
234
  - mt.getTrackbackPings
 
235
  - mt.getRecentPostTitles
 
236
 
 
237
        http://www.sixapart.com/developers/xmlrpc/movable_type_api/
 
238
*/
 
239
 
 
240
 
 
241
/*
 
242
 * $Log: _mt.api.php,v $
 
243
 * Revision 1.1  2008/01/14 07:22:07  fplanque
 
244
 * Refactoring
 
245
 *
 
246
 * Revision 1.5  2008/01/13 19:43:26  fplanque
 
247
 * minor
 
248
 *
 
249
 * Revision 1.4  2008/01/13 03:12:06  fplanque
 
250
 * XML-RPC API debugging
 
251
 *
 
252
 * Revision 1.3  2008/01/12 22:51:11  fplanque
 
253
 * RSD support
 
254
 *
 
255
 * Revision 1.2  2008/01/12 08:06:15  fplanque
 
256
 * more xmlrpc tests
 
257
 *
 
258
 */
 
259
?>
 
 
b'\\ No newline at end of file'