Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 1932 lines (1487 sloc) 55.054 kb
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1 <?php
2
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
3 define('XMLRPC_REQUEST', true);
4
5 // Some browser-embedded clients send cookies. We don't want them.
6 $_COOKIE = array();
7
f432ed6 Fix for PHP version 5.2.2 where $HTTP_RAW_POST_DATA isn't set. fixes #42...
rob1n authored
8 // A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default,
9 // but we can do it ourself.
10 if ( !isset( $HTTP_RAW_POST_DATA ) ) {
11 $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
12 }
13
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
14 # fix for mozBlog and other cases where '<?xml' isn't on the very first line
60ccea9 Check if HTTP_RAW_POST_DATA is set to avoid undefined var warning. Prop...
ryan authored
15 if ( isset($HTTP_RAW_POST_DATA) )
16 $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
17
4fe6495 whoops, a dot that was removed yesterday came back when restoring the fi...
michelvaldrighi authored
18 include('./wp-config.php');
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
19
20 if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
21 header('Content-type: text/xml; charset=' . get_option('blog_charset'), true);
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
22
23 ?>
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
24 <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
25 <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
26 <service>
27 <engineName>WordPress</engineName>
28 <engineLink>http://wordpress.org/</engineLink>
29 <homePageLink><?php bloginfo_rss('url') ?></homePageLink>
30 <apis>
d162935 WP XML-RPC API enhancements.
ryan authored
31 <api name="WordPress" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
32 <api name="Movable Type" blogID="1" preferred="true" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
33 <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
34 <api name="Blogger" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" />
35 </apis>
36 </service>
37 </rsd>
38 <?php
39 exit;
40 }
41
e57369e Include admin-functions in xmlrpc.
ryan authored
42 include_once(ABSPATH . 'wp-admin/admin-functions.php');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
43 include_once(ABSPATH . WPINC . '/class-IXR.php');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
44
45 // Turn off all warnings and errors.
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
46 // error_reporting(0);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
47
48 $post_default_title = ""; // posts submitted via the xmlrpc interface get that title
49
80b3445 fixed comment_status screwup, removed debug stuff, screwed up big time, ...
michelvaldrighi authored
50 $xmlrpc_logging = 0;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
51
52 function logIO($io,$msg) {
53 global $xmlrpc_logging;
54 if ($xmlrpc_logging) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
55 $fp = fopen("../xmlrpc.log","a+");
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
56 $date = gmdate("Y-m-d H:i:s ");
57 $iot = ($io == "I") ? " Input: " : " Output: ";
58 fwrite($fp, "\n\n".$date.$iot.$msg);
59 fclose($fp);
60 }
61 return true;
62 }
63
64 function starify($string) {
65 $i = strlen($string);
66 return str_repeat('*', $i);
67 }
68
75ec542 avoid $HTTP_RAW_POST_DATA notices. props mgeisler and Nazgul. fixes #14...
markjaquith authored
69 if ( isset($HTTP_RAW_POST_DATA) )
70 logIO("I", $HTTP_RAW_POST_DATA);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
71
9611463 added Emmanuel Frecon's fix to create directories in mw.newMediaObject, ...
michelvaldrighi authored
72
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
73 class wp_xmlrpc_server extends IXR_Server {
74
75 function wp_xmlrpc_server() {
76 $this->methods = array(
9af6317 WP XML-RPC API
ryan authored
77 // WordPress API
78 'wp.getPage' => 'this:wp_getPage',
79 'wp.getPages' => 'this:wp_getPages',
80 'wp.newPage' => 'this:wp_newPage',
81 'wp.deletePage' => 'this:wp_deletePage',
82 'wp.editPage' => 'this:wp_editPage',
83 'wp.getPageList' => 'this:wp_getPageList',
84 'wp.getAuthors' => 'this:wp_getAuthors',
85 'wp.getCategories' => 'this:mw_getCategories', // Alias
86 'wp.newCategory' => 'this:wp_newCategory',
87 'wp.suggestCategories' => 'this:wp_suggestCategories',
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
88 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias
9af6317 WP XML-RPC API
ryan authored
89
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
90 // Blogger API
91 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
92 'blogger.getUserInfo' => 'this:blogger_getUserInfo',
93 'blogger.getPost' => 'this:blogger_getPost',
94 'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
95 'blogger.getTemplate' => 'this:blogger_getTemplate',
96 'blogger.setTemplate' => 'this:blogger_setTemplate',
97 'blogger.newPost' => 'this:blogger_newPost',
98 'blogger.editPost' => 'this:blogger_editPost',
99 'blogger.deletePost' => 'this:blogger_deletePost',
100
101 // MetaWeblog API (with MT extensions to structs)
102 'metaWeblog.newPost' => 'this:mw_newPost',
103 'metaWeblog.editPost' => 'this:mw_editPost',
104 'metaWeblog.getPost' => 'this:mw_getPost',
105 'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
106 'metaWeblog.getCategories' => 'this:mw_getCategories',
107 'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
108
109 // MetaWeblog API aliases for Blogger API
110 // see http://www.xmlrpc.com/stories/storyReader$2460
111 'metaWeblog.deletePost' => 'this:blogger_deletePost',
112 'metaWeblog.getTemplate' => 'this:blogger_getTemplate',
113 'metaWeblog.setTemplate' => 'this:blogger_setTemplate',
114 'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
115
116 // MovableType API
117 'mt.getCategoryList' => 'this:mt_getCategoryList',
118 'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
119 'mt.getPostCategories' => 'this:mt_getPostCategories',
120 'mt.setPostCategories' => 'this:mt_setPostCategories',
121 'mt.supportedMethods' => 'this:mt_supportedMethods',
122 'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
123 'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
124 'mt.publishPost' => 'this:mt_publishPost',
125
126 // PingBack
127 'pingback.ping' => 'this:pingback_ping',
128 'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
129
130 'demo.sayHello' => 'this:sayHello',
131 'demo.addTwoNumbers' => 'this:addTwoNumbers'
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
132 );
087df40 Allow plugins to hook into XML-RPC server.
saxmatt authored
133 $this->methods = apply_filters('xmlrpc_methods', $this->methods);
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
134 $this->IXR_Server($this->methods);
135 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
136
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
137 function sayHello($args) {
138 return 'Hello!';
139 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
140
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
141 function addTwoNumbers($args) {
142 $number1 = $args[0];
143 $number2 = $args[1];
144 return $number1 + $number2;
145 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
146
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
147 function login_pass_ok($user_login, $user_pass) {
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
148 if (!user_pass_ok($user_login, $user_pass)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
149 $this->error = new IXR_Error(403, __('Bad login/pass combination.'));
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
150 return false;
151 }
152 return true;
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
153 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
154
9c9ba0a Escape XMLRPC args.
ryan authored
155 function escape(&$array) {
156 global $wpdb;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
157
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
158 if(!is_array($array)) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
159 return($wpdb->escape($array));
160 }
161 else {
162 foreach ( (array) $array as $k => $v ) {
163 if (is_array($v)) {
164 $this->escape($array[$k]);
165 } else if (is_object($v)) {
166 //skip
167 } else {
168 $array[$k] = $wpdb->escape($v);
169 }
9c9ba0a Escape XMLRPC args.
ryan authored
170 }
171 }
172 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
173
9af6317 WP XML-RPC API
ryan authored
174 /**
175 * WordPress XML-RPC API
176 * wp_getPage
177 */
178 function wp_getPage($args) {
179 $this->escape($args);
180
7602d17 (int)er the dragon.
matt authored
181 $blog_id = (int) $args[0];
182 $page_id = (int) $args[1];
9af6317 WP XML-RPC API
ryan authored
183 $username = $args[2];
184 $password = $args[3];
185
186 if(!$this->login_pass_ok($username, $password)) {
187 return($this->error);
188 }
189
190 // Lookup page info.
191 $page = get_page($page_id);
192
193 // If we found the page then format the data.
194 if($page->ID && ($page->post_type == "page")) {
195 // Get all of the page content and link.
196 $full_page = get_extended($page->post_content);
197 $link = post_permalink($page->ID);
198
d162935 WP XML-RPC API enhancements.
ryan authored
199 // Get info the page parent if there is one.
200 $parent_title = "";
201 if(!empty($page->post_parent)) {
202 $parent = get_page($page->post_parent);
203 $parent_title = $parent->post_title;
204 }
205
9af6317 WP XML-RPC API
ryan authored
206 // Determine comment and ping settings.
207 $allow_comments = ("open" == $page->comment_status) ? 1 : 0;
208 $allow_pings = ("open" == $page->ping_status) ? 1 : 0;
209
210 // Format page date.
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #4158 ...
ryan authored
211 $page_date = mysql2date("Ymd\TH:i:s", $page->post_date_gmt);
9af6317 WP XML-RPC API
ryan authored
212
213 // Pull the categories info together.
214 $categories = array();
215 foreach(wp_get_post_categories($page->ID) as $cat_id) {
216 $categories[] = get_cat_name($cat_id);
217 }
218
d162935 WP XML-RPC API enhancements.
ryan authored
219 // Get the author info.
220 $author = get_userdata($page->post_author);
9af6317 WP XML-RPC API
ryan authored
221
222 $page_struct = array(
d162935 WP XML-RPC API enhancements.
ryan authored
223 "dateCreated" => new IXR_Date($page_date),
224 "userid" => $page->post_author,
225 "page_id" => $page->ID,
226 "page_status" => $page->post_status,
227 "description" => $full_page["main"],
228 "title" => $page->post_title,
229 "link" => $link,
230 "permaLink" => $link,
231 "categories" => $categories,
232 "excerpt" => $page->post_excerpt,
233 "text_more" => $full_page["extended"],
234 "mt_allow_comments" => $allow_comments,
235 "mt_allow_pings" => $allow_pings,
236 "wp_slug" => $page->post_name,
237 "wp_password" => $page->post_password,
e71e25d XMLRPC API updates.
ryan authored
238 "wp_author" => $author->display_name,
d162935 WP XML-RPC API enhancements.
ryan authored
239 "wp_page_parent_id" => $page->post_parent,
240 "wp_page_parent_title" => $parent_title,
241 "wp_page_order" => $page->menu_order,
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
242 "wp_author_id" => $author->ID,
1c731fa XMLRPC changes from Joseph.
ryan authored
243 "wp_author_display_name" => $author->display_name
9af6317 WP XML-RPC API
ryan authored
244 );
245
246 return($page_struct);
247 }
248 // If the page doesn't exist indicate that.
249 else {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
250 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
251 }
252 }
253
254 /**
255 * WordPress XML-RPC API
256 * wp_getPages
257 */
258 function wp_getPages($args) {
259 $this->escape($args);
260
7602d17 (int)er the dragon.
matt authored
261 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
262 $username = $args[1];
263 $password = $args[2];
264
265 if(!$this->login_pass_ok($username, $password)) {
266 return($this->error);
267 }
268
269 // Lookup info on pages.
270 $pages = get_pages();
271 $num_pages = count($pages);
272
273 // If we have pages, put together their info.
274 if($num_pages >= 1) {
275 $pages_struct = array();
276
277 for($i = 0; $i < $num_pages; $i++) {
278 $page = wp_xmlrpc_server::wp_getPage(array(
279 $blog_id, $pages[$i]->ID, $username, $password
280 ));
281 $pages_struct[] = $page;
282 }
283
284 return($pages_struct);
285 }
286 // If no pages were found return an error.
287 else {
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return empty ...
ryan authored
288 return(array());
9af6317 WP XML-RPC API
ryan authored
289 }
290 }
291
292 /**
293 * WordPress XML-RPC API
294 * wp_newPage
295 */
296 function wp_newPage($args) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
297 // Items not escaped here will be escaped in newPost.
298 $username = $this->escape($args[1]);
299 $password = $this->escape($args[2]);
9af6317 WP XML-RPC API
ryan authored
300 $page = $args[3];
301 $publish = $args[4];
302
303 if(!$this->login_pass_ok($username, $password)) {
304 return($this->error);
305 }
306
307 // Set the user context and check if they are allowed
308 // to add new pages.
309 $user = set_current_user(0, $username);
310 if(!current_user_can("publish_pages")) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
311 return(new IXR_Error(401, __("Sorry, you can not add new pages.")));
9af6317 WP XML-RPC API
ryan authored
312 }
313
314 // Mark this as content for a page.
315 $args[3]["post_type"] = "page";
316
317 // Let mw_newPost do all of the heavy lifting.
318 return($this->mw_newPost($args));
319 }
320
321 /**
322 * WordPress XML-RPC API
323 * wp_deletePage
324 */
325 function wp_deletePage($args) {
326 $this->escape($args);
327
7602d17 (int)er the dragon.
matt authored
328 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
329 $username = $args[1];
330 $password = $args[2];
7602d17 (int)er the dragon.
matt authored
331 $page_id = (int) $args[3];
9af6317 WP XML-RPC API
ryan authored
332
333 if(!$this->login_pass_ok($username, $password)) {
334 return($this->error);
335 }
336
337 // Get the current page based on the page_id and
338 // make sure it is a page and not a post.
339 $actual_page = wp_get_single_post($page_id, ARRAY_A);
340 if(
341 !$actual_page
342 || ($actual_page["post_type"] != "page")
343 ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
344 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
345 }
346
347 // Set the user context and make sure they can delete pages.
348 set_current_user(0, $username);
349 if(!current_user_can("delete_page", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
350 return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page.")));
9af6317 WP XML-RPC API
ryan authored
351 }
352
353 // Attempt to delete the page.
354 $result = wp_delete_post($page_id);
355 if(!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
356 return(new IXR_Error(500, __("Failed to delete the page.")));
9af6317 WP XML-RPC API
ryan authored
357 }
358
359 return(true);
360 }
361
362 /**
363 * WordPress XML-RPC API
364 * wp_editPage
365 */
366 function wp_editPage($args) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
367 // Items not escaped here will be escaped in editPost.
7602d17 (int)er the dragon.
matt authored
368 $blog_id = (int) $args[0];
ae7fa6c Cast to int after escaping. Props Joseph Scott.
ryan authored
369 $page_id = (int) $this->escape($args[1]);
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
370 $username = $this->escape($args[2]);
371 $password = $this->escape($args[3]);
9af6317 WP XML-RPC API
ryan authored
372 $content = $args[4];
373 $publish = $args[5];
374
375 if(!$this->login_pass_ok($username, $password)) {
376 return($this->error);
377 }
378
379 // Get the page data and make sure it is a page.
380 $actual_page = wp_get_single_post($page_id, ARRAY_A);
381 if(
382 !$actual_page
383 || ($actual_page["post_type"] != "page")
384 ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
385 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
386 }
387
388 // Set the user context and make sure they are allowed to edit pages.
389 set_current_user(0, $username);
390 if(!current_user_can("edit_page", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
391 return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page.")));
9af6317 WP XML-RPC API
ryan authored
392 }
393
394 // Mark this as content for a page.
395 $content["post_type"] = "page";
396
397 // Arrange args in the way mw_editPost understands.
398 $args = array(
399 $page_id,
400 $username,
401 $password,
402 $content,
403 $publish
404 );
405
406 // Let mw_editPost do all of the heavy lifting.
407 return($this->mw_editPost($args));
408 }
409
410 /**
411 * WordPress XML-RPC API
412 * wp_getPageList
413 */
414 function wp_getPageList($args) {
415 global $wpdb;
416
417 $this->escape($args);
418
7602d17 (int)er the dragon.
matt authored
419 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
420 $username = $args[1];
421 $password = $args[2];
422
423 if(!$this->login_pass_ok($username, $password)) {
424 return($this->error);
425 }
426
427 // Get list of pages ids and titles
428 $page_list = $wpdb->get_results("
429 SELECT ID page_id,
d162935 WP XML-RPC API enhancements.
ryan authored
430 post_title page_title,
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
431 post_parent page_parent_id,
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #4158 ...
ryan authored
432 post_date_gmt
9af6317 WP XML-RPC API
ryan authored
433 FROM {$wpdb->posts}
434 WHERE post_type = 'page'
435 ORDER BY ID
436 ");
437
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
438 // The date needs to be formated properly.
439 $num_pages = count($page_list);
440 for($i = 0; $i < $num_pages; $i++) {
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #4158 ...
ryan authored
441 $post_date = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date_gmt);
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
442 $page_list[$i]->dateCreated = new IXR_Date($post_date);
443
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #4158 ...
ryan authored
444 unset($page_list[$i]->post_date_gmt);
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
445 }
446
9af6317 WP XML-RPC API
ryan authored
447 return($page_list);
448 }
449
450 /**
451 * WordPress XML-RPC API
452 * wp_getAuthors
453 */
454 function wp_getAuthors($args) {
455 global $wpdb;
456
457 $this->escape($args);
458
7602d17 (int)er the dragon.
matt authored
459 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
460 $username = $args[1];
461 $password = $args[2];
462
463 if(!$this->login_pass_ok($username, $password)) {
464 return($this->error);
465 }
466
bf37dbf Use get_users_of_blog() for wp_getAuthors
ryan authored
467 return(get_users_of_blog());
9af6317 WP XML-RPC API
ryan authored
468 }
469
470 /**
471 * WordPress XML-RPC API
472 * wp_newCategory
473 */
474 function wp_newCategory($args) {
475 $this->escape($args);
476
7602d17 (int)er the dragon.
matt authored
477 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
478 $username = $args[1];
479 $password = $args[2];
480 $category = $args[3];
481
482 if(!$this->login_pass_ok($username, $password)) {
483 return($this->error);
484 }
485
486 // Set the user context and make sure they are
487 // allowed to add a category.
488 set_current_user(0, $username);
489 if(!current_user_can("manage_categories", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
490 return(new IXR_Error(401, __("Sorry, you do not have the right to add a category.")));
9af6317 WP XML-RPC API
ryan authored
491 }
492
493 // We need this to make use of the wp_insert_category()
494 // funciton.
495 require_once(ABSPATH . "wp-admin/admin-db.php");
496
497 // If no slug was provided make it empty so that
498 // WordPress will generate one.
499 if(empty($category["slug"])) {
500 $category["slug"] = "";
501 }
502
503 // If no parent_id was provided make it empty
504 // so that it will be a top level page (no parent).
c8997ff Reverse logic.
ryan authored
505 if ( !isset($category["parent_id"]) )
9af6317 WP XML-RPC API
ryan authored
506 $category["parent_id"] = "";
507
508 // If no description was provided make it empty.
509 if(empty($category["description"])) {
510 $category["description"] = "";
511 }
d0f79bb trailing tabs and whitespace cleanup.
markjaquith authored
512
9af6317 WP XML-RPC API
ryan authored
513 $new_category = array(
514 "cat_name" => $category["name"],
515 "category_nicename" => $category["slug"],
516 "category_parent" => $category["parent_id"],
517 "category_description" => $category["description"]
518 );
519
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
520 $cat_id = wp_insert_category($new_category);
9af6317 WP XML-RPC API
ryan authored
521 if(!$cat_id) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
522 return(new IXR_Error(500, __("Sorry, the new category failed.")));
9af6317 WP XML-RPC API
ryan authored
523 }
524
525 return($cat_id);
526 }
527
528 /**
529 * WordPress XML-RPC API
530 * wp_suggestCategories
531 */
532 function wp_suggestCategories($args) {
533 global $wpdb;
534
535 $this->escape($args);
536
7602d17 (int)er the dragon.
matt authored
537 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
538 $username = $args[1];
539 $password = $args[2];
540 $category = $args[3];
541 $max_results = $args[4];
542
543 if(!$this->login_pass_ok($username, $password)) {
544 return($this->error);
545 }
546
547 // Only set a limit if one was provided.
548 $limit = "";
549 if(!empty($max_results)) {
550 $limit = "LIMIT {$max_results}";
551 }
552
553 $category_suggestions = $wpdb->get_results("
554 SELECT cat_ID category_id,
555 cat_name category_name
556 FROM {$wpdb->categories}
557 WHERE cat_name LIKE '{$category}%'
558 {$limit}
559 ");
560
561 return($category_suggestions);
562 }
563
564
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
565 /* Blogger API functions
566 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
567 */
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
568
569
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
570 /* blogger.getUsersBlogs will make more sense once we support multiple blogs */
571 function blogger_getUsersBlogs($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
572
9c9ba0a Escape XMLRPC args.
ryan authored
573 $this->escape($args);
574
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
575 $user_login = $args[1];
576 $user_pass = $args[2];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
577
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
578 if (!$this->login_pass_ok($user_login, $user_pass)) {
579 return $this->error;
580 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
581
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
582 set_current_user(0, $user_login);
583 $is_admin = current_user_can('level_8');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
584
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
585 $struct = array(
586 'isAdmin' => $is_admin,
587 'url' => get_option('home') . '/',
588 'blogid' => '1',
589 'blogName' => get_option('blogname')
590 );
e762c60 Remove debug cruft. fixes #2273
ryan authored
591
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
592 return array($struct);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
593 }
594
595
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
596 /* blogger.getUsersInfo gives your client some info about you, so you don't have to */
597 function blogger_getUserInfo($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
598
9c9ba0a Escape XMLRPC args.
ryan authored
599 $this->escape($args);
600
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
601 $user_login = $args[1];
602 $user_pass = $args[2];
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
603
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
604 if (!$this->login_pass_ok($user_login, $user_pass)) {
605 return $this->error;
606 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
607
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
608 $user_data = get_userdatabylogin($user_login);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
609
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
610 $struct = array(
611 'nickname' => $user_data->nickname,
612 'userid' => $user_data->ID,
613 'url' => $user_data->user_url,
614 'email' => $user_data->user_email,
615 'lastname' => $user_data->last_name,
616 'firstname' => $user_data->first_name
617 );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
618
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
619 return $struct;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
620 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
621
622
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
623 /* blogger.getPost ...gets a post */
624 function blogger_getPost($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
625
9c9ba0a Escape XMLRPC args.
ryan authored
626 $this->escape($args);
627
7602d17 (int)er the dragon.
matt authored
628 $post_ID = (int) $args[1];
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
629 $user_login = $args[2];
630 $user_pass = $args[3];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
631
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
632 if (!$this->login_pass_ok($user_login, $user_pass)) {
633 return $this->error;
634 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
635
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
636 $user_data = get_userdatabylogin($user_login);
637 $post_data = wp_get_single_post($post_ID, ARRAY_A);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
638
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
639 $categories = implode(',', wp_get_post_categories($post_ID));
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
640
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
641 $content = '<title>'.stripslashes($post_data['post_title']).'</title>';
642 $content .= '<category>'.$categories.'</category>';
643 $content .= stripslashes($post_data['post_content']);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
644
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
645 $struct = array(
646 'userid' => $post_data['post_author'],
647 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
648 'content' => $content,
649 'postid' => $post_data['ID']
650 );
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
651
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
652 return $struct;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
653 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
654
655
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
656 /* blogger.getRecentPosts ...gets recent posts */
657 function blogger_getRecentPosts($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
658
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
659 global $wpdb;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
660
9c9ba0a Escape XMLRPC args.
ryan authored
661 $this->escape($args);
662
7602d17 (int)er the dragon.
matt authored
663 $blog_ID = (int) $args[1]; /* though we don't use it yet */
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
664 $user_login = $args[2];
665 $user_pass = $args[3];
666 $num_posts = $args[4];
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
667
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
668 if (!$this->login_pass_ok($user_login, $user_pass)) {
669 return $this->error;
670 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
671
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
672 $posts_list = wp_get_recent_posts($num_posts);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
673
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
674 if (!$posts_list) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
675 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.'));
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
676 return $this->error;
677 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
678
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
679 foreach ($posts_list as $entry) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
680
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
681 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
682 $categories = implode(',', wp_get_post_categories($entry['ID']));
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
683
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
684 $content = '<title>'.stripslashes($entry['post_title']).'</title>';
685 $content .= '<category>'.$categories.'</category>';
686 $content .= stripslashes($entry['post_content']);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
687
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
688 $struct[] = array(
689 'userid' => $entry['post_author'],
690 'dateCreated' => new IXR_Date($post_date),
691 'content' => $content,
692 'postid' => $entry['ID'],
693 );
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
694
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
695 }
696
697 $recent_posts = array();
698 for ($j=0; $j<count($struct); $j++) {
699 array_push($recent_posts, $struct[$j]);
700 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
701
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
702 return $recent_posts;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
703 }
704
705
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
706 /* blogger.getTemplate returns your blog_filename */
707 function blogger_getTemplate($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
708
9c9ba0a Escape XMLRPC args.
ryan authored
709 $this->escape($args);
710
7602d17 (int)er the dragon.
matt authored
711 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
712 $user_login = $args[2];
713 $user_pass = $args[3];
714 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
715
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
716 if (!$this->login_pass_ok($user_login, $user_pass)) {
717 return $this->error;
718 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
719
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
720 set_current_user(0, $user_login);
721 if ( !current_user_can('edit_themes') ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
722 return new IXR_Error(401, __('Sorry, this user can not edit the template.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
723 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
724
efcb63a s/URI/URL/. Props Nazgul. fixes #2666
ryan authored
725 /* warning: here we make the assumption that the weblog's URL is on the same server */
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
726 $filename = get_option('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
727 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
728
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
729 $f = fopen($filename, 'r');
730 $content = fread($f, filesize($filename));
731 fclose($f);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
732
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
733 /* so it is actually editable with a windows/mac client */
734 // FIXME: (or delete me) do we really want to cater to bad clients at the expense of good ones by BEEPing up their line breaks? commented. $content = str_replace("\n", "\r\n", $content);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
735
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
736 return $content;
737 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
738
739
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
740 /* blogger.setTemplate updates the content of blog_filename */
741 function blogger_setTemplate($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
742
9c9ba0a Escape XMLRPC args.
ryan authored
743 $this->escape($args);
744
7602d17 (int)er the dragon.
matt authored
745 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
746 $user_login = $args[2];
747 $user_pass = $args[3];
748 $content = $args[4];
749 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
750
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
751 if (!$this->login_pass_ok($user_login, $user_pass)) {
752 return $this->error;
753 }
1387744 added blogger.newPost
michelvaldrighi authored
754
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
755 set_current_user(0, $user_login);
756 if ( !current_user_can('edit_themes') ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
757 return new IXR_Error(401, __('Sorry, this user can not edit the template.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
758 }
1387744 added blogger.newPost
michelvaldrighi authored
759
efcb63a s/URI/URL/. Props Nazgul. fixes #2666
ryan authored
760 /* warning: here we make the assumption that the weblog's URL is on the same server */
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
761 $filename = get_option('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
762 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
1387744 added blogger.newPost
michelvaldrighi authored
763
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
764 if ($f = fopen($filename, 'w+')) {
765 fwrite($f, $content);
766 fclose($f);
767 } else {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
768 return new IXR_Error(500, __('Either the file is not writable, or something wrong happened. The file has not been updated.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
769 }
1387744 added blogger.newPost
michelvaldrighi authored
770
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
771 return true;
772 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
773
774
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
775 /* blogger.newPost ...creates a new post */
776 function blogger_newPost($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
777
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
778 global $wpdb;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
779
9c9ba0a Escape XMLRPC args.
ryan authored
780 $this->escape($args);
781
7602d17 (int)er the dragon.
matt authored
782 $blog_ID = (int) $args[1]; /* though we don't use it yet */
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
783 $user_login = $args[2];
784 $user_pass = $args[3];
785 $content = $args[4];
786 $publish = $args[5];
1387744 added blogger.newPost
michelvaldrighi authored
787
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
788 if (!$this->login_pass_ok($user_login, $user_pass)) {
789 return $this->error;
790 }
c2fd7b8 Capability updates for xmlrpc.
ryan authored
791
792 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
793 $user = set_current_user(0, $user_login);
794 if ( !current_user_can($cap) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
795 return new IXR_Error(401, __('Sorry, you can not post on this weblog or category.'));
1387744 added blogger.newPost
michelvaldrighi authored
796
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
797 $post_status = ($publish) ? 'publish' : 'draft';
1387744 added blogger.newPost
michelvaldrighi authored
798
c2fd7b8 Capability updates for xmlrpc.
ryan authored
799 $post_author = $user->ID;
1387744 added blogger.newPost
michelvaldrighi authored
800
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
801 $post_title = xmlrpc_getposttitle($content);
802 $post_category = xmlrpc_getpostcategory($content);
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since tha...
ryan authored
803 $post_content = xmlrpc_removepostdata($content);
1387744 added blogger.newPost
michelvaldrighi authored
804
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
805 $post_date = current_time('mysql');
806 $post_date_gmt = current_time('mysql', 1);
1387744 added blogger.newPost
michelvaldrighi authored
807
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
808 $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
1387744 added blogger.newPost
michelvaldrighi authored
809
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
810 $post_ID = wp_insert_post($post_data);
1387744 added blogger.newPost
michelvaldrighi authored
811
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
812 if (!$post_ID) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
813 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
814 }
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
815 $this->attach_uploads( $post_ID, $post_content );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
816
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
817 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
818
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
819 return $post_ID;
1387744 added blogger.newPost
michelvaldrighi authored
820 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
821
822
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
823 /* blogger.editPost ...edits a post */
824 function blogger_editPost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
825
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
826 global $wpdb;
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
827
9c9ba0a Escape XMLRPC args.
ryan authored
828 $this->escape($args);
829
5b22739 More int casts
ryan authored
830 $post_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
831 $user_login = $args[2];
832 $user_pass = $args[3];
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since tha...
ryan authored
833 $content = $args[4];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
834 $publish = $args[5];
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
835
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
836 if (!$this->login_pass_ok($user_login, $user_pass)) {
837 return $this->error;
838 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
839
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
840 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
841
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
842 if (!$actual_post) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
843 return new IXR_Error(404, __('Sorry, no such post.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
844 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
845
9c9ba0a Escape XMLRPC args.
ryan authored
846 $this->escape($actual_post);
847
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
848 set_current_user(0, $user_login);
849 if ( !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
850 return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.'));
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
851
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
852 extract($actual_post);
9c9ba0a Escape XMLRPC args.
ryan authored
853
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
854 if ( ('publish' == $post_status) && !current_user_can('publish_posts') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
855 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
856
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
857 $post_title = xmlrpc_getposttitle($content);
858 $post_category = xmlrpc_getpostcategory($content);
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since tha...
ryan authored
859 $post_content = xmlrpc_removepostdata($content);
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
860
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
861 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt');
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
862
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
863 $result = wp_update_post($postdata);
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
864
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
865 if (!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
866 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
867 }
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
868 $this->attach_uploads( $ID, $post_content );
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
869
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
870 return true;
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
871 }
872
873
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
874 /* blogger.deletePost ...deletes a post */
875 function blogger_deletePost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
876
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
877 global $wpdb;
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
878
9c9ba0a Escape XMLRPC args.
ryan authored
879 $this->escape($args);
880
7602d17 (int)er the dragon.
matt authored
881 $post_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
882 $user_login = $args[2];
883 $user_pass = $args[3];
884 $publish = $args[4];
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
885
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
886 if (!$this->login_pass_ok($user_login, $user_pass)) {
887 return $this->error;
888 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
889
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
890 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
a41790f added blogger.editPost and blogger.deletePost, time to move on to metaWe...
michelvaldrighi authored
891
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
892 if (!$actual_post) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
893 return new IXR_Error(404, __('Sorry, no such post.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
894 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
895
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
896 set_current_user(0, $user_login);
897 if ( !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
898 return new IXR_Error(401, __('Sorry, you do not have the right to delete this post.'));
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
899
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
900 $result = wp_delete_post($post_ID);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
901
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
902 if (!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
903 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
904 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
905
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
906 return true;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
907 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
908
909
910
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
911 /* MetaWeblog API functions
912 * specs on wherever Dave Winer wants them to be
913 */
80b3445 fixed comment_status screwup, removed debug stuff, screwed up big time, ...
michelvaldrighi authored
914
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
915 /* metaweblog.newPost creates a post */
916 function mw_newPost($args) {
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
917
d1ea1c9 Use instead of hardcoding 1. Do we really need a separate default cate...
ryan authored
918 global $wpdb, $post_default_category;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
919
9c9ba0a Escape XMLRPC args.
ryan authored
920 $this->escape($args);
921
7602d17 (int)er the dragon.
matt authored
922 $blog_ID = (int) $args[0]; // we will support this in the near future
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
923 $user_login = $args[1];
924 $user_pass = $args[2];
925 $content_struct = $args[3];
926 $publish = $args[4];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
927
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
928 if (!$this->login_pass_ok($user_login, $user_pass)) {
929 return $this->error;
930 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
931
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
932 $user = set_current_user(0, $user_login);
933 if ( !current_user_can('publish_posts') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
934 return new IXR_Error(401, __('Sorry, you can not post on this weblog or category.'));
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
935
9af6317 WP XML-RPC API
ryan authored
936 // The post_type defaults to post, but could also be page.
937 $post_type = "post";
938 if(
939 !empty($content_struct["post_type"])
940 && ($content_struct["post_type"] == "page")
941 ) {
942 $post_type = "page";
943 }
944
945 // Let WordPress generate the post_name (slug) unless
946 // one has been provided.
947 $post_name = "";
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
948 if(isset($content_struct["wp_slug"])) {
9af6317 WP XML-RPC API
ryan authored
949 $post_name = $content_struct["wp_slug"];
950 }
951
952 // Only use a password if one was given.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
953 if(isset($content_struct["wp_password"])) {
9af6317 WP XML-RPC API
ryan authored
954 $post_password = $content_struct["wp_password"];
955 }
956
957 // Only set a post parent if one was provided.
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
958 if(isset($content_struct["wp_page_parent_id"])) {
9af6317 WP XML-RPC API
ryan authored
959 $post_parent = $content_struct["wp_page_parent_id"];
960 }
961
962 // Only set the menu_order if it was provided.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
963 if(isset($content_struct["wp_page_order"])) {
9af6317 WP XML-RPC API
ryan authored
964 $menu_order = $content_struct["wp_page_order"];
965 }
966
c2fd7b8 Capability updates for xmlrpc.
ryan authored
967 $post_author = $user->ID;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
968
e71e25d XMLRPC API updates.
ryan authored
969 // If an author id was provided then use it instead.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
970 if(
971 isset($content_struct["wp_author_id"])
972 && ($user->ID != $content_struct["wp_author_id"])
973 ) {
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
974 switch($post_type) {
975 case "post":
976 if(!current_user_can("edit_others_posts")) {
977 return(new IXR_Error(401, "You are not allowed to " .
978 "post as this user"));
979 }
980 break;
981 case "page":
982 if(!current_user_can("edit_others_pages")) {
983 return(new IXR_Error(401, "You are not allowed to " .
984 "create pages as this user"));
985 }
986 break;
987 default:
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
988 return(new IXR_Error(401, __("Invalid post type.")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
989 break;
990 }
e71e25d XMLRPC API updates.
ryan authored
991 $post_author = $content_struct["wp_author_id"];
992 }
993
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
994 $post_title = $content_struct['title'];
99df7e3 Cleaning up filters and format-to-post
saxmatt authored
995 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
996 $post_status = $publish ? 'publish' : 'draft';
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
997
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
998 $post_excerpt = $content_struct['mt_excerpt'];
999 $post_more = $content_struct['mt_text_more'];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1000
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1001 if(isset($content_struct["mt_allow_comments"])) {
1002 switch((int) $content_struct["mt_allow_comments"]) {
1003 case 0:
1004 $comment_status = "closed";
1005 break;
1006 case 1:
1007 $comment_status = "open";
1008 break;
1009 default:
1010 $comment_status = get_option("default_comment_status");
1011 break;
1012 }
1013 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1014
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1015 if(isset($content_struct["mt_allow_pings"])) {
1016 switch((int) $content_struct["mt_allow_pings"]) {
1017 case 0:
1018 $ping_status = "closed";
1019 break;
1020 case 1:
1021 $ping_status = "open";
1022 break;
1023 default:
1024 $ping_status = get_option("default_ping_status");
1025 break;
1026 }
1027 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1028
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1029 if ($post_more) {
1030 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
1031 }
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post() ...
ryan authored
1032
97bcc74 Handle array of mt_tb_ping_urls. Props bafonso. fixes #3721
ryan authored
1033 $to_ping = $content_struct['mt_tb_ping_urls'];
1034 if ( is_array($to_ping) )
1035 $to_ping = implode(' ', $to_ping);
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post() ...
ryan authored
1036
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1037 // Do some timestamp voodoo
1038 $dateCreatedd = $content_struct['dateCreated'];
9367489 dateCreated typos
michelvaldrighi authored
1039 if (!empty($dateCreatedd)) {
06d0270 I was stupidly parsing dateCreated even when it was empty -- hence the c...
michelvaldrighi authored
1040 $dateCreated = $dateCreatedd->getIso();
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1041 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #4158 ...
ryan authored
1042 $post_date_gmt = iso8601_to_datetime($dateCreated. "Z", GMT);
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1043 } else {
1044 $post_date = current_time('mysql');
1045 $post_date_gmt = current_time('mysql', 1);
1046 }
1047
1048 $catnames = $content_struct['categories'];
83e6c81 s/logio/logIO/. Remove logio calls from the one function in functions-p...
rboren authored
1049 logIO('O', 'Post cats: ' . printr($catnames,true));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1050 $post_category = array();
1051
6ff9558 Make sure category list is actually a list. http://mosquito.wordpress.o...
ryan authored
1052 if (is_array($catnames)) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1053 foreach ($catnames as $cat) {
1054 $post_category[] = get_cat_ID($cat);
1055 }
54766ea XMLRPC category fixes
ryan authored
1056 }
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
1057
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1058 // We've got all the data -- post it:
3c05580 Reverting [5278]. It breaks mw_getRecentPosts.
ryan authored
1059 $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order');
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1060
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
1061 $post_ID = wp_insert_post($postdata);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1062
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1063 if (!$post_ID) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1064 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1065 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1066
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
1067 $this->attach_uploads( $post_ID, $post_content );
1068
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1069 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1070
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1071 return strval($post_ID);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1072 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1073
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
1074 function attach_uploads( $post_ID, $post_content ) {
1075 global $wpdb;
1076
1077 // find any unattached files
1078 $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '-1' AND post_type = 'attachment'" );
1079 if( is_array( $attachments ) ) {
1080 foreach( $attachments as $file ) {
1081 if( strpos( $post_content, $file->guid ) !== false ) {
1082 $wpdb->query( "UPDATE {$wpdb->posts} SET post_parent = '$post_ID' WHERE ID = '{$file->ID}'" );
1083 }
1084 }
1085 }
1086 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1087
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1088 /* metaweblog.editPost ...edits a post */
1089 function mw_editPost($args) {
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1090
d1ea1c9 Use instead of hardcoding 1. Do we really need a separate default cate...
ryan authored
1091 global $wpdb, $post_default_category;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1092
9c9ba0a Escape XMLRPC args.
ryan authored
1093 $this->escape($args);
1094
5b22739 More int casts
ryan authored
1095 $post_ID = (int) $args[0];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1096 $user_login = $args[1];
1097 $user_pass = $args[2];
1098 $content_struct = $args[3];
1099 $publish = $args[4];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1100
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1101 if (!$this->login_pass_ok($user_login, $user_pass)) {
1102 return $this->error;
1103 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1104
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1105 $user = set_current_user(0, $user_login);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1106
9af6317 WP XML-RPC API
ryan authored
1107 // The post_type defaults to post, but could also be page.
1108 $post_type = "post";
1109 if(
1110 !empty($content_struct["post_type"])
1111 && ($content_struct["post_type"] == "page")
1112 ) {
1113 $post_type = "page";
1114 }
1115
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1116 // Edit page caps are checked in editPage. Just check post here.
1117 if ( ( 'post' == $post_type ) && !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1118 return new IXR_Error(401, __('Sorry, you can not edit this post.'));
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1119
1120 $postdata = wp_get_single_post($post_ID, ARRAY_A);
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return empty ...
ryan authored
1121
1122 // If there is no post data for the give post id, stop
1123 // now and return an error. Other wise a new post will be
1124 // created (which was the old behavior).
1125 if(empty($postdata["ID"])) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1126 return(new IXR_Error(404, __("Invalid post id.")));
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return empty ...
ryan authored
1127 }
1128
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1129 extract($postdata);
1130 $this->escape($postdata);
1131
9af6317 WP XML-RPC API
ryan authored
1132 // Let WordPress manage slug if none was provided.
1133 $post_name = "";
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1134 if(isset($content_struct["wp_slug"])) {
9af6317 WP XML-RPC API
ryan authored
1135 $post_name = $content_struct["wp_slug"];
1136 }
1137
1138 // Only use a password if one was given.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1139 if(isset($content_struct["wp_password"])) {
9af6317 WP XML-RPC API
ryan authored
1140 $post_password = $content_struct["wp_password"];
1141 }
1142
1143 // Only set a post parent if one was given.
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
1144 if(isset($content_struct["wp_page_parent_id"])) {
9af6317 WP XML-RPC API
ryan authored
1145 $post_parent = $content_struct["wp_page_parent_id"];
1146 }
1147
9bc0cc2 More XML-RPC API enhancements from Joseph Scott.
ryan authored
1148 // Only set the menu_order if it was given.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1149 if(isset($content_struct["wp_page_order"])) {
9af6317 WP XML-RPC API
ryan authored
1150 $menu_order = $content_struct["wp_page_order"];
1151 }
1152
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1153 $post_author = $user->ID;
1154
9bc0cc2 More XML-RPC API enhancements from Joseph Scott.
ryan authored
1155 // Only set the post_author if one is set.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1156 if(
1157 isset($content_struct["wp_author_id"])
1158 && ($user->ID != $content_struct["wp_author_id"])
1159 ) {
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
1160 switch($post_type) {
1161 case "post":
1162 if(!current_user_can("edit_others_posts")) {
1163 return(new IXR_Error(401, "You are not allowed to " .
1164 "change the post author as this user."));
1165 }
1166 break;
1167 case "page":
1168 if(!current_user_can("edit_others_pages")) {
1169 return(new IXR_Error(401, "You are not allowed to " .
1170 "change the page author as this user."));
1171 }
1172 break;
1173 default:
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1174 return(new IXR_Error(401, __("Invalid post type.")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
1175 break;
1176 }
e71e25d XMLRPC API updates.
ryan authored
1177 $post_author = $content_struct["wp_author_id"];
1178 }
1179
1180 // Only set ping_status if it was provided.
1181 if(isset($content_struct["mt_allow_pings"])) {
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1182 switch((int) $content_struct["mt_allow_pings"]) {
1183 case 0:
e71e25d XMLRPC API updates.
ryan authored
1184 $ping_status = "closed";
1185 break;
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1186 case 1:
e71e25d XMLRPC API updates.
ryan authored
1187 $ping_status = "open";
1188 break;
1189 }
9bc0cc2 More XML-RPC API enhancements from Joseph Scott.
ryan authored
1190 }
1191
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1192 $post_title = $content_struct['title'];
99df7e3 Cleaning up filters and format-to-post
saxmatt authored
1193 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1194 $catnames = $content_struct['categories'];
bdfab81 Default category and pingback check fixes.
ryan authored
1195
1196 $post_category = array();
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
1197
6ff9558 Make sure category list is actually a list. http://mosquito.wordpress.o...
ryan authored
1198 if (is_array($catnames)) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1199 foreach ($catnames as $cat) {
1200 $post_category[] = get_cat_ID($cat);
1201 }
54766ea XMLRPC category fixes
ryan authored
1202 }
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1203
1204 $post_excerpt = $content_struct['mt_excerpt'];
1205 $post_more = $content_struct['mt_text_more'];
1206 $post_status = $publish ? 'publish' : 'draft';
1207
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1208 if ( ('publish' == $post_status) ) {
1209 if ( ( 'page' == $post_type ) && !current_user_can('publish_pages') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1210 return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.'));
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1211 else if ( !current_user_can('publish_posts') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1212 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1213 }
1214
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1215 if ($post_more) {
1216 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
1217 }
1218
97bcc74 Handle array of mt_tb_ping_urls. Props bafonso. fixes #3721
ryan authored
1219 $to_ping = $content_struct['mt_tb_ping_urls'];
1220 if ( is_array($to_ping) )
1221 $to_ping = implode(' ', $to_ping);
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1222
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
1223 if(isset($content_struct["mt_allow_comments"])) {
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Props ...
ryan authored
1224 $comment_status = (int) $content_struct["mt_allow_comments"];
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
1225 }
1226
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1227 // Do some timestamp voodoo
9367489 dateCreated typos
michelvaldrighi authored
1228 $dateCreatedd = $content_struct['dateCreated'];
1229 if (!empty($dateCreatedd)) {
06d0270 I was stupidly parsing dateCreated even when it was empty -- hence the c...
michelvaldrighi authored
1230 $dateCreated = $dateCreatedd->getIso();
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1231 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #4158 ...
ryan authored
1232 $post_date_gmt = iso8601_to_datetime($dateCreated . "Z", GMT);
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1233 } else {
1234 $post_date = $postdata['post_date'];
1235 $post_date_gmt = $postdata['post_date_gmt'];
1236 }
1237
1238 // We've got all the data -- post it:
3c05580 Reverting [5278]. It breaks mw_getRecentPosts.
ryan authored
1239 $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1240
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post() ...
ryan authored
1241 $result = wp_update_post($newpost);
1242 if (!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1243 return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1244 }
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
1245 $this->attach_uploads( $ID, $post_content );
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1246
1247 logIO('O',"(MW) Edited ! ID: $post_ID");
1248
1249 return true;
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit ou...
michelvaldrighi authored
1250 }
1251
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1252
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1253 /* metaweblog.getPost ...returns a post */
1254 function mw_getPost($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1255
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1256 global $wpdb;
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit ou...
michelvaldrighi authored
1257
9c9ba0a Escape XMLRPC args.
ryan authored
1258 $this->escape($args);
1259
7602d17 (int)er the dragon.
matt authored
1260 $post_ID = (int) $args[0];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1261 $user_login = $args[1];
1262 $user_pass = $args[2];
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit ou...
michelvaldrighi authored
1263
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1264 if (!$this->login_pass_ok($user_login, $user_pass)) {
1265 return $this->error;
1266 }
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit ou...
michelvaldrighi authored
1267
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
1268 $postdata = wp_get_single_post($post_ID, ARRAY_A);
b763f6c added mw.getRecentPosts, mw.getCategories, refactored the living shit ou...
michelvaldrighi authored
1269
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...