Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 2644 lines (2076 sloc) 75.481 kB
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1 <?php
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
2 /**
3 * XML-RPC protocol support for WordPress
4 *
5 * @license GPL v2 <./license.txt>
6 * @package WordPress
7 */
8
9 /**
10 * Whether this is a XMLRPC Request
11 *
12 * @var bool
13 */
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
14 define('XMLRPC_REQUEST', true);
15
16 // Some browser-embedded clients send cookies. We don't want them.
17 $_COOKIE = array();
18
321c310 Remove trailing whitespace
ryan authored
19 // 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
20 // but we can do it ourself.
21 if ( !isset( $HTTP_RAW_POST_DATA ) ) {
22 $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
23 }
24
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
25 // 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
26 if ( isset($HTTP_RAW_POST_DATA) )
27 $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
28
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
29 /** Include the bootstrap for setting up WordPress environment */
5b81135 Allow wp-config.php to exist one level up from WordPress root directo…
ryan authored
30 include('./wp-load.php');
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
31
321c310 Remove trailing whitespace
ryan authored
32 if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd
9ce729e Content-Type, not Content-type, as headers are case sensitive. Props …
rob1n authored
33 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
34 ?>
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
35 <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
36 <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
37 <service>
38 <engineName>WordPress</engineName>
39 <engineLink>http://wordpress.org/</engineLink>
40 <homePageLink><?php bloginfo_rss('url') ?></homePageLink>
41 <apis>
c668167 Make RSD links SSL aware by using site_url(). fixes #7401 for 2.6
ryan authored
42 <api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url('xmlrpc.php') ?>" />
43 <api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php') ?>" />
44 <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php') ?>" />
45 <api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php') ?>" />
46 <api name="Atom" blogID="" preferred="false" apiLink="<?php echo apply_filters('atom_service_url', site_url('wp-app.php/service') ) ?>" />
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
47 </apis>
48 </service>
49 </rsd>
50 <?php
51 exit;
52 }
53
770613e Admin includes reorg. see #4334
ryan authored
54 include_once(ABSPATH . 'wp-admin/includes/admin.php');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
55 include_once(ABSPATH . WPINC . '/class-IXR.php');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
56
57 // Turn off all warnings and errors.
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
58 // error_reporting(0);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
59
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
60 /**
61 * Posts submitted via the xmlrpc interface get that title
62 * @name post_default_title
63 * @var string
64 */
65 $post_default_title = "";
66
67 /**
68 * Whether to enable XMLRPC Logging.
69 *
70 * @name xmlrpc_logging
71 * @var int|bool
72 */
80b3445 fixed comment_status screwup, removed debug stuff, screwed up big tim…
michelvaldrighi authored
73 $xmlrpc_logging = 0;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
74
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
75 /**
76 * logIO() - Writes logging info to a file.
77 *
78 * @uses $xmlrpc_logging
79 * @package WordPress
80 * @subpackage Logging
81 *
82 * @param string $io Whether input or output
83 * @param string $msg Information describing logging reason.
84 * @return bool Always return true
85 */
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
86 function logIO($io,$msg) {
87 global $xmlrpc_logging;
88 if ($xmlrpc_logging) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
89 $fp = fopen("../xmlrpc.log","a+");
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
90 $date = gmdate("Y-m-d H:i:s ");
91 $iot = ($io == "I") ? " Input: " : " Output: ";
92 fwrite($fp, "\n\n".$date.$iot.$msg);
93 fclose($fp);
94 }
95 return true;
96 }
97
75ec542 avoid $HTTP_RAW_POST_DATA notices. props mgeisler and Nazgul. fixes …
markjaquith authored
98 if ( isset($HTTP_RAW_POST_DATA) )
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
99 logIO("I", $HTTP_RAW_POST_DATA);
100
101 /**
102 * @internal
103 * Left undocumented to work on later. If you want to finish, then please do so.
104 *
105 * @package WordPress
106 * @subpackage Publishing
107 */
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
108 class wp_xmlrpc_server extends IXR_Server {
109
110 function wp_xmlrpc_server() {
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
111 $this->methods = array(
9af6317 WP XML-RPC API
ryan authored
112 // WordPress API
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
113 'wp.getUsersBlogs' => 'this:wp_getUsersBlogs',
9af6317 WP XML-RPC API
ryan authored
114 'wp.getPage' => 'this:wp_getPage',
115 'wp.getPages' => 'this:wp_getPages',
116 'wp.newPage' => 'this:wp_newPage',
117 'wp.deletePage' => 'this:wp_deletePage',
118 'wp.editPage' => 'this:wp_editPage',
119 'wp.getPageList' => 'this:wp_getPageList',
120 'wp.getAuthors' => 'this:wp_getAuthors',
121 'wp.getCategories' => 'this:mw_getCategories', // Alias
122 'wp.newCategory' => 'this:wp_newCategory',
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
123 'wp.deleteCategory' => 'this:wp_deleteCategory',
9af6317 WP XML-RPC API
ryan authored
124 'wp.suggestCategories' => 'this:wp_suggestCategories',
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
125 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
126 'wp.getCommentCount' => 'this:wp_getCommentCount',
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See …
westi authored
127 'wp.getPostStatusList' => 'this:wp_getPostStatusList',
128 'wp.getPageStatusList' => 'this:wp_getPageStatusList',
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fi…
ryan authored
129 'wp.getPageTemplates' => 'this:wp_getPageTemplates',
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
130 'wp.getOptions' => 'this:wp_getOptions',
131 'wp.setOptions' => 'this:wp_setOptions',
9af6317 WP XML-RPC API
ryan authored
132
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
133 // Blogger API
134 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
135 'blogger.getUserInfo' => 'this:blogger_getUserInfo',
136 'blogger.getPost' => 'this:blogger_getPost',
137 'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
138 'blogger.getTemplate' => 'this:blogger_getTemplate',
139 'blogger.setTemplate' => 'this:blogger_setTemplate',
140 'blogger.newPost' => 'this:blogger_newPost',
141 'blogger.editPost' => 'this:blogger_editPost',
142 'blogger.deletePost' => 'this:blogger_deletePost',
143
144 // MetaWeblog API (with MT extensions to structs)
145 'metaWeblog.newPost' => 'this:mw_newPost',
146 'metaWeblog.editPost' => 'this:mw_editPost',
147 'metaWeblog.getPost' => 'this:mw_getPost',
148 'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
149 'metaWeblog.getCategories' => 'this:mw_getCategories',
150 'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
151
152 // MetaWeblog API aliases for Blogger API
153 // see http://www.xmlrpc.com/stories/storyReader$2460
154 'metaWeblog.deletePost' => 'this:blogger_deletePost',
155 'metaWeblog.getTemplate' => 'this:blogger_getTemplate',
156 'metaWeblog.setTemplate' => 'this:blogger_setTemplate',
157 'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
158
159 // MovableType API
160 'mt.getCategoryList' => 'this:mt_getCategoryList',
161 'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
162 'mt.getPostCategories' => 'this:mt_getPostCategories',
163 'mt.setPostCategories' => 'this:mt_setPostCategories',
164 'mt.supportedMethods' => 'this:mt_supportedMethods',
165 'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
166 'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
167 'mt.publishPost' => 'this:mt_publishPost',
168
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
169 // PingBack
170 'pingback.ping' => 'this:pingback_ping',
171 'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
172
173 'demo.sayHello' => 'this:sayHello',
174 'demo.addTwoNumbers' => 'this:addTwoNumbers'
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
175 );
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
176
177 $this->initialise_blog_option_info( );
087df40 Allow plugins to hook into XML-RPC server.
saxmatt authored
178 $this->methods = apply_filters('xmlrpc_methods', $this->methods);
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
179 $this->IXR_Server($this->methods);
180 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
181
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
182 function sayHello($args) {
183 return 'Hello!';
184 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
185
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
186 function addTwoNumbers($args) {
187 $number1 = $args[0];
188 $number2 = $args[1];
189 return $number1 + $number2;
190 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
191
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
192 function login_pass_ok($user_login, $user_pass) {
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
193 if ( !get_option( 'enable_xmlrpc' ) ) {
194 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this blog. An admin user can enable them at %s'), admin_url('options-writing.php') ) );
195 return false;
196 }
197
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
198 if (!user_pass_ok($user_login, $user_pass)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
199 $this->error = new IXR_Error(403, __('Bad login/pass combination.'));
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
200 return false;
201 }
202 return true;
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
203 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
204
9c9ba0a Escape XMLRPC args.
ryan authored
205 function escape(&$array) {
206 global $wpdb;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
207
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
208 if(!is_array($array)) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
209 return($wpdb->escape($array));
210 }
211 else {
212 foreach ( (array) $array as $k => $v ) {
213 if (is_array($v)) {
214 $this->escape($array[$k]);
215 } else if (is_object($v)) {
216 //skip
217 } else {
218 $array[$k] = $wpdb->escape($v);
219 }
9c9ba0a Escape XMLRPC args.
ryan authored
220 }
221 }
222 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
223
d889837 Trailing whitespace cleanup
ryan authored
224 function get_custom_fields($post_id) {
225 $post_id = (int) $post_id;
226
227 $custom_fields = array();
228
229 foreach ( (array) has_meta($post_id) as $meta ) {
230 // Don't expose protected fields.
231 if ( strpos($meta['meta_key'], '_wp_') === 0 ) {
232 continue;
233 }
234
235 $custom_fields[] = array(
236 "id" => $meta['meta_id'],
237 "key" => $meta['meta_key'],
238 "value" => $meta['meta_value']
239 );
240 }
241
242 return $custom_fields;
243 }
244
245 function set_custom_fields($post_id, $fields) {
246 $post_id = (int) $post_id;
247
248 foreach ( (array) $fields as $meta ) {
249 if ( isset($meta['id']) ) {
250 $meta['id'] = (int) $meta['id'];
251
252 if ( isset($meta['key']) ) {
253 update_meta($meta['id'], $meta['key'], $meta['value']);
254 }
255 else {
256 delete_meta($meta['id']);
257 }
258 }
259 else {
260 $_POST['metakeyinput'] = $meta['key'];
261 $_POST['metavalue'] = $meta['value'];
262 add_meta($post_id);
263 }
264 }
265 }
630cd82 Custom fields support for xmlrpc from josephscott. fixes #5148
ryan authored
266
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
267 function initialise_blog_option_info( ) {
268 global $wp_version;
269
270 $this->blog_options = array(
271 // Read only options
272 'software_name' => array(
273 'desc' => __( 'Software Name' ),
274 'readonly' => true,
275 'value' => 'WordPress'
276 ),
277 'software_version' => array(
278 'desc' => __( 'Software Version' ),
279 'readonly' => true,
280 'value' => $wp_version
281 ),
282 'blog_url' => array(
283 'desc' => __( 'Blog URL' ),
284 'readonly' => true,
285 'option' => 'siteurl'
286 ),
287
288 // Updatable options
289 'time_zone' => array(
290 'desc' => __( 'Time Zone' ),
291 'readonly' => false,
292 'option' => 'gmt_offset'
293 ),
294 'blog_title' => array(
295 'desc' => __( 'Blog Title' ),
296 'readonly' => false,
297 'option' => 'blogname'
298 ),
299 'blog_tagline' => array(
300 'desc' => __( 'Blog Tagline' ),
301 'readonly' => false,
302 'option' => 'blogdescription'
303 ),
304 'date_format' => array(
305 'desc' => __( 'Date Format' ),
306 'readonly' => false,
307 'option' => 'date_format'
308 ),
309 'time_format' => array(
310 'desc' => __( 'Time Format' ),
311 'readonly' => false,
312 'option' => 'time_format'
313 )
314 );
315
316 $this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options );
317 }
318
9af6317 WP XML-RPC API
ryan authored
319 /**
320 * WordPress XML-RPC API
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
321 * wp_getUsersBlogs
322 */
323 function wp_getUsersBlogs( $args ) {
324 // If this isn't on WPMU then just use blogger_getUsersBlogs
325 if( !function_exists( 'is_site_admin' ) ) {
326 array_unshift( $args, 1 );
327 return $this->blogger_getUsersBlogs( $args );
328 }
329
330 $this->escape( $args );
331
332 $username = $args[0];
333 $password = $args[1];
334
335 if( !$this->login_pass_ok( $username, $password ) )
336 return $this->error;
337
338 do_action( 'xmlrpc_call', 'wp.getUsersBlogs' );
339
340 $user = set_current_user( 0, $username );
341
342 $blogs = (array) get_blogs_of_user( $user->ID );
343 $struct = array( );
344
345 foreach( $blogs as $blog ) {
346 // Don't include blogs that aren't hosted at this site
347 if( $blog->site_id != 1 )
348 continue;
349
350 $blog_id = $blog->userblog_id;
351 switch_to_blog($blog_id);
352 $is_admin = current_user_can('level_8');
353
354 $struct[] = array(
355 'isAdmin' => $is_admin,
356 'url' => get_option( 'home' ) . '/',
357 'blogid' => $blog_id,
358 'blogName' => get_option( 'blogname' ),
359 'xmlrpc' => get_option( 'home' ) . '/xmlrpc.php'
360 );
361 }
362
363 return $struct;
364 }
365
366 /**
367 * WordPress XML-RPC API
9af6317 WP XML-RPC API
ryan authored
368 * wp_getPage
369 */
370 function wp_getPage($args) {
371 $this->escape($args);
372
7602d17 (int)er the dragon.
matt authored
373 $blog_id = (int) $args[0];
374 $page_id = (int) $args[1];
9af6317 WP XML-RPC API
ryan authored
375 $username = $args[2];
376 $password = $args[3];
377
378 if(!$this->login_pass_ok($username, $password)) {
379 return($this->error);
380 }
381
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
382 set_current_user( 0, $username );
383 if( !current_user_can( 'edit_page', $page_id ) )
384 return new IXR_Error( 401, __( 'Sorry, you can not edit this page.' ) );
385
3177977 '>"
westi authored
386 do_action('xmlrpc_call', 'wp.getPage');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
387
9af6317 WP XML-RPC API
ryan authored
388 // Lookup page info.
389 $page = get_page($page_id);
390
391 // If we found the page then format the data.
392 if($page->ID && ($page->post_type == "page")) {
393 // Get all of the page content and link.
394 $full_page = get_extended($page->post_content);
395 $link = post_permalink($page->ID);
396
d162935 WP XML-RPC API enhancements.
ryan authored
397 // Get info the page parent if there is one.
398 $parent_title = "";
399 if(!empty($page->post_parent)) {
400 $parent = get_page($page->post_parent);
401 $parent_title = $parent->post_title;
402 }
403
9af6317 WP XML-RPC API
ryan authored
404 // Determine comment and ping settings.
405 $allow_comments = ("open" == $page->comment_status) ? 1 : 0;
406 $allow_pings = ("open" == $page->ping_status) ? 1 : 0;
407
408 // Format page date.
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
409 $page_date = mysql2date("Ymd\TH:i:s", $page->post_date);
410 $page_date_gmt = mysql2date("Ymd\TH:i:s", $page->post_date_gmt);
9af6317 WP XML-RPC API
ryan authored
411
412 // Pull the categories info together.
413 $categories = array();
414 foreach(wp_get_post_categories($page->ID) as $cat_id) {
415 $categories[] = get_cat_name($cat_id);
416 }
417
d162935 WP XML-RPC API enhancements.
ryan authored
418 // Get the author info.
419 $author = get_userdata($page->post_author);
9af6317 WP XML-RPC API
ryan authored
420
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fi…
ryan authored
421 $page_template = get_post_meta( $page->ID, '_wp_page_template', true );
422 if( empty( $page_template ) )
423 $page_template = 'default';
424
9af6317 WP XML-RPC API
ryan authored
425 $page_struct = array(
d162935 WP XML-RPC API enhancements.
ryan authored
426 "dateCreated" => new IXR_Date($page_date),
427 "userid" => $page->post_author,
428 "page_id" => $page->ID,
429 "page_status" => $page->post_status,
430 "description" => $full_page["main"],
431 "title" => $page->post_title,
432 "link" => $link,
433 "permaLink" => $link,
434 "categories" => $categories,
435 "excerpt" => $page->post_excerpt,
436 "text_more" => $full_page["extended"],
437 "mt_allow_comments" => $allow_comments,
438 "mt_allow_pings" => $allow_pings,
439 "wp_slug" => $page->post_name,
440 "wp_password" => $page->post_password,
e71e25d XMLRPC API updates.
ryan authored
441 "wp_author" => $author->display_name,
d162935 WP XML-RPC API enhancements.
ryan authored
442 "wp_page_parent_id" => $page->post_parent,
443 "wp_page_parent_title" => $parent_title,
444 "wp_page_order" => $page->menu_order,
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
445 "wp_author_id" => $author->ID,
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
446 "wp_author_display_name" => $author->display_name,
630cd82 Custom fields support for xmlrpc from josephscott. fixes #5148
ryan authored
447 "date_created_gmt" => new IXR_Date($page_date_gmt),
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fi…
ryan authored
448 "custom_fields" => $this->get_custom_fields($page_id),
449 "wp_page_template" => $page_template
9af6317 WP XML-RPC API
ryan authored
450 );
451
452 return($page_struct);
453 }
454 // If the page doesn't exist indicate that.
455 else {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
456 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
457 }
458 }
459
460 /**
461 * WordPress XML-RPC API
462 * wp_getPages
463 */
464 function wp_getPages($args) {
465 $this->escape($args);
466
7602d17 (int)er the dragon.
matt authored
467 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
468 $username = $args[1];
469 $password = $args[2];
470
471 if(!$this->login_pass_ok($username, $password)) {
472 return($this->error);
473 }
474
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
475 set_current_user( 0, $username );
476 if( !current_user_can( 'edit_pages' ) )
477 return new IXR_Error( 401, __( 'Sorry, you can not edit pages.' ) );
478
3177977 '>"
westi authored
479 do_action('xmlrpc_call', 'wp.getPages');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
480
9af6317 WP XML-RPC API
ryan authored
481 // Lookup info on pages.
482 $pages = get_pages();
483 $num_pages = count($pages);
484
485 // If we have pages, put together their info.
486 if($num_pages >= 1) {
487 $pages_struct = array();
488
489 for($i = 0; $i < $num_pages; $i++) {
490 $page = wp_xmlrpc_server::wp_getPage(array(
491 $blog_id, $pages[$i]->ID, $username, $password
492 ));
493 $pages_struct[] = $page;
494 }
495
496 return($pages_struct);
497 }
498 // If no pages were found return an error.
499 else {
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return emp…
ryan authored
500 return(array());
9af6317 WP XML-RPC API
ryan authored
501 }
502 }
503
504 /**
505 * WordPress XML-RPC API
506 * wp_newPage
507 */
508 function wp_newPage($args) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
509 // Items not escaped here will be escaped in newPost.
510 $username = $this->escape($args[1]);
511 $password = $this->escape($args[2]);
9af6317 WP XML-RPC API
ryan authored
512 $page = $args[3];
513 $publish = $args[4];
514
515 if(!$this->login_pass_ok($username, $password)) {
516 return($this->error);
517 }
518
3177977 '>"
westi authored
519 do_action('xmlrpc_call', 'wp.newPage');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
520
9af6317 WP XML-RPC API
ryan authored
521 // Set the user context and check if they are allowed
522 // to add new pages.
523 $user = set_current_user(0, $username);
524 if(!current_user_can("publish_pages")) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
525 return(new IXR_Error(401, __("Sorry, you can not add new pages.")));
9af6317 WP XML-RPC API
ryan authored
526 }
527
528 // Mark this as content for a page.
529 $args[3]["post_type"] = "page";
530
531 // Let mw_newPost do all of the heavy lifting.
532 return($this->mw_newPost($args));
533 }
534
535 /**
536 * WordPress XML-RPC API
537 * wp_deletePage
538 */
539 function wp_deletePage($args) {
540 $this->escape($args);
541
7602d17 (int)er the dragon.
matt authored
542 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
543 $username = $args[1];
544 $password = $args[2];
7602d17 (int)er the dragon.
matt authored
545 $page_id = (int) $args[3];
9af6317 WP XML-RPC API
ryan authored
546
547 if(!$this->login_pass_ok($username, $password)) {
548 return($this->error);
549 }
550
3177977 '>"
westi authored
551 do_action('xmlrpc_call', 'wp.deletePage');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
552
9af6317 WP XML-RPC API
ryan authored
553 // Get the current page based on the page_id and
554 // make sure it is a page and not a post.
555 $actual_page = wp_get_single_post($page_id, ARRAY_A);
556 if(
557 !$actual_page
558 || ($actual_page["post_type"] != "page")
559 ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
560 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
561 }
562
563 // Set the user context and make sure they can delete pages.
564 set_current_user(0, $username);
565 if(!current_user_can("delete_page", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
566 return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page.")));
9af6317 WP XML-RPC API
ryan authored
567 }
568
569 // Attempt to delete the page.
570 $result = wp_delete_post($page_id);
571 if(!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
572 return(new IXR_Error(500, __("Failed to delete the page.")));
9af6317 WP XML-RPC API
ryan authored
573 }
574
575 return(true);
576 }
577
578 /**
579 * WordPress XML-RPC API
580 * wp_editPage
581 */
582 function wp_editPage($args) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
583 // Items not escaped here will be escaped in editPost.
7602d17 (int)er the dragon.
matt authored
584 $blog_id = (int) $args[0];
ae7fa6c Cast to int after escaping. Props Joseph Scott.
ryan authored
585 $page_id = (int) $this->escape($args[1]);
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
586 $username = $this->escape($args[2]);
587 $password = $this->escape($args[3]);
9af6317 WP XML-RPC API
ryan authored
588 $content = $args[4];
589 $publish = $args[5];
590
591 if(!$this->login_pass_ok($username, $password)) {
592 return($this->error);
593 }
594
3177977 '>"
westi authored
595 do_action('xmlrpc_call', 'wp.editPage');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
596
9af6317 WP XML-RPC API
ryan authored
597 // Get the page data and make sure it is a page.
598 $actual_page = wp_get_single_post($page_id, ARRAY_A);
599 if(
600 !$actual_page
601 || ($actual_page["post_type"] != "page")
602 ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
603 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
604 }
605
606 // Set the user context and make sure they are allowed to edit pages.
607 set_current_user(0, $username);
608 if(!current_user_can("edit_page", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
609 return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page.")));
9af6317 WP XML-RPC API
ryan authored
610 }
611
612 // Mark this as content for a page.
613 $content["post_type"] = "page";
614
615 // Arrange args in the way mw_editPost understands.
616 $args = array(
617 $page_id,
618 $username,
619 $password,
620 $content,
621 $publish
622 );
623
624 // Let mw_editPost do all of the heavy lifting.
625 return($this->mw_editPost($args));
626 }
627
628 /**
629 * WordPress XML-RPC API
630 * wp_getPageList
631 */
632 function wp_getPageList($args) {
633 global $wpdb;
634
635 $this->escape($args);
636
7602d17 (int)er the dragon.
matt authored
637 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
638 $username = $args[1];
639 $password = $args[2];
640
641 if(!$this->login_pass_ok($username, $password)) {
642 return($this->error);
643 }
644
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
645 set_current_user( 0, $username );
646 if( !current_user_can( 'edit_pages' ) )
647 return new IXR_Error( 401, __( 'Sorry, you can not edit pages.' ) );
648
3177977 '>"
westi authored
649 do_action('xmlrpc_call', 'wp.getPageList');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
650
9af6317 WP XML-RPC API
ryan authored
651 // Get list of pages ids and titles
652 $page_list = $wpdb->get_results("
653 SELECT ID page_id,
d162935 WP XML-RPC API enhancements.
ryan authored
654 post_title page_title,
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
655 post_parent page_parent_id,
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
656 post_date_gmt,
657 post_date
9af6317 WP XML-RPC API
ryan authored
658 FROM {$wpdb->posts}
659 WHERE post_type = 'page'
660 ORDER BY ID
661 ");
662
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
663 // The date needs to be formated properly.
664 $num_pages = count($page_list);
665 for($i = 0; $i < $num_pages; $i++) {
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
666 $post_date = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date);
667 $post_date_gmt = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date_gmt);
668
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
669 $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
670 $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
671
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #41…
ryan authored
672 unset($page_list[$i]->post_date_gmt);
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT va…
markjaquith authored
673 unset($page_list[$i]->post_date);
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
674 }
675
9af6317 WP XML-RPC API
ryan authored
676 return($page_list);
677 }
678
679 /**
680 * WordPress XML-RPC API
681 * wp_getAuthors
682 */
683 function wp_getAuthors($args) {
684
685 $this->escape($args);
686
7602d17 (int)er the dragon.
matt authored
687 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
688 $username = $args[1];
689 $password = $args[2];
690
691 if(!$this->login_pass_ok($username, $password)) {
692 return($this->error);
693 }
694
2490ec4 Limit what getAuthors exposes. Props josephscott for the patch and xk…
ryan authored
695 set_current_user(0, $username);
696 if(!current_user_can("edit_posts")) {
697 return(new IXR_Error(401, __("Sorry, you can not edit posts on this blog.")));
698 }
699
3177977 '>"
westi authored
700 do_action('xmlrpc_call', 'wp.getAuthors');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
701
2490ec4 Limit what getAuthors exposes. Props josephscott for the patch and xk…
ryan authored
702 $authors = array();
703 foreach( (array) get_users_of_blog() as $row ) {
704 $authors[] = array(
705 "user_id" => $row->user_id,
706 "user_login" => $row->user_login,
707 "display_name" => $row->display_name
708 );
709 }
710
711 return($authors);
9af6317 WP XML-RPC API
ryan authored
712 }
713
714 /**
715 * WordPress XML-RPC API
716 * wp_newCategory
717 */
718 function wp_newCategory($args) {
719 $this->escape($args);
720
7602d17 (int)er the dragon.
matt authored
721 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
722 $username = $args[1];
723 $password = $args[2];
724 $category = $args[3];
725
726 if(!$this->login_pass_ok($username, $password)) {
727 return($this->error);
728 }
729
3177977 '>"
westi authored
730 do_action('xmlrpc_call', 'wp.newCategory');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
731
9af6317 WP XML-RPC API
ryan authored
732 // Set the user context and make sure they are
733 // allowed to add a category.
734 set_current_user(0, $username);
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
735 if(!current_user_can("manage_categories")) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
736 return(new IXR_Error(401, __("Sorry, you do not have the right to add a category.")));
9af6317 WP XML-RPC API
ryan authored
737 }
738
739 // If no slug was provided make it empty so that
740 // WordPress will generate one.
741 if(empty($category["slug"])) {
742 $category["slug"] = "";
743 }
744
745 // If no parent_id was provided make it empty
746 // so that it will be a top level page (no parent).
c8997ff Reverse logic.
ryan authored
747 if ( !isset($category["parent_id"]) )
9af6317 WP XML-RPC API
ryan authored
748 $category["parent_id"] = "";
749
750 // If no description was provided make it empty.
751 if(empty($category["description"])) {
752 $category["description"] = "";
753 }
2f09416 Trim empty lines. Nothing but newline.
ryan authored
754
9af6317 WP XML-RPC API
ryan authored
755 $new_category = array(
756 "cat_name" => $category["name"],
757 "category_nicename" => $category["slug"],
758 "category_parent" => $category["parent_id"],
759 "category_description" => $category["description"]
760 );
761
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
762 $cat_id = wp_insert_category($new_category);
9af6317 WP XML-RPC API
ryan authored
763 if(!$cat_id) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
764 return(new IXR_Error(500, __("Sorry, the new category failed.")));
9af6317 WP XML-RPC API
ryan authored
765 }
766
767 return($cat_id);
768 }
769
770 /**
771 * WordPress XML-RPC API
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
772 * wp_deleteCategory
773 */
774 function wp_deleteCategory($args) {
775 $this->escape($args);
776
777 $blog_id = (int) $args[0];
778 $username = $args[1];
779 $password = $args[2];
780 $category_id = (int) $args[3];
781
782 if( !$this->login_pass_ok( $username, $password ) ) {
783 return $this->error;
784 }
785
3177977 '>"
westi authored
786 do_action('xmlrpc_call', 'wp.deleteCategory');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
787
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
788 set_current_user(0, $username);
789 if( !current_user_can("manage_categories") ) {
fc943e2 Grammar fixes from takayukister and thenlich. fixes #5992
ryan authored
790 return new IXR_Error( 401, __( "Sorry, you do not have the right to delete a category." ) );
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
791 }
792
793 return wp_delete_category( $category_id );
794 }
795
796
797 /**
798 * WordPress XML-RPC API
9af6317 WP XML-RPC API
ryan authored
799 * wp_suggestCategories
800 */
801 function wp_suggestCategories($args) {
802 $this->escape($args);
803
7602d17 (int)er the dragon.
matt authored
804 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
805 $username = $args[1];
806 $password = $args[2];
807 $category = $args[3];
070d2fd Int cast. Props to Alexander Concha for the find, Joseph Scott for t…
markjaquith authored
808 $max_results = (int) $args[4];
9af6317 WP XML-RPC API
ryan authored
809
810 if(!$this->login_pass_ok($username, $password)) {
811 return($this->error);
812 }
813
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
814 set_current_user(0, $username);
d889837 Trailing whitespace cleanup
ryan authored
815 if( !current_user_can( 'edit_posts' ) )
9f9769b Add some more actions to xmlrpc. Fixes #5686 props joesephscott.
westi authored
816 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this blog in order to view categories.' ) );
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
817
3177977 '>"
westi authored
818 do_action('xmlrpc_call', 'wp.suggestCategories');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
819
fc8d883 Fix wp.suggestCategories return values. Props josephscott. fixes #5406
ryan authored
820 $category_suggestions = array();
7217266 AND get_terms() field queries
ryan authored
821 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category);
fc8d883 Fix wp.suggestCategories return values. Props josephscott. fixes #5406
ryan authored
822 foreach ( (array) get_categories($args) as $cat ) {
823 $category_suggestions[] = array(
824 "category_id" => $cat->cat_ID,
825 "category_name" => $cat->cat_name
826 );
827 }
9af6317 WP XML-RPC API
ryan authored
828
829 return($category_suggestions);
830 }
831
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
832 function wp_getCommentCount( $args ) {
d889837 Trailing whitespace cleanup
ryan authored
833 $this->escape($args);
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
834
d889837 Trailing whitespace cleanup
ryan authored
835 $blog_id = (int) $args[0];
836 $username = $args[1];
837 $password = $args[2];
838 $post_id = (int) $args[3];
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
839
d889837 Trailing whitespace cleanup
ryan authored
840 if( !$this->login_pass_ok( $username, $password ) ) {
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
841 return $this->error;
d889837 Trailing whitespace cleanup
ryan authored
842 }
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
843
d889837 Trailing whitespace cleanup
ryan authored
844 set_current_user( 0, $username );
845 if( !current_user_can( 'edit_posts' ) ) {
428d820 Grammar fix. Props thenlich and hansengel. fixes #5991
ryan authored
846 return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) );
d889837 Trailing whitespace cleanup
ryan authored
847 }
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
848
9f9769b Add some more actions to xmlrpc. Fixes #5686 props joesephscott.
westi authored
849 do_action('xmlrpc_call', 'wp.getCommentCount');
850
94eb722 Use wp_count_comments() in wp.getCommentCount. Props josephscott. fix…
ryan authored
851 $count = wp_count_comments( $post_id );
852 return array(
853 "approved" => $count->approved,
854 "awaiting_moderation" => $count->moderated,
855 "spam" => $count->spam,
856 "total_comments" => $count->total_comments
857 );
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
858 }
859
9af6317 WP XML-RPC API
ryan authored
860
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See …
westi authored
861 function wp_getPostStatusList( $args ) {
862 $this->escape( $args );
863
864 $blog_id = (int) $args[0];
865 $username = $args[1];
866 $password = $args[2];
867
868 if( !$this->login_pass_ok( $username, $password ) ) {
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
869 return $this->error;
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See …
westi authored
870 }
871
872 set_current_user( 0, $username );
873 if( !current_user_can( 'edit_posts' ) ) {
874 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
875 }
876
9f9769b Add some more actions to xmlrpc. Fixes #5686 props joesephscott.
westi authored
877 do_action('xmlrpc_call', 'wp.getPostStatusList');
878
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See …
westi authored
879 return get_post_statuses( );
880 }
881
882
883 function wp_getPageStatusList( $args ) {
884 $this->escape( $args );
885
886 $blog_id = (int) $args[0];
887 $username = $args[1];
888 $password = $args[2];
889
890 if( !$this->login_pass_ok( $username, $password ) ) {
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
891 return $this->error;
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See …
westi authored
892 }
893
894 set_current_user( 0, $username );
895 if( !current_user_can( 'edit_posts' ) ) {
a33b080 Typo fix from rnt. fixes #5700
ryan authored
896 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See …
westi authored
897 }
898
9f9769b Add some more actions to xmlrpc. Fixes #5686 props joesephscott.
westi authored
899 do_action('xmlrpc_call', 'wp.getPageStatusList');
900
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See …
westi authored
901 return get_page_statuses( );
902 }
903
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fi…
ryan authored
904 function wp_getPageTemplates( $args ) {
905 $this->escape( $args );
906
907 $blog_id = (int) $args[0];
908 $username = $args[1];
909 $password = $args[2];
910
911 if( !$this->login_pass_ok( $username, $password ) ) {
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
912 return $this->error;
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fi…
ryan authored
913 }
914
915 set_current_user( 0, $username );
916 if( !current_user_can( 'edit_pages' ) ) {
917 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
918 }
919
920 $templates = get_page_templates( );
921 $templates['Default'] = 'default';
922
923 return $templates;
924 }
925
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
926 function wp_getOptions( $args ) {
927 $this->escape( $args );
928
929 $blog_id = (int) $args[0];
930 $username = $args[1];
931 $password = $args[2];
932 $options = (array) $args[3];
933
934 if( !$this->login_pass_ok( $username, $password ) )
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
935 return $this->error;
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
936
937 $user = set_current_user( 0, $username );
938
939 // If no specific options where asked for, return all of them
940 if (count( $options ) == 0 ) {
941 $options = array_keys($this->blog_options);
942 }
943
944 return $this->_getOptions($options);
945 }
946
947 function _getOptions($options)
948 {
949 $data = array( );
950 foreach( $options as $option ) {
951 if( array_key_exists( $option, $this->blog_options ) )
952 {
953 $data[$option] = $this->blog_options[$option];
954 //Is the value static or dynamic?
955 if( isset( $data[$option]['option'] ) ) {
956 $data[$option]['value'] = get_option( $data[$option]['option'] );
957 unset($data[$option]['option']);
958 }
959 }
960 }
961
962 return $data;
963 }
964
965 function wp_setOptions( $args ) {
966 $this->escape( $args );
967
968 $blog_id = (int) $args[0];
969 $username = $args[1];
970 $password = $args[2];
971 $options = (array) $args[3];
972
973 if( !$this->login_pass_ok( $username, $password ) )
3f90dc2 More informative error message when remote publishing is disabled. D…
ryan authored
974 return $this->error;
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
975
976 $user = set_current_user( 0, $username );
977 if( !current_user_can( 'manage_options' ) )
978 return new IXR_Error( 403, __( 'You are not allowed to update options.' ) );
979
980 foreach( $options as $o_name => $o_value ) {
981 $option_names[] = $o_name;
982 if( empty( $o_value ) )
983 continue;
984
985 if( !array_key_exists( $o_name, $this->blog_options ) )
986 continue;
987
988 if( $this->blog_options[$o_name]['readonly'] == true )
989 continue;
990
991 update_option( $this->blog_options[$o_name]['option'], $o_value );
992 }
993
994 //Now return the updated values
995 return $this->_getOptions($option_names);
996 }
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See …
westi authored
997
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
998 /* Blogger API functions
999 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
1000 */
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1001
1002
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1003 /* blogger.getUsersBlogs will make more sense once we support multiple blogs */
1004 function blogger_getUsersBlogs($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1005
9c9ba0a Escape XMLRPC args.
ryan authored
1006 $this->escape($args);
1007
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
1008 $user_login = $args[1];
1009 $user_pass = $args[2];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1010
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
1011 if (!$this->login_pass_ok($user_login, $user_pass)) {
1012 return $this->error;
1013 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1014
3177977 '>"
westi authored
1015 do_action('xmlrpc_call', 'blogger.getUsersBlogs');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1016
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
1017 set_current_user(0, $user_login);
25b49b2 Remove last remaining user level checks in favor of capabilities chec…
markjaquith authored
1018 $is_admin = current_user_can('manage_options');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1019
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
1020 $struct = array(
1021 'isAdmin' => $is_admin,
1022 'url' => get_option('home') . '/',
1023 'blogid' => '1',
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
1024 'blogName' => get_option('blogname'),
1025 'xmlrpc' => get_option('home') . '/xmlrpc.php',
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
1026 );
e762c60 Remove debug cruft. fixes #2273
ryan authored
1027
be3e9aa Whitespace cleanup. Props donncha. fixes #4034
ryan authored
1028 return array($struct);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1029 }
1030
1031
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1032 /* blogger.getUsersInfo gives your client some info about you, so you don't have to */
1033 function blogger_getUserInfo($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1034
9c9ba0a Escape XMLRPC args.
ryan authored
1035 $this->escape($args);
1036
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1037 $user_login = $args[1];
1038 $user_pass = $args[2];
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
1039
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1040 if (!$this->login_pass_ok($user_login, $user_pass)) {
1041 return $this->error;
1042 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
1043
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
1044 set_current_user( 0, $user_login );
d889837 Trailing whitespace cleanup
ryan authored
1045 if( !current_user_can( 'edit_posts' ) )
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
1046 return new IXR_Error( 401, __( 'Sorry, you do not have access to user data on this blog.' ) );
1047
3177977 '>"
westi authored
1048 do_action('xmlrpc_call', 'blogger.getUserInfo');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1049
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1050 $user_data = get_userdatabylogin($user_login);
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1051
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1052 $struct = array(
1053 'nickname' => $user_data->nickname,
1054 'userid' => $user_data->ID,
1055 'url' => $user_data->user_url,
1056 'lastname' => $user_data->last_name,
1057 'firstname' => $user_data->first_name
1058 );
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1059
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1060 return $struct;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1061 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1062
1063
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1064 /* blogger.getPost ...gets a post */
1065 function blogger_getPost($args) {
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1066
9c9ba0a Escape XMLRPC args.
ryan authored
1067 $this->escape($args);
1068
7602d17 (int)er the dragon.
matt authored
1069 $post_ID = (int) $args[1];
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1070 $user_login = $args[2];
1071 $user_pass = $args[3];
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1072
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1073 if (!$this->login_pass_ok($user_login, $user_pass)) {
1074 return $this->error;
1075 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1076
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
1077 set_current_user( 0, $user_login );
d889837 Trailing whitespace cleanup
ryan authored
1078 if( !current_user_can( 'edit_post', $post_ID ) )
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
1079 return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) );
1080
3177977 '>"
westi authored
1081 do_action('xmlrpc_call', 'blogger.getPost');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1082
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1083 $post_data = wp_get_single_post($post_ID, ARRAY_A);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1084
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1085 $categories = implode(',', wp_get_post_categories($post_ID));
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1086
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1087 $content = '<title>'.stripslashes($post_data['post_title']).'</title>';
1088 $content .= '<category>'.$categories.'</category>';
1089 $content .= stripslashes($post_data['post_content']);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1090
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1091 $struct = array(
1092 'userid' => $post_data['post_author'],
1093 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
1094 'content' => $content,
1095 'postid' => $post_data['ID']
1096 );
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1097
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1098 return $struct;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1099 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1100
1101
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1102 /* blogger.getRecentPosts ...gets recent posts */
1103 function blogger_getRecentPosts($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1104
9c9ba0a Escape XMLRPC args.
ryan authored
1105 $this->escape($args);
1106
7602d17 (int)er the dragon.
matt authored
1107 $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
1108 $user_login = $args[2];
1109 $user_pass = $args[3];
1110 $num_posts = $args[4];
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1111
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1112 if (!$this->login_pass_ok($user_login, $user_pass)) {
1113 return $this->error;
1114 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1115
3177977 '>"
westi authored
1116 do_action('xmlrpc_call', 'blogger.getRecentPosts');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1117
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1118 $posts_list = wp_get_recent_posts($num_posts);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1119
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
1120 set_current_user( 0, $user_login );
1121
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1122 if (!$posts_list) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1123 $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
1124 return $this->error;
1125 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1126
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1127 foreach ($posts_list as $entry) {
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
1128 if( !current_user_can( 'edit_post', $entry['ID'] ) )
1129 continue;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1130
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1131 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
1132 $categories = implode(',', wp_get_post_categories($entry['ID']));
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
1133
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1134 $content = '<title>'.stripslashes($entry['post_title']).'</title>';
1135 $content .= '<category>'.$categories.'</category>';
1136 $content .= stripslashes($entry['post_content']);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1137
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1138 $struct[] = array(
1139 'userid' => $entry['post_author'],
1140 'dateCreated' => new IXR_Date($post_date),
1141 'content' => $content,
1142 'postid' => $entry['ID'],
1143 );
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1144
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1145 }
1146
1147 $recent_posts = array();
1148 for ($j=0; $j<count($struct); $j++) {
1149 array_push($recent_posts, $struct[$j]);
1150 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1151
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fix…
ryan authored
1152 return $recent_posts;
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1153 }
1154
1155
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1156 /* blogger.getTemplate returns your blog_filename */
1157 function blogger_getTemplate($args) {
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1158
9c9ba0a Escape XMLRPC args.
ryan authored
1159 $this->escape($args);
1160
7602d17 (int)er the dragon.
matt authored
1161 $blog_ID = (int) $args[1];
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1162 $user_login = $args[2];
1163 $user_pass = $args[3];
1164 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1165
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1166 if (!$this->login_pass_ok($user_login, $user_pass)) {
1167 return $this->error;
1168 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1169
3177977 '>"
westi authored
1170 do_action('xmlrpc_call', 'blogger.getTemplate');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1171
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
1172 set_current_user(0, $user_login);
1173 if ( !current_user_can('edit_themes') ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
1174 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
1175 }
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1176
8c454d7 Favor the term "blog" instead of "weblog." Props foolswisdom and Naz…
markjaquith authored
1177 /* 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
1178 $filename = get_option('home') . '/';
4177556 Add HTTPS support, fixes #1372
matt authored
1179 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
1180
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1181 $f = fopen($filename, 'r');
1182 $content = fread($f, filesize($filename));
1183 fclose($f);
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1184
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1185 /* so it is actually editable with a windows/mac client */
321c310 Remove trailing whitespace
ryan authored
1186 // 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
1187
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1188 return $content;
1189 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1190
1191
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1192 /* blogger.setTemplate updates the content of blog_filename */
1193 function blogger_setTemplate($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1194
9c9ba0a Escape XMLRPC args.
ryan authored
1195 $this->escape($args);
1196
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1197 $blog_ID = (int) $args[1];
1198 $user_login = $args[2];
1199 $user_pass = $args[3];
1200 $content = $args[4];
1201 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
7feb841 added blogger.getTemplate and blogger.setTemplate
michelvaldrighi authored
1202
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1203 if (!$this->login_pass_ok($user_login, $user_pass)) {
1204 return $this->error;
1205 }
1387744 added blogger.newPost
michelvaldrighi authored
1206
3177977 '>"
westi authored
1207 do_action('xmlrpc_call', 'blogger.setTemplate');
1387744 added blogger.newPost
michelvaldrighi authored
1208
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1209 set_current_user(0, $user_login);
1210 if ( !current_user_can('edit_themes') ) {
1211 return new IXR_Error(401, __('Sorry, this user can not edit the template.'));
1212 }
1387744 added blogger.newPost
michelvaldrighi authored
1213
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1214 /* warning: here we make the assumption that the blog's URL is on the same server */
1215 $filename = get_option('home') . '/';
1216 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
1217
1218 if ($f = fopen($filename, 'w+')) {
1219 fwrite($f, $content);
1220 fclose($f);
1221 } else {
1222 return new IXR_Error(500, __('Either the file is not writable, or something wrong happened. The file has not been updated.'));
1223 }
1387744 added blogger.newPost
michelvaldrighi authored
1224
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1225 return true;
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1226 }
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1227
1228
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1229 /* blogger.newPost ...creates a new post */
1230 function blogger_newPost($args) {
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1231
9c9ba0a Escape XMLRPC args.
ryan authored
1232 $this->escape($args);
1233
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1234 $blog_ID = (int) $args[1]; /* though we don't use it yet */
1235 $user_login = $args[2];
1236 $user_pass = $args[3];
1237 $content = $args[4];
1238 $publish = $args[5];
d889837 Trailing whitespace cleanup
ryan authored
1239
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1240 if (!$this->login_pass_ok($user_login, $user_pass)) {
1241 return $this->error;
1242 }
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1243
3177977 '>"
westi authored
1244 do_action('xmlrpc_call', 'blogger.newPost');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1245
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1246 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
1247 $user = set_current_user(0, $user_login);
1248 if ( !current_user_can($cap) )
1249 return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.'));
d889837 Trailing whitespace cleanup
ryan authored
1250
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1251 $post_status = ($publish) ? 'publish' : 'draft';
d889837 Trailing whitespace cleanup
ryan authored
1252
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1253 $post_author = $user->ID;
d889837 Trailing whitespace cleanup
ryan authored
1254
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1255 $post_title = xmlrpc_getposttitle($content);
1256 $post_category = xmlrpc_getpostcategory($content);
1257 $post_content = xmlrpc_removepostdata($content);
d889837 Trailing whitespace cleanup
ryan authored
1258
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1259 $post_date = current_time('mysql');
1260 $post_date_gmt = current_time('mysql', 1);
d889837 Trailing whitespace cleanup
ryan authored
1261
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1262 $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
d889837 Trailing whitespace cleanup
ryan authored
1263
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1264 $post_ID = wp_insert_post($post_data);
1265 if ( is_wp_error( $post_ID ) )
1266 return new IXR_Error(500, $post_ID->get_error_message());
1267
1268 if (!$post_ID)
1269 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
1270
1271 $this->attach_uploads( $post_ID, $post_content );
1272
1273 logIO('O', "Posted ! ID: $post_ID");
1274
1275 return $post_ID;
1387744 added blogger.newPost
michelvaldrighi authored
1276 }
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
1277
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1278 /* blogger.editPost ...edits a post */
1279 function blogger_editPost($args) {
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
1280
9c9ba0a Escape XMLRPC args.
ryan authored
1281 $this->escape($args);
d889837 Trailing whitespace cleanup
ryan authored
1282
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1283 $post_ID = (int) $args[1];
1284 $user_login = $args[2];
1285 $user_pass = $args[3];
1286 $content = $args[4];
1287 $publish = $args[5];
d889837 Trailing whitespace cleanup
ryan authored
1288
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1289 if (!$this->login_pass_ok($user_login, $user_pass)) {
1290 return $this->error;
1291 }
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1292
3177977 '>"
westi authored
1293 do_action('xmlrpc_call', 'blogger.editPost');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1294
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1295 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
d889837 Trailing whitespace cleanup
ryan authored
1296
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1297 if (!$actual_post) {
1298 return new IXR_Error(404, __('Sorry, no such post.'));
1299 }
d889837 Trailing whitespace cleanup
ryan authored
1300
9c9ba0a Escape XMLRPC args.
ryan authored
1301 $this->escape($actual_post);
d889837 Trailing whitespace cleanup
ryan authored
1302
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1303 set_current_user(0, $user_login);
1304 if ( !current_user_can('edit_post', $post_ID) )
1305 return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.'));
d889837 Trailing whitespace cleanup
ryan authored
1306
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1307 extract($actual_post, EXTR_SKIP);
d889837 Trailing whitespace cleanup
ryan authored
1308
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1309 if ( ('publish' == $post_status) && !current_user_can('publish_posts') )
1310 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
d889837 Trailing whitespace cleanup
ryan authored
1311
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1312 $post_title = xmlrpc_getposttitle($content);
1313 $post_category = xmlrpc_getpostcategory($content);
1314 $post_content = xmlrpc_removepostdata($content);
d889837 Trailing whitespace cleanup
ryan authored
1315
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1316 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt');
d889837 Trailing whitespace cleanup
ryan authored
1317
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1318 $result = wp_update_post($postdata);
d889837 Trailing whitespace cleanup
ryan authored
1319
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1320 if (!$result) {
1321 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.'));
1322 }
1323 $this->attach_uploads( $ID, $post_content );
d889837 Trailing whitespace cleanup
ryan authored
1324
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1325 return true;
a41790f added blogger.editPost and blogger.deletePost, time to move on to met…
michelvaldrighi authored
1326 }
1327
1328
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got repl…
michelvaldrighi authored
1329 /* blogger.deletePost ...deletes a post */
1330 function blogger_deletePost($args) {
9c9ba0a Escape XMLRPC args.
ryan authored
1331 $this->escape($args);
d889837 Trailing whitespace cleanup
ryan authored
1332
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1333 $post_ID = (int) $args[1];
1334 $user_login = $args[2];
1335 $user_pass = $args[3];
1336 $publish = $args[4];
d889837 Trailing whitespace cleanup
ryan authored
1337
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1338 if (!$this->login_pass_ok($user_login, $user_pass)) {
1339 return $this->error;
1340 }
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1341
3177977 '>"
westi authored
1342 do_action('xmlrpc_call', 'blogger.deletePost');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1343
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1344 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
d889837 Trailing whitespace cleanup
ryan authored
1345
7f92e82 Check type. Props josephscott. fixes #8267 for 2.6
ryan authored
1346 if (!$actual_post || $actual_post['post_type'] != 'post') {
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1347 return new IXR_Error(404, __('Sorry, no such post.'));
1348 }
d889837 Trailing whitespace cleanup
ryan authored
1349
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1350 set_current_user(0, $user_login);
1351 if ( !current_user_can('edit_post', $post_ID) )
1352 return new IXR_Error(401, __('Sorry, you do not have the right to delete this post.'));
d889837 Trailing whitespace cleanup
ryan authored
1353
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1354 $result = wp_delete_post($post_ID);
d889837 Trailing whitespace cleanup
ryan authored
1355
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1356 if (!$result) {
1357 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.'));
1358 }
d889837 Trailing whitespace cleanup
ryan authored
1359
028a159 Remove unused vars. Props DD32. see #5418
ryan authored
1360 return true;
7c7e0fb moved wp-admin/xmlrpc.php to the root dir
michelvaldrighi authored
1361 }
1300404 added metaweblog methods: newPost, editPost, getPost -- UNTESTED (yet)
michelvaldrighi authored
1362
1363
1364
a7322e8