Skip to content
Newer
Older
100644 2033 lines (1584 sloc) 56.4 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
321c310 Remove trailing whitespace
ryan authored
8 // A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default,
f432ed6 Fix for PHP version 5.2.2 where $HTTP_RAW_POST_DATA isn't set. fixes …
rob1n authored
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. Pr…
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
321c310 Remove trailing whitespace
ryan authored
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>
adda69e We prefer our own API. (Which MT/Typepad have cloned already.)
matt authored
31 <api name="WordPress" blogID="1" preferred="true" apiLink="<?php bloginfo_rss('wpurl') ?>/xmlrpc.php" />
32 <api name="Movable Type" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('wpurl') ?>/xmlrpc.php" />
fe5e71c RSD link fixes from Joseph Scott. fixes #4329 for 2.3
ryan authored
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. fixe…
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. fixe…
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. fixe…
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.
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
211 $page_date = mysql2date("Ymd\TH:i:s", $page->post_date);
212 $page_date_gmt = mysql2date("Ymd\TH:i:s", $page->post_date_gmt);
9af6317 WP XML-RPC API
ryan authored
213
214 // Pull the categories info together.
215 $categories = array();
216 foreach(wp_get_post_categories($page->ID) as $cat_id) {
217 $categories[] = get_cat_name($cat_id);
218 }
219
d162935 WP XML-RPC API enhancements.
ryan authored
220 // Get the author info.
221 $author = get_userdata($page->post_author);
9af6317 WP XML-RPC API
ryan authored
222
223 $page_struct = array(
d162935 WP XML-RPC API enhancements.
ryan authored
224 "dateCreated" => new IXR_Date($page_date),
225 "userid" => $page->post_author,
226 "page_id" => $page->ID,
227 "page_status" => $page->post_status,
228 "description" => $full_page["main"],
229 "title" => $page->post_title,
230 "link" => $link,
231 "permaLink" => $link,
232 "categories" => $categories,
233 "excerpt" => $page->post_excerpt,
234 "text_more" => $full_page["extended"],
235 "mt_allow_comments" => $allow_comments,
236 "mt_allow_pings" => $allow_pings,
237 "wp_slug" => $page->post_name,
238 "wp_password" => $page->post_password,
e71e25d XMLRPC API updates.
ryan authored
239 "wp_author" => $author->display_name,
d162935 WP XML-RPC API enhancements.
ryan authored
240 "wp_page_parent_id" => $page->post_parent,
241 "wp_page_parent_title" => $parent_title,
242 "wp_page_order" => $page->menu_order,
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
243 "wp_author_id" => $author->ID,
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
244 "wp_author_display_name" => $author->display_name,
245 "date_created_gmt" => new IXR_Date($page_date_gmt)
9af6317 WP XML-RPC API
ryan authored
246 );
247
248 return($page_struct);
249 }
250 // If the page doesn't exist indicate that.
251 else {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
252 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
253 }
254 }
255
256 /**
257 * WordPress XML-RPC API
258 * wp_getPages
259 */
260 function wp_getPages($args) {
261 $this->escape($args);
262
7602d17 (int)er the dragon.
matt authored
263 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
264 $username = $args[1];
265 $password = $args[2];
266
267 if(!$this->login_pass_ok($username, $password)) {
268 return($this->error);
269 }
270
271 // Lookup info on pages.
272 $pages = get_pages();
273 $num_pages = count($pages);
274
275 // If we have pages, put together their info.
276 if($num_pages >= 1) {
277 $pages_struct = array();
278
279 for($i = 0; $i < $num_pages; $i++) {
280 $page = wp_xmlrpc_server::wp_getPage(array(
281 $blog_id, $pages[$i]->ID, $username, $password
282 ));
283 $pages_struct[] = $page;
284 }
285
286 return($pages_struct);
287 }
288 // If no pages were found return an error.
289 else {
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return empt…
ryan authored
290 return(array());
9af6317 WP XML-RPC API
ryan authored
291 }
292 }
293
294 /**
295 * WordPress XML-RPC API
296 * wp_newPage
297 */
298 function wp_newPage($args) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
299 // Items not escaped here will be escaped in newPost.
300 $username = $this->escape($args[1]);
301 $password = $this->escape($args[2]);
9af6317 WP XML-RPC API
ryan authored
302 $page = $args[3];
303 $publish = $args[4];
304
305 if(!$this->login_pass_ok($username, $password)) {
306 return($this->error);
307 }
308
309 // Set the user context and check if they are allowed
310 // to add new pages.
311 $user = set_current_user(0, $username);
312 if(!current_user_can("publish_pages")) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
313 return(new IXR_Error(401, __("Sorry, you can not add new pages.")));
9af6317 WP XML-RPC API
ryan authored
314 }
315
316 // Mark this as content for a page.
317 $args[3]["post_type"] = "page";
318
319 // Let mw_newPost do all of the heavy lifting.
320 return($this->mw_newPost($args));
321 }
322
323 /**
324 * WordPress XML-RPC API
325 * wp_deletePage
326 */
327 function wp_deletePage($args) {
328 $this->escape($args);
329
7602d17 (int)er the dragon.
matt authored
330 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
331 $username = $args[1];
332 $password = $args[2];
7602d17 (int)er the dragon.
matt authored
333 $page_id = (int) $args[3];
9af6317 WP XML-RPC API
ryan authored
334
335 if(!$this->login_pass_ok($username, $password)) {
336 return($this->error);
337 }
338
339 // Get the current page based on the page_id and
340 // make sure it is a page and not a post.
341 $actual_page = wp_get_single_post($page_id, ARRAY_A);
342 if(
343 !$actual_page
344 || ($actual_page["post_type"] != "page")
345 ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
346 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
347 }
348
349 // Set the user context and make sure they can delete pages.
350 set_current_user(0, $username);
351 if(!current_user_can("delete_page", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
352 return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page.")));
9af6317 WP XML-RPC API
ryan authored
353 }
354
355 // Attempt to delete the page.
356 $result = wp_delete_post($page_id);
357 if(!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
358 return(new IXR_Error(500, __("Failed to delete the page.")));
9af6317 WP XML-RPC API
ryan authored
359 }
360
361 return(true);
362 }
363
364 /**
365 * WordPress XML-RPC API
366 * wp_editPage
367 */
368 function wp_editPage($args) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
369 // Items not escaped here will be escaped in editPost.
7602d17 (int)er the dragon.
matt authored
370 $blog_id = (int) $args[0];
ae7fa6c Cast to int after escaping. Props Joseph Scott.
ryan authored
371 $page_id = (int) $this->escape($args[1]);
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
372 $username = $this->escape($args[2]);
373 $password = $this->escape($args[3]);
9af6317 WP XML-RPC API
ryan authored
374 $content = $args[4];
375 $publish = $args[5];
376
377 if(!$this->login_pass_ok($username, $password)) {
378 return($this->error);
379 }
380
381 // Get the page data and make sure it is a page.
382 $actual_page = wp_get_single_post($page_id, ARRAY_A);
383 if(
384 !$actual_page
385 || ($actual_page["post_type"] != "page")
386 ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
387 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
388 }
389
390 // Set the user context and make sure they are allowed to edit pages.
391 set_current_user(0, $username);
392 if(!current_user_can("edit_page", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
393 return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page.")));
9af6317 WP XML-RPC API
ryan authored
394 }
395
396 // Mark this as content for a page.
397 $content["post_type"] = "page";
398
399 // Arrange args in the way mw_editPost understands.
400 $args = array(
401 $page_id,
402 $username,
403 $password,
404 $content,
405 $publish
406 );
407
408 // Let mw_editPost do all of the heavy lifting.
409 return($this->mw_editPost($args));
410 }
411
412 /**
413 * WordPress XML-RPC API
414 * wp_getPageList
415 */
416 function wp_getPageList($args) {
417 global $wpdb;
418
419 $this->escape($args);
420
7602d17 (int)er the dragon.
matt authored
421 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
422 $username = $args[1];
423 $password = $args[2];
424
425 if(!$this->login_pass_ok($username, $password)) {
426 return($this->error);
427 }
428
429 // Get list of pages ids and titles
430 $page_list = $wpdb->get_results("
431 SELECT ID page_id,
d162935 WP XML-RPC API enhancements.
ryan authored
432 post_title page_title,
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
433 post_parent page_parent_id,
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
434 post_date_gmt,
435 post_date
9af6317 WP XML-RPC API
ryan authored
436 FROM {$wpdb->posts}
437 WHERE post_type = 'page'
438 ORDER BY ID
439 ");
440
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
441 // The date needs to be formated properly.
442 $num_pages = count($page_list);
443 for($i = 0; $i < $num_pages; $i++) {
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
444 $post_date = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date);
445 $post_date_gmt = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date_gmt);
446
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
447 $page_list[$i]->dateCreated = new IXR_Date($post_date);
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
448 $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
449
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #415…
ryan authored
450 unset($page_list[$i]->post_date_gmt);
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
451 unset($page_list[$i]->post_date);
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
452 }
453
9af6317 WP XML-RPC API
ryan authored
454 return($page_list);
455 }
456
457 /**
458 * WordPress XML-RPC API
459 * wp_getAuthors
460 */
461 function wp_getAuthors($args) {
462 global $wpdb;
463
464 $this->escape($args);
465
7602d17 (int)er the dragon.
matt authored
466 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
467 $username = $args[1];
468 $password = $args[2];
469
470 if(!$this->login_pass_ok($username, $password)) {
471 return($this->error);
472 }
473
bf37dbf Use get_users_of_blog() for wp_getAuthors
ryan authored
474 return(get_users_of_blog());
9af6317 WP XML-RPC API
ryan authored
475 }
476
477 /**
478 * WordPress XML-RPC API
479 * wp_newCategory
480 */
481 function wp_newCategory($args) {
482 $this->escape($args);
483
7602d17 (int)er the dragon.
matt authored
484 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
485 $username = $args[1];
486 $password = $args[2];
487 $category = $args[3];
488
489 if(!$this->login_pass_ok($username, $password)) {
490 return($this->error);
491 }
492
493 // Set the user context and make sure they are
494 // allowed to add a category.
495 set_current_user(0, $username);
496 if(!current_user_can("manage_categories", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
497 return(new IXR_Error(401, __("Sorry, you do not have the right to add a category.")));
9af6317 WP XML-RPC API
ryan authored
498 }
499
500 // If no slug was provided make it empty so that
501 // WordPress will generate one.
502 if(empty($category["slug"])) {
503 $category["slug"] = "";
504 }
505
506 // If no parent_id was provided make it empty
507 // so that it will be a top level page (no parent).
c8997ff Reverse logic.
ryan authored
508 if ( !isset($category["parent_id"]) )
9af6317 WP XML-RPC API
ryan authored
509 $category["parent_id"] = "";
510
511 // If no description was provided make it empty.
512 if(empty($category["description"])) {
513 $category["description"] = "";
514 }
2f09416 Trim empty lines. Nothing but newline.
ryan authored
515
9af6317 WP XML-RPC API
ryan authored
516 $new_category = array(
517 "cat_name" => $category["name"],
518 "category_nicename" => $category["slug"],
519 "category_parent" => $category["parent_id"],
520 "category_description" => $category["description"]
521 );
522
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
523 $cat_id = wp_insert_category($new_category);
9af6317 WP XML-RPC API
ryan authored
524 if(!$cat_id) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
525 return(new IXR_Error(500, __("Sorry, the new category failed.")));
9af6317 WP XML-RPC API
ryan authored
526 }
527
528 return($cat_id);
529 }
530
531 /**
532 * WordPress XML-RPC API
533 * wp_suggestCategories
534 */
535 function wp_suggestCategories($args) {
536 global $wpdb;
537
538 $this->escape($args);
539
7602d17 (int)er the dragon.
matt authored
540 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
541 $username = $args[1];
542 $password = $args[2];
543 $category = $args[3];
070d2fd Int cast. Props to Alexander Concha for the find, Joseph Scott for th…
markjaquith authored
544 $max_results = (int) $args[4];
9af6317 WP XML-RPC API
ryan authored
545
546 if(!$this->login_pass_ok($username, $password)) {
547 return($this->error);
548 }
549
7217266 AND get_terms() field queries
ryan authored
550 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category);
821cf4b suggestCategories cleanup
ryan authored
551 $category_suggestions = get_categories($args);
9af6317 WP XML-RPC API
ryan authored
552
553 return($category_suggestions);
554 }
555
556
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
557 /* Blogger API functions
558 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
559 */
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
560
561
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
562 /* blogger.getUsersBlogs will make more sense once we support multiple blogs */
563 function blogger_getUsersBlogs($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
564
9c9ba0a Escape XMLRPC args.
ryan authored
565 $this->escape($args);
566
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
567 $user_login = $args[1];
568 $user_pass = $args[2];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
569
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
570 if (!$this->login_pass_ok($user_login, $user_pass)) {
571 return $this->error;
572 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
573
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
574 set_current_user(0, $user_login);
575 $is_admin = current_user_can('level_8');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
576
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
577 $struct = array(
578 'isAdmin' => $is_admin,
579 'url' => get_option('home') . '/',
580 'blogid' => '1',
581 'blogName' => get_option('blogname')
582 );
e762c60 Remove debug cruft. fixes #2273
ryan authored
583
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
584 return array($struct);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
585 }
586
587
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
588 /* blogger.getUsersInfo gives your client some info about you, so you don't have to */
589 function blogger_getUserInfo($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
590
9c9ba0a Escape XMLRPC args.
ryan authored
591 $this->escape($args);
592
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
593 $user_login = $args[1];
594 $user_pass = $args[2];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
595
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
596 if (!$this->login_pass_ok($user_login, $user_pass)) {
597 return $this->error;
598 }
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. fixe…
ryan authored
600 $user_data = get_userdatabylogin($user_login);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
601
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
602 $struct = array(
603 'nickname' => $user_data->nickname,
604 'userid' => $user_data->ID,
605 'url' => $user_data->user_url,
606 'email' => $user_data->user_email,
607 'lastname' => $user_data->last_name,
608 'firstname' => $user_data->first_name
609 );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
610
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
611 return $struct;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
612 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
613
614
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
615 /* blogger.getPost ...gets a post */
616 function blogger_getPost($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
617
9c9ba0a Escape XMLRPC args.
ryan authored
618 $this->escape($args);
619
7602d17 (int)er the dragon.
matt authored
620 $post_ID = (int) $args[1];
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
621 $user_login = $args[2];
622 $user_pass = $args[3];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
623
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
624 if (!$this->login_pass_ok($user_login, $user_pass)) {
625 return $this->error;
626 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
627
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
628 $user_data = get_userdatabylogin($user_login);
629 $post_data = wp_get_single_post($post_ID, ARRAY_A);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
630
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
631 $categories = implode(',', wp_get_post_categories($post_ID));
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
632
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
633 $content = '<title>'.stripslashes($post_data['post_title']).'</title>';
634 $content .= '<category>'.$categories.'</category>';
635 $content .= stripslashes($post_data['post_content']);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
636
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
637 $struct = array(
638 'userid' => $post_data['post_author'],
639 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
640 'content' => $content,
641 'postid' => $post_data['ID']
642 );
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
643
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
644 return $struct;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
645 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
646
647
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
648 /* blogger.getRecentPosts ...gets recent posts */
649 function blogger_getRecentPosts($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
650
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
651 global $wpdb;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
652
9c9ba0a Escape XMLRPC args.
ryan authored
653 $this->escape($args);
654
7602d17 (int)er the dragon.
matt authored
655 $blog_ID = (int) $args[1]; /* though we don't use it yet */
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
656 $user_login = $args[2];
657 $user_pass = $args[3];
658 $num_posts = $args[4];
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
659
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
660 if (!$this->login_pass_ok($user_login, $user_pass)) {
661 return $this->error;
662 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
663
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
664 $posts_list = wp_get_recent_posts($num_posts);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
665
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
666 if (!$posts_list) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
667 $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. fixe…
ryan authored
668 return $this->error;
669 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
670
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
671 foreach ($posts_list as $entry) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
672
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
673 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
674 $categories = implode(',', wp_get_post_categories($entry['ID']));
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
675
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
676 $content = '<title>'.stripslashes($entry['post_title']).'</title>';
677 $content .= '<category>'.$categories.'</category>';
678 $content .= stripslashes($entry['post_content']);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
679
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
680 $struct[] = array(
681 'userid' => $entry['post_author'],
682 'dateCreated' => new IXR_Date($post_date),
683 'content' => $content,
684 'postid' => $entry['ID'],
685 );
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
686
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
687 }
688
689 $recent_posts = array();
690 for ($j=0; $j<count($struct); $j++) {
691 array_push($recent_posts, $struct[$j]);
692 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
693
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixe…
ryan authored
694 return $recent_posts;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
695 }
696
697
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
698 /* blogger.getTemplate returns your blog_filename */
699 function blogger_getTemplate($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
700
9c9ba0a Escape XMLRPC args.
ryan authored
701 $this->escape($args);
702
7602d17 (int)er the dragon.
matt authored
703 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
704 $user_login = $args[2];
705 $user_pass = $args[3];
706 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
707
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
708 if (!$this->login_pass_ok($user_login, $user_pass)) {
709 return $this->error;
710 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
711
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
712 set_current_user(0, $user_login);
713 if ( !current_user_can('edit_themes') ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
714 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
715 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
716
8c454d7 Favor the term "blog" instead of "weblog." Props foolswisdom and Nazg…
markjaquith authored
717 /* warning: here we make the assumption that the blog's URL is on the same server */
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
718 $filename = get_option('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
719 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
720
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
721 $f = fopen($filename, 'r');
722 $content = fread($f, filesize($filename));
723 fclose($f);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
724
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
725 /* so it is actually editable with a windows/mac client */
321c310 Remove trailing whitespace
ryan authored
726 // 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
727
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
728 return $content;
729 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
730
731
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
732 /* blogger.setTemplate updates the content of blog_filename */
733 function blogger_setTemplate($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
734
9c9ba0a Escape XMLRPC args.
ryan authored
735 $this->escape($args);
736
7602d17 (int)er the dragon.
matt authored
737 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
738 $user_login = $args[2];
739 $user_pass = $args[3];
740 $content = $args[4];
741 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
742
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
743 if (!$this->login_pass_ok($user_login, $user_pass)) {
744 return $this->error;
745 }
1387744 added blogger.newPost
michelvaldrighi authored
746
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
747 set_current_user(0, $user_login);
748 if ( !current_user_can('edit_themes') ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
749 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
750 }
1387744 added blogger.newPost
michelvaldrighi authored
751
8c454d7 Favor the term "blog" instead of "weblog." Props foolswisdom and Nazg…
markjaquith authored
752 /* warning: here we make the assumption that the blog's URL is on the same server */
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
753 $filename = get_option('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
754 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
1387744 added blogger.newPost
michelvaldrighi authored
755
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
756 if ($f = fopen($filename, 'w+')) {
757 fwrite($f, $content);
758 fclose($f);
759 } else {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
760 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
761 }
1387744 added blogger.newPost
michelvaldrighi authored
762
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
763 return true;
764 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
765
766
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
767 /* blogger.newPost ...creates a new post */
768 function blogger_newPost($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
769
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
770 global $wpdb;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
771
9c9ba0a Escape XMLRPC args.
ryan authored
772 $this->escape($args);
773
7602d17 (int)er the dragon.
matt authored
774 $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
775 $user_login = $args[2];
776 $user_pass = $args[3];
777 $content = $args[4];
778 $publish = $args[5];
1387744 added blogger.newPost
michelvaldrighi authored
779
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
780 if (!$this->login_pass_ok($user_login, $user_pass)) {
781 return $this->error;
782 }
2f09416 Trim empty lines. Nothing but newline.
ryan authored
783
c2fd7b8 Capability updates for xmlrpc.
ryan authored
784 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
785 $user = set_current_user(0, $user_login);
786 if ( !current_user_can($cap) )
8c454d7 Favor the term "blog" instead of "weblog." Props foolswisdom and Nazg…
markjaquith authored
787 return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.'));
1387744 added blogger.newPost
michelvaldrighi authored
788
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
789 $post_status = ($publish) ? 'publish' : 'draft';
1387744 added blogger.newPost
michelvaldrighi authored
790
c2fd7b8 Capability updates for xmlrpc.
ryan authored
791 $post_author = $user->ID;
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_title = xmlrpc_getposttitle($content);
794 $post_category = xmlrpc_getpostcategory($content);
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since t…
ryan authored
795 $post_content = xmlrpc_removepostdata($content);
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_date = current_time('mysql');
798 $post_date_gmt = current_time('mysql', 1);
1387744 added blogger.newPost
michelvaldrighi authored
799
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
800 $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
801
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
802 $post_ID = wp_insert_post($post_data);
1387744 added blogger.newPost
michelvaldrighi authored
803
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
804 if (!$post_ID) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
805 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
806 }
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
807 $this->attach_uploads( $post_ID, $post_content );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
808
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
809 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
810
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
811 return $post_ID;
1387744 added blogger.newPost
michelvaldrighi authored
812 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
813
814
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
815 /* blogger.editPost ...edits a post */
816 function blogger_editPost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
817
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
818 global $wpdb;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
819
9c9ba0a Escape XMLRPC args.
ryan authored
820 $this->escape($args);
821
5b22739 More int casts
ryan authored
822 $post_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
823 $user_login = $args[2];
824 $user_pass = $args[3];
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since t…
ryan authored
825 $content = $args[4];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
826 $publish = $args[5];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
827
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
828 if (!$this->login_pass_ok($user_login, $user_pass)) {
829 return $this->error;
830 }
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 $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
833
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
834 if (!$actual_post) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
835 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
836 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
837
9c9ba0a Escape XMLRPC args.
ryan authored
838 $this->escape($actual_post);
839
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
840 set_current_user(0, $user_login);
841 if ( !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
842 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
843
c09f6ff escape before extracting. Props Alexander Concha.
ryan authored
844 extract($actual_post, EXTR_SKIP);
9c9ba0a Escape XMLRPC args.
ryan authored
845
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
846 if ( ('publish' == $post_status) && !current_user_can('publish_posts') )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
847 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
848
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
849 $post_title = xmlrpc_getposttitle($content);
850 $post_category = xmlrpc_getpostcategory($content);
183593f Fix typo in blogger_editPost(). Don't invoke content_save_pre since t…
ryan authored
851 $post_content = xmlrpc_removepostdata($content);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
852
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
853 $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
854
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
855 $result = wp_update_post($postdata);
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 if (!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
858 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
859 }
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
860 $this->attach_uploads( $ID, $post_content );
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
861
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
862 return true;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
863 }
864
865
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
866 /* blogger.deletePost ...deletes a post */
867 function blogger_deletePost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
868
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
869 global $wpdb;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
870
9c9ba0a Escape XMLRPC args.
ryan authored
871 $this->escape($args);
872
7602d17 (int)er the dragon.
matt authored
873 $post_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
874 $user_login = $args[2];
875 $user_pass = $args[3];
876 $publish = $args[4];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
877
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
878 if (!$this->login_pass_ok($user_login, $user_pass)) {
879 return $this->error;
880 }
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 $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
883
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
884 if (!$actual_post) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
885 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
886 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
887
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
888 set_current_user(0, $user_login);
889 if ( !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
890 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
891
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
892 $result = wp_delete_post($post_ID);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
893
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
894 if (!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
895 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
896 }
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 return true;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
899 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
900
901
902
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
903 /* MetaWeblog API functions
904 * specs on wherever Dave Winer wants them to be
905 */
80b3445 fixed comment_status screwup, removed debug stuff, screwed up big tim…
michelvaldrighi authored
906
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
907 /* metaweblog.newPost creates a post */
908 function mw_newPost($args) {
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
909
d1ea1c9 Use instead of hardcoding 1. Do we really need a separate default cat…
ryan authored
910 global $wpdb, $post_default_category;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
911
9c9ba0a Escape XMLRPC args.
ryan authored
912 $this->escape($args);
913
7602d17 (int)er the dragon.
matt authored
914 $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
915 $user_login = $args[1];
916 $user_pass = $args[2];
917 $content_struct = $args[3];
918 $publish = $args[4];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
919
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
920 if (!$this->login_pass_ok($user_login, $user_pass)) {
921 return $this->error;
922 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
923
f904142 Add 'edit_posts' capability check to metaWeblog.newPost. Props Joseph…
ryan authored
924 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
925 $user = set_current_user(0, $user_login);
f904142 Add 'edit_posts' capability check to metaWeblog.newPost. Props Joseph…
ryan authored
926 if ( !current_user_can($cap) )
8c454d7 Favor the term "blog" instead of "weblog." Props foolswisdom and Nazg…
markjaquith authored
927 return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.'));
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
928
9af6317 WP XML-RPC API
ryan authored
929 // The post_type defaults to post, but could also be page.
930 $post_type = "post";
931 if(
932 !empty($content_struct["post_type"])
933 && ($content_struct["post_type"] == "page")
934 ) {
935 $post_type = "page";
936 }
937
938 // Let WordPress generate the post_name (slug) unless
939 // one has been provided.
940 $post_name = "";
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
941 if(isset($content_struct["wp_slug"])) {
9af6317 WP XML-RPC API
ryan authored
942 $post_name = $content_struct["wp_slug"];
943 }
944
945 // Only use a password if one was given.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
946 if(isset($content_struct["wp_password"])) {
9af6317 WP XML-RPC API
ryan authored
947 $post_password = $content_struct["wp_password"];
948 }
949
950 // Only set a post parent if one was provided.
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
951 if(isset($content_struct["wp_page_parent_id"])) {
9af6317 WP XML-RPC API
ryan authored
952 $post_parent = $content_struct["wp_page_parent_id"];
953 }
954
955 // 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
956 if(isset($content_struct["wp_page_order"])) {
9af6317 WP XML-RPC API
ryan authored
957 $menu_order = $content_struct["wp_page_order"];
958 }
959
c2fd7b8 Capability updates for xmlrpc.
ryan authored
960 $post_author = $user->ID;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
961
e71e25d XMLRPC API updates.
ryan authored
962 // 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
963 if(
964 isset($content_struct["wp_author_id"])
965 && ($user->ID != $content_struct["wp_author_id"])
966 ) {
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
967 switch($post_type) {
968 case "post":
969 if(!current_user_can("edit_others_posts")) {
8a3ed38 More xmlrpc.php i18n fixes from nbachiyski. fixes #3997
rob1n authored
970 return(new IXR_Error(401, __("You are not allowed to post as this user")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
971 }
972 break;
973 case "page":
974 if(!current_user_can("edit_others_pages")) {
8a3ed38 More xmlrpc.php i18n fixes from nbachiyski. fixes #3997
rob1n authored
975 return(new IXR_Error(401, __("You are not allowed to create pages as this user")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
976 }
977 break;
978 default:
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
979 return(new IXR_Error(401, __("Invalid post type.")));
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
980 break;
981 }
e71e25d XMLRPC API updates.
ryan authored
982 $post_author = $content_struct["wp_author_id"];
983 }
984
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
985 $post_title = $content_struct['title'];
99df7e3 Cleaning up filters and format-to-post
saxmatt authored
986 $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
987 $post_status = $publish ? 'publish' : 'draft';
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
988
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
989 $post_excerpt = $content_struct['mt_excerpt'];
990 $post_more = $content_struct['mt_text_more'];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
991
560b73b mt_keywords support. Props westi and josephscott. fixes #900
ryan authored
992 $tags_input = $content_struct['mt_keywords'];
993
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
994 if(isset($content_struct["mt_allow_comments"])) {
7ffc5ee Accept 'open' and 'closed' as valid values for mt_allow_comments and …
ryan authored
995 if(!is_numeric($content_struct["mt_allow_comments"])) {
996 switch($content_struct["mt_allow_comments"]) {
997 case "closed":
998 $comment_status = "closed";
999 break;
1000 case "open":
1001 $comment_status = "open";
1002 break;
1003 default:
1004 $comment_status = get_option("default_comment_status");
1005 break;
1006 }
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1007 }
7ffc5ee Accept 'open' and 'closed' as valid values for mt_allow_comments and …
ryan authored
1008 else {
1009 switch((int) $content_struct["mt_allow_comments"]) {
1010 case 0:
1011 $comment_status = "closed";
1012 break;
1013 case 1:
1014 $comment_status = "open";
1015 break;
1016 default:
1017 $comment_status = get_option("default_comment_status");
1018 break;
1019 }
1020 }
1021 }
1022 else {
1023 $comment_status = get_option("default_comment_status");
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1024 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1025
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1026 if(isset($content_struct["mt_allow_pings"])) {
7ffc5ee Accept 'open' and 'closed' as valid values for mt_allow_comments and …
ryan authored
1027 if(!is_numeric($content_struct["mt_allow_pings"])) {
4f183b4 mt_allow_pings fix. Props Joseph Scott and Allan Odgaard. fixes #4770…
ryan authored
1028 switch($content_struct['mt_allow_pings']) {
7ffc5ee Accept 'open' and 'closed' as valid values for mt_allow_comments and …
ryan authored
1029 case "closed":
1030 $ping_status = "closed";
321c310 Remove trailing whitespace
ryan authored
1031 break;
7ffc5ee Accept 'open' and 'closed' as valid values for mt_allow_comments and …
ryan authored
1032 case "open":
1033 $ping_status = "open";
1034 break;
1035 default:
1036 $ping_status = get_option("default_ping_status");
1037 break;
1038 }
1039 }
1040 else {
1041 switch((int) $content_struct["mt_allow_pings"]) {
1042 case 0:
1043 $ping_status = "closed";
1044 break;
1045 case 1:
1046 $ping_status = "open";
1047 break;
1048 default:
1049 $ping_status = get_option("default_ping_status");
1050 break;
1051 }
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1052 }
1053 }
7ffc5ee Accept 'open' and 'closed' as valid values for mt_allow_comments and …
ryan authored
1054 else {
1055 $ping_status = get_option("default_ping_status");
1056 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1057
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1058 if ($post_more) {
1059 $post_content = $post_content . "\n<!--more-->\n" . $post_more;
1060 }
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post(…
ryan authored
1061
97bcc74 Handle array of mt_tb_ping_urls. Props bafonso. fixes #3721
ryan authored
1062 $to_ping = $content_struct['mt_tb_ping_urls'];
1063 if ( is_array($to_ping) )
1064 $to_ping = implode(' ', $to_ping);
de05283 Don't stomp post_ID in mw_editPost(). Pass TB URIs to wp_update_post(…
ryan authored
1065
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
1066 // Do some timestamp voodoo
1067 $dateCreatedd = $content_struct['dateCreated'];
1068 if (!empty($dateCreatedd)) {
1069 $dateCreated = $dateCreatedd->getIso();
1070 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
1071 $post_date_gmt = iso8601_to_datetime($dateCreated, GMT);
1072 } else {
1073 $post_date = current_time('mysql');
1074 $post_date_gmt = current_time('mysql', 1);
1075 }
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1076
1077 $catnames = $content_struct['categories'];
83e6c81 s/logio/logIO/. Remove logio calls from the one function in functions…
rboren authored
1078 logIO('O', 'Post cats: ' . printr($catnames,true));
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1079 $post_category = array();
1080
6ff9558 Make sure category list is actually a list. http://mosquito.wordpress…
ryan authored
1081 if (is_array($catnames)) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1082 foreach ($catnames as $cat) {
1083 $post_category[] = get_cat_ID($cat);
1084 }
54766ea XMLRPC category fixes
ryan authored
1085 }
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
1086
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1087 // We've got all the data -- post it:
560b73b mt_keywords support. Props westi and josephscott. fixes #900
ryan authored
1088 $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', 'tags_input');
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1089
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
1090 $post_ID = wp_insert_post($postdata);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1091
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1092 if (!$post_ID) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1093 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
1094 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1095
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
1096 $this->attach_uploads( $post_ID, $post_content );
1097
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1098 logIO('O', "Posted ! ID: $post_ID");
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1099
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1100 return strval($post_ID);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1101 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1102
d0e1e74 Create attachments for xmlrpc uploads. Props donncha. fixes #3400
ryan authored
1103 function attach_uploads( $post_ID, $post_content ) {
1104 global $wpdb;
1105
1106 // find any unattached files
1107 $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '-1' AND post_type = 'attachment'" );
1108 if( is_array( $attachments ) ) {
1109 foreach( $attachments as $file ) {
1110 if( strpos( $post_content, $file->guid ) !== false ) {
1111 $wpdb->query( "UPDATE {$wpdb->posts} SET post_parent = '$post_ID' WHERE ID = '{$file->ID}'" );
1112 }
1113 }
1114 }
1115 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1116
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1117 /* metaweblog.editPost ...edits a post */
1118 function mw_editPost($args) {
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1119
d1ea1c9 Use instead of hardcoding 1. Do we really need a separate default cat…
ryan authored
1120 global $wpdb, $post_default_category;
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1121
9c9ba0a Escape XMLRPC args.
ryan authored
1122 $this->escape($args);
1123
5b22739 More int casts
ryan authored
1124 $post_ID = (int) $args[0];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1125 $user_login = $args[1];
1126 $user_pass = $args[2];
1127 $content_struct = $args[3];
1128 $publish = $args[4];
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1129
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1130 if (!$this->login_pass_ok($user_login, $user_pass)) {
1131 return $this->error;
1132 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1133
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1134 $user = set_current_user(0, $user_login);
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1135
9af6317 WP XML-RPC API
ryan authored
1136 // The post_type defaults to post, but could also be page.
1137 $post_type = "post";
1138 if(
1139 !empty($content_struct["post_type"])
1140 && ($content_struct["post_type"] == "page")
1141 ) {
1142 $post_type = "page";
1143 }
1144
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1145 // Edit page caps are checked in editPage. Just check post here.
1146 if ( ( 'post' == $post_type ) && !current_user_can('edit_post', $post_ID) )
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1147 return new IXR_Error(401, __('Sorry, you can not edit this post.'));
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1148
1149 $postdata = wp_get_single_post($post_ID, ARRAY_A);
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return empt…
ryan authored
1150
1151 // If there is no post data for the give post id, stop
1152 // now and return an error. Other wise a new post will be
1153 // created (which was the old behavior).
1154 if(empty($postdata["ID"])) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1155 return(new IXR_Error(404, __("Invalid post id.")));
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return empt…
ryan authored
1156 }
1157
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1158 $this->escape($postdata);
c09f6ff escape before extracting. Props Alexander Concha.
ryan authored
1159 extract($postdata, EXTR_SKIP);
b5a1246 Check for publish caps when editing via xmlrpc.
ryan authored
1160
9af6317 WP XML-RPC API
ryan authored
1161 // Let WordPress manage slug if none was provided.
1162 $post_name = "";
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1163 if(isset($content_struct["wp_slug"])) {
9af6317 WP XML-RPC API
ryan authored
1164 $post_name = $content_struct["wp_slug"];
1165 }
1166
1167 // Only use a password if one was given.
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1168 if(isset($content_struct["wp_password"])) {
9af6317 WP XML-RPC API
ryan authored
1169 $post_password = $content_struct["wp_password"];
1170 }
1171
1172 // Only set a post parent if one was given.
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
1173 if(isset($content_struct["wp_page_parent_id"])) {
9af6317 WP XML-RPC API
ryan authored
1174 $post_parent = $content_struct["wp_page_parent_id"];
1175 }
1176
9bc0cc2 More XML-RPC API enhancements from Joseph Scott.
ryan authored
1177 // 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
1178 if(isset($content_struct["wp_page_order"])) {
9af6317 WP XML-RPC API
ryan authored
1179 $menu_order = $content_struct["wp_page_order"];
1180 }
1181
9a75737 Prevent current author from claiming authorship of posts from other a…
markjaquith authored
1182 $post_author = $postdata["post_author"];
25fcd39 XML-RPC fixes to allow for empty/zero settings in various fields. Pro…
ryan authored
1183
9bc0cc2 More XML-RPC API enhancements from Joseph Scott.
ryan authored
1184 // 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
1185 if(
1186 isset($content_struct["wp_author_id"])
1187 && ($user->ID != $content_struct["wp_author_i