Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 1924 lines (1480 sloc) 54.902 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 …
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. P…
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…
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
9ce729e Content-Type, not Content-type, as headers are case sensitive. Props …
rob1n 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>
fe5e71c RSD link fixes from Joseph Scott. fixes #4329 for 2.3
ryan authored
31 <api name="WordPress" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('wpurl') ?>/xmlrpc.php" />
32 <api name="Movable Type" blogID="1" preferred="true" apiLink="<?php bloginfo_rss('wpurl') ?>/xmlrpc.php" />
33 <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('wpurl') ?>/xmlrpc.php" />
34 <api name="Blogger" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('wpurl') ?>/xmlrpc.php" />
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
35 </apis>
36 </service>
37 </rsd>
38 <?php
39 exit;
40 }
41
770613e Admin includes reorg. see #4334
ryan authored
42 include_once(ABSPATH . 'wp-admin/includes/admin.php');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
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 repl…
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 tim…
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 repl…
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 …
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.newMediaObjec…
michelvaldrighi authored
72
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
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. fix…
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 repl…
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 repl…
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 repl…
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 repl…
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 repl…
michelvaldrighi authored
147 function login_pass_ok($user_login, $user_pass) {
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
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. fix…
ryan authored
150 return false;
151 }
152 return true;
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
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.
0c80a47 explicitly state Zulu time for desktop editors. Props Erik Barzeski …
markjaquith authored
211 $page_date = mysql2date("Ymd\TH:i:s\Z", $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 emp…
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 #41…
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++) {
0c80a47 explicitly state Zulu time for desktop editors. Props Erik Barzeski …
markjaquith authored
441 $post_date = mysql2date("Ymd\TH:i:s\Z", $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 #41…
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 // If no slug was provided make it empty so that
494 // WordPress will generate one.
495 if(empty($category["slug"])) {
496 $category["slug"] = "";
497 }
498
499 // If no parent_id was provided make it empty
500 // so that it will be a top level page (no parent).
c8997ff Reverse logic.
ryan authored
501 if ( !isset($category["parent_id"]) )
9af6317 WP XML-RPC API
ryan authored
502 $category["parent_id"] = "";
503
504 // If no description was provided make it empty.
505 if(empty($category["description"])) {
506 $category["description"] = "";
507 }
d0f79bb trailing tabs and whitespace cleanup.
markjaquith authored
508
9af6317 WP XML-RPC API
ryan authored
509 $new_category = array(
510 "cat_name" => $category["name"],
511 "category_nicename" => $category["slug"],
512 "category_parent" => $category["parent_id"],
513 "category_description" => $category["description"]
514 );
515
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
516 $cat_id = wp_insert_category($new_category);
9af6317 WP XML-RPC API
ryan authored
517 if(!$cat_id) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
518 return(new IXR_Error(500, __("Sorry, the new category failed.")));
9af6317 WP XML-RPC API
ryan authored
519 }
520
521 return($cat_id);
522 }
523
524 /**
525 * WordPress XML-RPC API
526 * wp_suggestCategories
527 */
528 function wp_suggestCategories($args) {
529 global $wpdb;
530
531 $this->escape($args);
532
7602d17 (int)er the dragon.
matt authored
533 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
534 $username = $args[1];
535 $password = $args[2];
536 $category = $args[3];
070d2fd Int cast. Props to Alexander Concha for the find, Joseph Scott for t…
markjaquith authored
537 $max_results = (int) $args[4];
9af6317 WP XML-RPC API
ryan authored
538
539 if(!$this->login_pass_ok($username, $password)) {
540 return($this->error);
541 }
542
543 // Only set a limit if one was provided.
544 $limit = "";
545 if(!empty($max_results)) {
546 $limit = "LIMIT {$max_results}";
547 }
548
549 $category_suggestions = $wpdb->get_results("
550 SELECT cat_ID category_id,
551 cat_name category_name
552 FROM {$wpdb->categories}
553 WHERE cat_name LIKE '{$category}%'
554 {$limit}
555 ");
556
557 return($category_suggestions);
558 }
559
560
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
561 /* Blogger API functions
562 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
563 */
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
564
565
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
566 /* blogger.getUsersBlogs will make more sense once we support multiple blogs */
567 function blogger_getUsersBlogs($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
568
9c9ba0a Escape XMLRPC args.
ryan authored
569 $this->escape($args);
570
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
571 $user_login = $args[1];
572 $user_pass = $args[2];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
573
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
574 if (!$this->login_pass_ok($user_login, $user_pass)) {
575 return $this->error;
576 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
577
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
578 set_current_user(0, $user_login);
579 $is_admin = current_user_can('level_8');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
580
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
581 $struct = array(
582 'isAdmin' => $is_admin,
583 'url' => get_option('home') . '/',
584 'blogid' => '1',
585 'blogName' => get_option('blogname')
586 );
e762c60 Remove debug cruft. fixes #2273
ryan authored
587
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
588 return array($struct);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
589 }
590
591
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
592 /* blogger.getUsersInfo gives your client some info about you, so you don't have to */
593 function blogger_getUserInfo($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
594
9c9ba0a Escape XMLRPC args.
ryan authored
595 $this->escape($args);
596
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
597 $user_login = $args[1];
598 $user_pass = $args[2];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
599
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
600 if (!$this->login_pass_ok($user_login, $user_pass)) {
601 return $this->error;
602 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
603
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
604 $user_data = get_userdatabylogin($user_login);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
605
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
606 $struct = array(
607 'nickname' => $user_data->nickname,
608 'userid' => $user_data->ID,
609 'url' => $user_data->user_url,
610 'email' => $user_data->user_email,
611 'lastname' => $user_data->last_name,
612 'firstname' => $user_data->first_name
613 );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
614
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
615 return $struct;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
616 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
617
618
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
619 /* blogger.getPost ...gets a post */
620 function blogger_getPost($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
621
9c9ba0a Escape XMLRPC args.
ryan authored
622 $this->escape($args);
623
7602d17 (int)er the dragon.
matt authored
624 $post_ID = (int) $args[1];
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
625 $user_login = $args[2];
626 $user_pass = $args[3];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
627
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
628 if (!$this->login_pass_ok($user_login, $user_pass)) {
629 return $this->error;
630 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
631
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
632 $user_data = get_userdatabylogin($user_login);
633 $post_data = wp_get_single_post($post_ID, ARRAY_A);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
634
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
635 $categories = implode(',', wp_get_post_categories($post_ID));
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
636
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
637 $content = '<title>'.stripslashes($post_data['post_title']).'</title>';
638 $content .= '<category>'.$categories.'</category>';
639 $content .= stripslashes($post_data['post_content']);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
640
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
641 $struct = array(
642 'userid' => $post_data['post_author'],
643 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
644 'content' => $content,
645 'postid' => $post_data['ID']
646 );
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
647
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
648 return $struct;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
649 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
650
651
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
652 /* blogger.getRecentPosts ...gets recent posts */
653 function blogger_getRecentPosts($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
654
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
655 global $wpdb;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
656
9c9ba0a Escape XMLRPC args.
ryan authored
657 $this->escape($args);
658
7602d17 (int)er the dragon.
matt authored
659 $blog_ID = (int) $args[1]; /* though we don't use it yet */
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
660 $user_login = $args[2];
661 $user_pass = $args[3];
662 $num_posts = $args[4];
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
663
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
664 if (!$this->login_pass_ok($user_login, $user_pass)) {
665 return $this->error;
666 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
667
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
668 $posts_list = wp_get_recent_posts($num_posts);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
669
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
670 if (!$posts_list) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
671 $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. fix…
ryan authored
672 return $this->error;
673 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
674
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
675 foreach ($posts_list as $entry) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
676
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
677 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
678 $categories = implode(',', wp_get_post_categories($entry['ID']));
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
679
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
680 $content = '<title>'.stripslashes($entry['post_title']).'</title>';
681 $content .= '<category>'.$categories.'</category>';
682 $content .= stripslashes($entry['post_content']);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
683
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
684 $struct[] = array(
685 'userid' => $entry['post_author'],
686 'dateCreated' => new IXR_Date($post_date),
687 'content' => $content,
688 'postid' => $entry['ID'],
689 );
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
690
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
691 }
692
693 $recent_posts = array();
694 for ($j=0; $j<count($struct); $j++) {
695 array_push($recent_posts, $struct[$j]);
696 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
697
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
698 return $recent_posts;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
699 }
700
701
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
702 /* blogger.getTemplate returns your blog_filename */
703 function blogger_getTemplate($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
704
9c9ba0a Escape XMLRPC args.
ryan authored
705 $this->escape($args);
706
7602d17 (int)er the dragon.
matt authored
707 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
708 $user_login = $args[2];
709 $user_pass = $args[3];
710 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
711
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
712 if (!$this->login_pass_ok($user_login, $user_pass)) {
713 return $this->error;
714 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
715
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
716 set_current_user(0, $user_login);
717 if ( !current_user_can('edit_themes') ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
718 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 repl…
michelvaldrighi authored
719 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
720
efcb63a s/URI/URL/. Props Nazgul. fixes #2666
ryan authored
721 /* 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
722 $filename = get_option('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
723 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
724
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
725 $f = fopen($filename, 'r');
726 $content = fread($f, filesize($filename));
727 fclose($f);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
728
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
729 /* so it is actually editable with a windows/mac client */
730 // 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
731
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
732 return $content;
733 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
734
735
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
736 /* blogger.setTemplate updates the content of blog_filename */
737 function blogger_setTemplate($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
738
9c9ba0a Escape XMLRPC args.
ryan authored
739 $this->escape($args);
740
7602d17 (int)er the dragon.
matt authored
741 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
742 $user_login = $args[2];
743 $user_pass = $args[3];
744 $content = $args[4];
745 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
746
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
747 if (!$this->login_pass_ok($user_login, $user_pass)) {
748 return $this->error;
749 }
1387744 added blogger.newPost
michelvaldrighi authored
750
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
751 set_current_user(0, $user_login);
752 if ( !current_user_can('edit_themes') ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
753 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 repl…
michelvaldrighi authored
754 }
1387744 added blogger.newPost
michelvaldrighi authored
755
efcb63a s/URI/URL/. Props Nazgul. fixes #2666
ryan authored
756 /* 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
757 $filename = get_option('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
758 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
1387744 added blogger.newPost
michelvaldrighi authored
759
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
760 if ($f = fopen($filename, 'w+')) {
761 fwrite($f, $content);
762 fclose($f);
763 } else {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
764 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 repl…
michelvaldrighi authored
765 }
1387744 added blogger.newPost
michelvaldrighi authored
766
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
767 return true;
768 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
769
770
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
771 /* blogger.newPost ...creates a new post */
772 function blogger_newPost($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
773
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
774 global $wpdb;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
775
9c9ba0a Escape XMLRPC args.
ryan authored
776 $this->escape($args);
777
7602d17 (int)er the dragon.
matt authored
778 $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 repl…
michelvaldrighi authored
779 $user_login = $args[2];
780 $user_pass = $args[3];
781 $content = $args[4];
782 $publish = $args[5];
1387744 added blogger.newPost
michelvaldrighi authored
783
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
784 if (!$this->login_pass_ok($user_login, $user_pass)) {
785 return $this->error;
786 }
c2fd7b8 Capability updates for xmlrpc.
ryan authored
787
788 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
789 $user = set_current_user(0, $user_login);
790 if ( !current_user_can($cap) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
791 return new IXR_Error(401, __('Sorry, you can not post on this weblog or category.'));
1387744 added blogger.newPost
michelvaldrighi authored
792
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
793 $post_status = ($publish) ? 'publish' : 'draft';
1387744 added blogger.newPost
michelvaldrighi authored
794
c2fd7b8 Capability updates for xmlrpc.
ryan authored
795 $post_author = $user->ID;
1387744 added blogger.newPost
michelvaldrighi authored
796
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
797 $post_title = xmlrpc_getposttitle($content);
798 $post_category = xmlrpc_getpostcategory($content);
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since …
ryan authored
799 $post_content = xmlrpc_removepostdata($content);
1387744 added blogger.newPost
michelvaldrighi authored
800
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
801 $post_date = current_time('mysql');
802 $post_date_gmt = current_time('mysql', 1);
1387744 added blogger.newPost
michelvaldrighi authored
803
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
804 $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
805
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
806 $post_ID = wp_insert_post($post_data);
1387744 added blogger.newPost
michelvaldrighi authored
807
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
808 if (!$post_ID) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
809 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 repl…
michelvaldrighi authored
810 }
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
811 $this->attach_uploads( $post_ID, $post_content );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
812
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
813 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
814
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
815 return $post_ID;
1387744 added blogger.newPost
michelvaldrighi authored
816 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
817
818
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
819 /* blogger.editPost ...edits a post */
820 function blogger_editPost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
821
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
822 global $wpdb;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
823
9c9ba0a Escape XMLRPC args.
ryan authored
824 $this->escape($args);
825
5b22739 More int casts
ryan authored
826 $post_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
827 $user_login = $args[2];
828 $user_pass = $args[3];
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since …
ryan authored
829 $content = $args[4];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
830 $publish = $args[5];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
831
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
832 if (!$this->login_pass_ok($user_login, $user_pass)) {
833 return $this->error;
834 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
835
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
836 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
837
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
838 if (!$actual_post) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
839 return new IXR_Error(404, __('Sorry, no such post.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
840 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
841
9c9ba0a Escape XMLRPC args.
ryan authored
842 $this->escape($actual_post);
843
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
844 set_current_user(0, $user_login);
845 if ( !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
846 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 met…
michelvaldrighi authored
847
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
848 extract($actual_post);
9c9ba0a Escape XMLRPC args.
ryan authored
849
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
850 if ( ('publish' == $post_status) && !current_user_can('publish_posts') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
851 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
852
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
853 $post_title = xmlrpc_getposttitle($content);
854 $post_category = xmlrpc_getpostcategory($content);
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since …
ryan authored
855 $post_content = xmlrpc_removepostdata($content);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
856
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
857 $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 met…
michelvaldrighi authored
858
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
859 $result = wp_update_post($postdata);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
860
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
861 if (!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
862 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 repl…
michelvaldrighi authored
863 }
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
864 $this->attach_uploads( $ID, $post_content );
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
865
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
866 return true;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
867 }
868
869
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
870 /* blogger.deletePost ...deletes a post */
871 function blogger_deletePost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
872
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
873 global $wpdb;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
874
9c9ba0a Escape XMLRPC args.
ryan authored
875 $this->escape($args);
876
7602d17 (int)er the dragon.
matt authored
877 $post_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
878 $user_login = $args[2];
879 $user_pass = $args[3];
880 $publish = $args[4];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
881
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
882 if (!$this->login_pass_ok($user_login, $user_pass)) {
883 return $this->error;
884 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
885
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
886 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
887
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
888 if (!$actual_post) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
889 return new IXR_Error(404, __('Sorry, no such post.'));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
890 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
891
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
892 set_current_user(0, $user_login);
893 if ( !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
894 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
895
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
896 $result = wp_delete_post($post_ID);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
897
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
898 if (!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
899 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 repl…
michelvaldrighi authored
900 }
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 repl…
michelvaldrighi authored
902 return true;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
903 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
904
905
906
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
907 /* MetaWeblog API functions
908 * specs on wherever Dave Winer wants them to be
909 */
80b3445 fixed comment_status screwup, removed debug stuff, screwed up big tim…
michelvaldrighi authored
910
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
911 /* metaweblog.newPost creates a post */
912 function mw_newPost($args) {
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
913
d1ea1c9 Use instead of hardcoding 1. Do we really need a separate default c…
ryan authored
914 global $wpdb, $post_default_category;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
915
9c9ba0a Escape XMLRPC args.
ryan authored
916 $this->escape($args);
917
7602d17 (int)er the dragon.
matt authored
918 $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 repl…
michelvaldrighi authored
919 $user_login = $args[1];
920 $user_pass = $args[2];
921 $content_struct = $args[3];
922 $publish = $args[4];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
923
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
924 if (!$this->login_pass_ok($user_login, $user_pass)) {
925 return $this->error;
926 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
927
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
928 $user = set_current_user(0, $user_login);
929 if ( !current_user_can('publish_posts') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
930 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
931
9af6317 WP XML-RPC API
ryan authored
932 // The post_type defaults to post, but could also be page.
933 $post_type = "post";
934 if(
935 !empty($content_struct["post_type"])
936 && ($content_struct["post_type"] == "page")
937 ) {
938 $post_type = "page";
939 }
940
941 // Let WordPress generate the post_name (slug) unless
942 // one has been provided.
943 $post_name = "";
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
944 if(isset($content_struct["wp_slug"])) {
9af6317 WP XML-RPC API
ryan authored
945 $post_name = $content_struct["wp_slug"];
946 }
947
948 // Only use a password if one was given.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
949 if(isset($content_struct["wp_password"])) {
9af6317 WP XML-RPC API
ryan authored
950 $post_password = $content_struct["wp_password"];
951 }
952
953 // Only set a post parent if one was provided.
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
954 if(isset($content_struct["wp_page_parent_id"])) {
9af6317 WP XML-RPC API
ryan authored
955 $post_parent = $content_struct["wp_page_parent_id"];
956 }
957
958 // Only set the menu_order if it was provided.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
959 if(isset($content_struct["wp_page_order"])) {
9af6317 WP XML-RPC API
ryan authored
960 $menu_order = $content_struct["wp_page_order"];
961 }
962
c2fd7b8 Capability updates for xmlrpc.
ryan authored
963 $post_author = $user->ID;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
964
e71e25d XMLRPC API updates.
ryan authored
965 // If an author id was provided then use it instead.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
966 if(
967 isset($content_struct["wp_author_id"])
968 && ($user->ID != $content_struct["wp_author_id"])
969 ) {
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
970 switch($post_type) {
971 case "post":
972 if(!current_user_can("edit_others_posts")) {
8a3ed38 More xmlrpc.php i18n fixes from nbachiyski. fixes #3997
rob1n authored
973 return(new IXR_Error(401, __("You are not allowed to post as this user")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
974 }
975 break;
976 case "page":
977 if(!current_user_can("edit_others_pages")) {
8a3ed38 More xmlrpc.php i18n fixes from nbachiyski. fixes #3997
rob1n authored
978 return(new IXR_Error(401, __("You are not allowed to create pages as this user")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
979 }
980 break;
981 default:
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
982 return(new IXR_Error(401, __("Invalid post type.")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
983 break;
984 }
e71e25d XMLRPC API updates.
ryan authored
985 $post_author = $content_struct["wp_author_id"];
986 }
987
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
988 $post_title = $content_struct['title'];
99df7e3 Cleaning up filters and format-to-post
saxmatt authored
989 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
990 $post_status = $publish ? 'publish' : 'draft';
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
991
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
992 $post_excerpt = $content_struct['mt_excerpt'];
993 $post_more = $content_struct['mt_text_more'];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
994
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
995 if(isset($content_struct["mt_allow_comments"])) {
996 switch((int) $content_struct["mt_allow_comments"]) {
997 case 0:
998 $comment_status = "closed";
999 break;
1000 case 1:
1001 $comment_status = "open";
1002 break;
1003 default:
1004 $comment_status = get_option("default_comment_status");
1005 break;
1006 }
1007 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1008
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1009 if(isset($content_struct["mt_allow_pings"])) {
1010 switch((int) $content_struct["mt_allow_pings"]) {
1011 case 0:
1012 $ping_status = "closed";
1013 break;
1014 case 1:
1015 $ping_status = "open";
1016 break;
1017 default:
1018 $ping_status = get_option("default_ping_status");
1019 break;
1020 }
1021 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1022
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1023 if ($post_more) {
1024 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
1025 }
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post…
ryan authored
1026
97bcc74 Handle array of mt_tb_ping_urls. Props bafonso. fixes #3721
ryan authored
1027 $to_ping = $content_struct['mt_tb_ping_urls'];
1028 if ( is_array($to_ping) )
1029 $to_ping = implode(' ', $to_ping);
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post…
ryan authored
1030
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1031 // Do some timestamp voodoo
1032 $dateCreatedd = $content_struct['dateCreated'];
9367489 dateCreated typos
michelvaldrighi authored
1033 if (!empty($dateCreatedd)) {
06d0270 I was stupidly parsing dateCreated even when it was empty -- hence th…
michelvaldrighi authored
1034 $dateCreated = $dateCreatedd->getIso();
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1035 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #41…
ryan authored
1036 $post_date_gmt = iso8601_to_datetime($dateCreated. "Z", GMT);
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1037 } else {
1038 $post_date = current_time('mysql');
1039 $post_date_gmt = current_time('mysql', 1);
1040 }
1041
1042 $catnames = $content_struct['categories'];
83e6c81 s/logio/logIO/. Remove logio calls from the one function in function…
rboren authored
1043 logIO('O', 'Post cats: ' . printr($catnames,true));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1044 $post_category = array();
1045
6ff9558 Make sure category list is actually a list. http://mosquito.wordpres…
ryan authored
1046 if (is_array($catnames)) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1047 foreach ($catnames as $cat) {
1048 $post_category[] = get_cat_ID($cat);
1049 }
54766ea XMLRPC category fixes
ryan authored
1050 }
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
1051
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1052 // We've got all the data -- post it:
3c05580 Reverting [5278]. It breaks mw_getRecentPosts.
ryan authored
1053 $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
1054
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
1055 $post_ID = wp_insert_post($postdata);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1056
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1057 if (!$post_ID) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1058 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 repl…
michelvaldrighi authored
1059 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1060
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
1061 $this->attach_uploads( $post_ID, $post_content );
1062
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1063 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1064
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1065 return strval($post_ID);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1066 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1067
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
1068 function attach_uploads( $post_ID, $post_content ) {
1069 global $wpdb;
1070
1071 // find any unattached files
1072 $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '-1' AND post_type = 'attachment'" );
1073 if( is_array( $attachments ) ) {
1074 foreach( $attachments as $file ) {
1075 if( strpos( $post_content, $file->guid ) !== false ) {
1076 $wpdb->query( "UPDATE {$wpdb->posts} SET post_parent = '$post_ID' WHERE ID = '{$file->ID}'" );
1077 }
1078 }
1079 }
1080 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1081
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1082 /* metaweblog.editPost ...edits a post */
1083 function mw_editPost($args) {
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1084
d1ea1c9 Use instead of hardcoding 1. Do we really need a separate default c…
ryan authored
1085 global $wpdb, $post_default_category;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1086
9c9ba0a Escape XMLRPC args.
ryan authored
1087 $this->escape($args);
1088
5b22739 More int casts
ryan authored
1089 $post_ID = (int) $args[0];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1090 $user_login = $args[1];
1091 $user_pass = $args[2];
1092 $content_struct = $args[3];
1093 $publish = $args[4];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1094
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1095 if (!$this->login_pass_ok($user_login, $user_pass)) {
1096 return $this->error;
1097 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1098
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1099 $user = set_current_user(0, $user_login);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1100
9af6317 WP XML-RPC API
ryan authored
1101 // The post_type defaults to post, but could also be page.
1102 $post_type = "post";
1103 if(
1104 !empty($content_struct["post_type"])
1105 && ($content_struct["post_type"] == "page")
1106 ) {
1107 $post_type = "page";
1108 }
1109
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1110 // Edit page caps are checked in editPage. Just check post here.
1111 if ( ( 'post' == $post_type ) && !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1112 return new IXR_Error(401, __('Sorry, you can not edit this post.'));
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1113
1114 $postdata = wp_get_single_post($post_ID, ARRAY_A);
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return emp…
ryan authored
1115
1116 // If there is no post data for the give post id, stop
1117 // now and return an error. Other wise a new post will be
1118 // created (which was the old behavior).
1119 if(empty($postdata["ID"])) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1120 return(new IXR_Error(404, __("Invalid post id.")));
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return emp…
ryan authored
1121 }
1122
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1123 extract($postdata);
1124 $this->escape($postdata);
1125
9af6317 WP XML-RPC API
ryan authored
1126 // Let WordPress manage slug if none was provided.
1127 $post_name = "";
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1128 if(isset($content_struct["wp_slug"])) {
9af6317 WP XML-RPC API
ryan authored
1129 $post_name = $content_struct["wp_slug"];
1130 }
1131
1132 // Only use a password if one was given.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1133 if(isset($content_struct["wp_password"])) {
9af6317 WP XML-RPC API
ryan authored
1134 $post_password = $content_struct["wp_password"];
1135 }
1136
1137 // Only set a post parent if one was given.
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
1138 if(isset($content_struct["wp_page_parent_id"])) {
9af6317 WP XML-RPC API
ryan authored
1139 $post_parent = $content_struct["wp_page_parent_id"];
1140 }
1141
9bc0cc2 More XML-RPC API enhancements from Joseph Scott.
ryan authored
1142 // Only set the menu_order if it was given.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1143 if(isset($content_struct["wp_page_order"])) {
9af6317 WP XML-RPC API
ryan authored
1144 $menu_order = $content_struct["wp_page_order"];
1145 }
1146
9a75737 Prevent current author from claiming authorship of posts from other a…
markjaquith authored
1147 $post_author = $postdata["post_author"];
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1148
9bc0cc2 More XML-RPC API enhancements from Joseph Scott.
ryan authored
1149 // Only set the post_author if one is set.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1150 if(
1151 isset($content_struct["wp_author_id"])
1152 && ($user->ID != $content_struct["wp_author_id"])
1153 ) {
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
1154 switch($post_type) {
1155 case "post":
1156 if(!current_user_can("edit_others_posts")) {
8a3ed38 More xmlrpc.php i18n fixes from nbachiyski. fixes #3997
rob1n authored
1157 return(new IXR_Error(401, __("You are not allowed to change the post author as this user.")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
1158 }
1159 break;
1160 case "page":
1161 if(!current_user_can("edit_others_pages")) {
8a3ed38 More xmlrpc.php i18n fixes from nbachiyski. fixes #3997
rob1n authored
1162 return(new IXR_Error(401, __("You are not allowed to change the page author as this user.")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
1163 }
1164 break;
1165 default:
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1166 return(new IXR_Error(401, __("Invalid post type.")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
1167 break;
1168 }
e71e25d XMLRPC API updates.
ryan authored
1169 $post_author = $content_struct["wp_author_id"];
1170 }
1171
1172 // Only set ping_status if it was provided.
1173 if(isset($content_struct["mt_allow_pings"])) {
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1174 switch((int) $content_struct["mt_allow_pings"]) {
1175 case 0:
e71e25d XMLRPC API updates.
ryan authored
1176 $ping_status = "closed";
1177 break;
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1178 case 1:
e71e25d XMLRPC API updates.
ryan authored
1179 $ping_status = "open";
1180 break;
1181 }
9bc0cc2 More XML-RPC API enhancements from Joseph Scott.
ryan authored
1182 }
1183
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1184 $post_title = $content_struct['title'];
99df7e3 Cleaning up filters and format-to-post
saxmatt authored
1185 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1186 $catnames = $content_struct['categories'];
bdfab81 Default category and pingback check fixes.
ryan authored
1187
1188 $post_category = array();
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
1189
6ff9558 Make sure category list is actually a list. http://mosquito.wordpres…
ryan authored
1190 if (is_array($catnames)) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1191 foreach ($catnames as $cat) {
1192 $post_category[] = get_cat_ID($cat);
1193 }
54766ea XMLRPC category fixes
ryan authored
1194 }
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1195
1196 $post_excerpt = $content_struct['mt_excerpt'];
1197 $post_more = $content_struct['mt_text_more'];
1198 $post_status = $publish ? 'publish' : 'draft';
1199
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1200 if ( ('publish' == $post_status) ) {
1201 if ( ( 'page' == $post_type ) && !current_user_can('publish_pages') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1202 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
1203 else if ( !current_user_can('publish_posts') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1204 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
1205 }
1206
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1207 if ($post_more) {
1208 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
1209 }
1210
97bcc74 Handle array of mt_tb_ping_urls. Props bafonso. fixes #3721
ryan authored
1211 $to_ping = $content_struct['mt_tb_ping_urls'];
1212 if ( is_array($to_ping) )
1213 $to_ping = implode(' ', $to_ping);
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1214
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
1215 if(isset($content_struct["mt_allow_comments"])) {
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1216 $comment_status = (int) $content_struct["mt_allow_comments"];
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
1217 }
1218
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1219 // Do some timestamp voodoo
9367489 dateCreated typos
michelvaldrighi authored
1220