Ticket #18426: wp.editUser.patch
File wp.editUser.patch, 143.1 KB (added by , 13 years ago) |
---|
-
class-wp-xmlrpc-server.php
# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\xampp\htdocs\wordtrunk\wp-includes # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process.
1 1 <?php 2 2 3 /** 3 4 * XML-RPC protocol support for WordPress 4 5 * … … 35 36 function __construct() { 36 37 $this->methods = array( 37 38 // WordPress API 38 'wp.getUsersBlogs'=> 'this:wp_getUsersBlogs',39 'wp.getPage'=> 'this:wp_getPage',40 'wp.getPages'=> 'this:wp_getPages',41 'wp.newPage'=> 'this:wp_newPage',42 'wp.deletePage'=> 'this:wp_deletePage',43 'wp.editPage'=> 'this:wp_editPage',44 'wp.getPageList'=> 'this:wp_getPageList',45 'wp.getAuthors'=> 'this:wp_getAuthors',46 'wp.getCategories' => 'this:mw_getCategories',// Alias47 'wp.getTags'=> 'this:wp_getTags',48 'wp.newCategory'=> 'this:wp_newCategory',49 'wp.deleteCategory'=> 'this:wp_deleteCategory',50 'wp.suggestCategories'=> 'this:wp_suggestCategories',51 'wp.uploadFile' => 'this:mw_newMediaObject',// Alias52 'wp.getCommentCount'=> 'this:wp_getCommentCount',53 'wp.getPostStatusList'=> 'this:wp_getPostStatusList',54 'wp.getPageStatusList'=> 'this:wp_getPageStatusList',55 'wp.getPageTemplates'=> 'this:wp_getPageTemplates',56 'wp.getOptions'=> 'this:wp_getOptions',57 'wp.setOptions'=> 'this:wp_setOptions',58 'wp.getComment'=> 'this:wp_getComment',59 'wp.getComments'=> 'this:wp_getComments',60 'wp.deleteComment'=> 'this:wp_deleteComment',61 'wp.editComment'=> 'this:wp_editComment',62 'wp.newComment'=> 'this:wp_newComment',39 'wp.getUsersBlogs' => 'this:wp_getUsersBlogs', 40 'wp.getPage' => 'this:wp_getPage', 41 'wp.getPages' => 'this:wp_getPages', 42 'wp.newPage' => 'this:wp_newPage', 43 'wp.deletePage' => 'this:wp_deletePage', 44 'wp.editPage' => 'this:wp_editPage', 45 'wp.getPageList' => 'this:wp_getPageList', 46 'wp.getAuthors' => 'this:wp_getAuthors', 47 'wp.getCategories' => 'this:mw_getCategories', // Alias 48 'wp.getTags' => 'this:wp_getTags', 49 'wp.newCategory' => 'this:wp_newCategory', 50 'wp.deleteCategory' => 'this:wp_deleteCategory', 51 'wp.suggestCategories' => 'this:wp_suggestCategories', 52 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias 53 'wp.getCommentCount' => 'this:wp_getCommentCount', 54 'wp.getPostStatusList' => 'this:wp_getPostStatusList', 55 'wp.getPageStatusList' => 'this:wp_getPageStatusList', 56 'wp.getPageTemplates' => 'this:wp_getPageTemplates', 57 'wp.getOptions' => 'this:wp_getOptions', 58 'wp.setOptions' => 'this:wp_setOptions', 59 'wp.getComment' => 'this:wp_getComment', 60 'wp.getComments' => 'this:wp_getComments', 61 'wp.deleteComment' => 'this:wp_deleteComment', 62 'wp.editComment' => 'this:wp_editComment', 63 'wp.newComment' => 'this:wp_newComment', 63 64 'wp.getCommentStatusList' => 'this:wp_getCommentStatusList', 64 'wp.getMediaItem'=> 'this:wp_getMediaItem',65 'wp.getMediaLibrary'=> 'this:wp_getMediaLibrary',66 'wp.getPostFormats'=> 'this:wp_getPostFormats',67 65 'wp.getMediaItem' => 'this:wp_getMediaItem', 66 'wp.getMediaLibrary' => 'this:wp_getMediaLibrary', 67 'wp.getPostFormats' => 'this:wp_getPostFormats', 68 'wp.deleteUser' => 'this:wp_deleteUser', 68 69 // Blogger API 69 70 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', 70 71 'blogger.getUserInfo' => 'this:blogger_getUserInfo', … … 75 76 'blogger.newPost' => 'this:blogger_newPost', 76 77 'blogger.editPost' => 'this:blogger_editPost', 77 78 'blogger.deletePost' => 'this:blogger_deletePost', 78 79 79 // MetaWeblog API (with MT extensions to structs) 80 80 'metaWeblog.newPost' => 'this:mw_newPost', 81 81 'metaWeblog.editPost' => 'this:mw_editPost', … … 83 83 'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts', 84 84 'metaWeblog.getCategories' => 'this:mw_getCategories', 85 85 'metaWeblog.newMediaObject' => 'this:mw_newMediaObject', 86 87 86 // MetaWeblog API aliases for Blogger API 88 87 // see http://www.xmlrpc.com/stories/storyReader$2460 89 88 'metaWeblog.deletePost' => 'this:blogger_deletePost', 90 89 'metaWeblog.getTemplate' => 'this:blogger_getTemplate', 91 90 'metaWeblog.setTemplate' => 'this:blogger_setTemplate', 92 91 'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', 93 94 92 // MovableType API 95 93 'mt.getCategoryList' => 'this:mt_getCategoryList', 96 94 'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles', … … 100 98 'mt.supportedTextFilters' => 'this:mt_supportedTextFilters', 101 99 'mt.getTrackbackPings' => 'this:mt_getTrackbackPings', 102 100 'mt.publishPost' => 'this:mt_publishPost', 103 104 101 // PingBack 105 102 'pingback.ping' => 'this:pingback_ping', 106 103 'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks', 107 108 104 'demo.sayHello' => 'this:sayHello', 109 105 'demo.addTwoNumbers' => 'this:addTwoNumbers' 110 106 ); 111 107 112 $this->initialise_blog_option_info();108 $this->initialise_blog_option_info(); 113 109 $this->methods = apply_filters('xmlrpc_methods', $this->methods); 114 110 } 115 111 … … 155 151 * @see wp_xmlrpc_server::login 156 152 */ 157 153 function login_pass_ok($user_login, $user_pass) { 158 if ( !get_option( 'enable_xmlrpc' )) {159 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site. An admin user can enable them at %s'), admin_url('options-writing.php') ));154 if (!get_option('enable_xmlrpc')) { 155 $this->error = new IXR_Error(405, sprintf(__('XML-RPC services are disabled on this site. An admin user can enable them at %s'), admin_url('options-writing.php'))); 160 156 return false; 161 157 } 162 158 … … 177 173 * @return mixed WP_User object if authentication passed, false otherwise 178 174 */ 179 175 function login($username, $password) { 180 if ( !get_option( 'enable_xmlrpc' )) {181 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site. An admin user can enable them at %s'), admin_url('options-writing.php') ));176 if (!get_option('enable_xmlrpc')) { 177 $this->error = new IXR_Error(405, sprintf(__('XML-RPC services are disabled on this site. An admin user can enable them at %s'), admin_url('options-writing.php'))); 182 178 return false; 183 179 } 184 180 … … 189 185 return false; 190 186 } 191 187 192 wp_set_current_user( $user->ID);188 wp_set_current_user($user->ID); 193 189 return $user; 194 190 } 195 191 … … 207 203 if (!is_array($array)) { 208 204 return($wpdb->escape($array)); 209 205 } else { 210 foreach ( (array) $array as $k => $v) {211 if ( is_array($v)) {206 foreach ((array) $array as $k => $v) { 207 if (is_array($v)) { 212 208 $this->escape($array[$k]); 213 } else if ( is_object($v)) {209 } else if (is_object($v)) { 214 210 //skip 215 211 } else { 216 212 $array[$k] = $wpdb->escape($v); … … 232 228 233 229 $custom_fields = array(); 234 230 235 foreach ( (array) has_meta($post_id) as $meta) {231 foreach ((array) has_meta($post_id) as $meta) { 236 232 // Don't expose protected fields. 237 if ( ! current_user_can( 'edit_post_meta', $post_id , $meta['meta_key'] ))233 if (!current_user_can('edit_post_meta', $post_id, $meta['meta_key'])) 238 234 continue; 239 235 240 236 $custom_fields[] = array( 241 "id"=> $meta['meta_id'],242 "key"=> $meta['meta_key'],237 "id" => $meta['meta_id'], 238 "key" => $meta['meta_key'], 243 239 "value" => $meta['meta_value'] 244 240 ); 245 241 } … … 258 254 function set_custom_fields($post_id, $fields) { 259 255 $post_id = (int) $post_id; 260 256 261 foreach ( (array) $fields as $meta) {262 if ( isset($meta['id'])) {257 foreach ((array) $fields as $meta) { 258 if (isset($meta['id'])) { 263 259 $meta['id'] = (int) $meta['id']; 264 $pmeta = get_metadata_by_mid( 'post', $meta['id']);265 $meta['value'] = stripslashes_deep( $meta['value']);266 if ( isset($meta['key'])) {267 $meta['key'] = stripslashes( $meta['key']);268 if ( $meta['key'] != $pmeta->meta_key)260 $pmeta = get_metadata_by_mid('post', $meta['id']); 261 $meta['value'] = stripslashes_deep($meta['value']); 262 if (isset($meta['key'])) { 263 $meta['key'] = stripslashes($meta['key']); 264 if ($meta['key'] != $pmeta->meta_key) 269 265 continue; 270 if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ))271 update_metadata_by_mid( 'post', $meta['id'], $meta['value']);272 } elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta->meta_key )) {273 delete_metadata_by_mid( 'post', $meta['id']);266 if (current_user_can('edit_post_meta', $post_id, $meta['key'])) 267 update_metadata_by_mid('post', $meta['id'], $meta['value']); 268 } elseif (current_user_can('delete_post_meta', $post_id, $pmeta->meta_key)) { 269 delete_metadata_by_mid('post', $meta['id']); 274 270 } 275 } elseif ( current_user_can( 'add_post_meta', $post_id, stripslashes( $meta['key'] ) )) {276 add_post_meta( $post_id, $meta['key'], $meta['value']);271 } elseif (current_user_can('add_post_meta', $post_id, stripslashes($meta['key']))) { 272 add_post_meta($post_id, $meta['key'], $meta['value']); 277 273 } 278 274 } 279 275 } … … 285 281 * 286 282 * @since 2.6.0 287 283 */ 288 function initialise_blog_option_info() {284 function initialise_blog_option_info() { 289 285 global $wp_version; 290 286 291 287 $this->blog_options = array( 292 288 // Read only options 293 'software_name'=> array(294 'desc' => __( 'Software Name'),295 'readonly'=> true,296 'value'=> 'WordPress'289 'software_name' => array( 290 'desc' => __('Software Name'), 291 'readonly' => true, 292 'value' => 'WordPress' 297 293 ), 298 'software_version'=> array(299 'desc' => __( 'Software Version'),300 'readonly'=> true,301 'value'=> $wp_version294 'software_version' => array( 295 'desc' => __('Software Version'), 296 'readonly' => true, 297 'value' => $wp_version 302 298 ), 303 'blog_url'=> array(304 'desc' => __( 'Site URL'),305 'readonly'=> true,306 'option'=> 'siteurl'299 'blog_url' => array( 300 'desc' => __('Site URL'), 301 'readonly' => true, 302 'option' => 'siteurl' 307 303 ), 308 309 304 // Updatable options 310 'time_zone'=> array(311 'desc' => __( 'Time Zone'),312 'readonly'=> false,313 'option'=> 'gmt_offset'305 'time_zone' => array( 306 'desc' => __('Time Zone'), 307 'readonly' => false, 308 'option' => 'gmt_offset' 314 309 ), 315 'blog_title'=> array(316 'desc' => __( 'Site Title'),317 'readonly'=> false,318 'option'=> 'blogname'310 'blog_title' => array( 311 'desc' => __('Site Title'), 312 'readonly' => false, 313 'option' => 'blogname' 319 314 ), 320 'blog_tagline'=> array(321 'desc' => __( 'Site Tagline'),322 'readonly'=> false,323 'option'=> 'blogdescription'315 'blog_tagline' => array( 316 'desc' => __('Site Tagline'), 317 'readonly' => false, 318 'option' => 'blogdescription' 324 319 ), 325 'date_format'=> array(326 'desc' => __( 'Date Format'),327 'readonly'=> false,328 'option'=> 'date_format'320 'date_format' => array( 321 'desc' => __('Date Format'), 322 'readonly' => false, 323 'option' => 'date_format' 329 324 ), 330 'time_format'=> array(331 'desc' => __( 'Time Format'),332 'readonly'=> false,333 'option'=> 'time_format'325 'time_format' => array( 326 'desc' => __('Time Format'), 327 'readonly' => false, 328 'option' => 'time_format' 334 329 ), 335 'users_can_register'=> array(336 'desc' => __( 'Allow new users to sign up'),337 'readonly'=> false,338 'option'=> 'users_can_register'330 'users_can_register' => array( 331 'desc' => __('Allow new users to sign up'), 332 'readonly' => false, 333 'option' => 'users_can_register' 339 334 ), 340 'thumbnail_size_w'=> array(341 'desc' => __( 'Thumbnail Width'),342 'readonly'=> false,343 'option'=> 'thumbnail_size_w'335 'thumbnail_size_w' => array( 336 'desc' => __('Thumbnail Width'), 337 'readonly' => false, 338 'option' => 'thumbnail_size_w' 344 339 ), 345 'thumbnail_size_h'=> array(346 'desc' => __( 'Thumbnail Height'),347 'readonly'=> false,348 'option'=> 'thumbnail_size_h'340 'thumbnail_size_h' => array( 341 'desc' => __('Thumbnail Height'), 342 'readonly' => false, 343 'option' => 'thumbnail_size_h' 349 344 ), 350 'thumbnail_crop'=> array(351 'desc' => __( 'Crop thumbnail to exact dimensions'),352 'readonly'=> false,353 'option'=> 'thumbnail_crop'345 'thumbnail_crop' => array( 346 'desc' => __('Crop thumbnail to exact dimensions'), 347 'readonly' => false, 348 'option' => 'thumbnail_crop' 354 349 ), 355 'medium_size_w'=> array(356 'desc' => __( 'Medium size image width'),357 'readonly'=> false,358 'option'=> 'medium_size_w'350 'medium_size_w' => array( 351 'desc' => __('Medium size image width'), 352 'readonly' => false, 353 'option' => 'medium_size_w' 359 354 ), 360 'medium_size_h'=> array(361 'desc' => __( 'Medium size image height'),362 'readonly'=> false,363 'option'=> 'medium_size_h'355 'medium_size_h' => array( 356 'desc' => __('Medium size image height'), 357 'readonly' => false, 358 'option' => 'medium_size_h' 364 359 ), 365 'large_size_w'=> array(366 'desc' => __( 'Large size image width'),367 'readonly'=> false,368 'option'=> 'large_size_w'360 'large_size_w' => array( 361 'desc' => __('Large size image width'), 362 'readonly' => false, 363 'option' => 'large_size_w' 369 364 ), 370 'large_size_h'=> array(371 'desc' => __( 'Large size image height'),372 'readonly'=> false,373 'option'=> 'large_size_h'365 'large_size_h' => array( 366 'desc' => __('Large size image height'), 367 'readonly' => false, 368 'option' => 'large_size_h' 374 369 ) 375 370 ); 376 371 377 $this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options);372 $this->blog_options = apply_filters('xmlrpc_blog_options', $this->blog_options); 378 373 } 379 374 380 375 /** … … 392 387 * - 'blogName' 393 388 * - 'xmlrpc' - url of xmlrpc endpoint 394 389 */ 395 function wp_getUsersBlogs( $args) {390 function wp_getUsersBlogs($args) { 396 391 global $current_site; 397 392 // If this isn't on WPMU then just use blogger_getUsersBlogs 398 if ( !is_multisite()) {399 array_unshift( $args, 1);400 return $this->blogger_getUsersBlogs( $args);393 if (!is_multisite()) { 394 array_unshift($args, 1); 395 return $this->blogger_getUsersBlogs($args); 401 396 } 402 397 403 $this->escape( $args);398 $this->escape($args); 404 399 405 400 $username = $args[0]; 406 401 $password = $args[1]; 407 402 408 if ( !$user = $this->login($username, $password))403 if (!$user = $this->login($username, $password)) 409 404 return $this->error; 410 405 411 406 412 do_action( 'xmlrpc_call', 'wp.getUsersBlogs');407 do_action('xmlrpc_call', 'wp.getUsersBlogs'); 413 408 414 $blogs = (array) get_blogs_of_user( $user->ID);415 $struct = array();409 $blogs = (array) get_blogs_of_user($user->ID); 410 $struct = array(); 416 411 417 foreach ( $blogs as $blog) {412 foreach ($blogs as $blog) { 418 413 // Don't include blogs that aren't hosted at this site 419 if ( $blog->site_id != $current_site->id)414 if ($blog->site_id != $current_site->id) 420 415 continue; 421 416 422 417 $blog_id = $blog->userblog_id; … … 424 419 $is_admin = current_user_can('manage_options'); 425 420 426 421 $struct[] = array( 427 'isAdmin'=> $is_admin,428 'url' => get_option( 'home') . '/',429 'blogid'=> (string) $blog_id,430 'blogName' => get_option( 'blogname'),431 'xmlrpc' => site_url( 'xmlrpc.php')422 'isAdmin' => $is_admin, 423 'url' => get_option('home') . '/', 424 'blogid' => (string) $blog_id, 425 'blogName' => get_option('blogname'), 426 'xmlrpc' => site_url('xmlrpc.php') 432 427 ); 433 428 434 restore_current_blog();429 restore_current_blog(); 435 430 } 436 431 437 432 return $struct; … … 452 447 function wp_getPage($args) { 453 448 $this->escape($args); 454 449 455 $blog_id= (int) $args[0];456 $page_id= (int) $args[1];457 $username= $args[2];458 $password= $args[3];450 $blog_id = (int) $args[0]; 451 $page_id = (int) $args[1]; 452 $username = $args[2]; 453 $password = $args[3]; 459 454 460 if ( !$user = $this->login($username, $password)) {455 if (!$user = $this->login($username, $password)) { 461 456 return $this->error; 462 457 } 463 458 464 if ( !current_user_can( 'edit_page', $page_id ))465 return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ));459 if (!current_user_can('edit_page', $page_id)) 460 return new IXR_Error(401, __('Sorry, you cannot edit this page.')); 466 461 467 462 do_action('xmlrpc_call', 'wp.getPage'); 468 463 … … 470 465 $page = get_page($page_id); 471 466 472 467 // If we found the page then format the data. 473 if ( $page->ID && ($page->post_type == 'page')) {468 if ($page->ID && ($page->post_type == 'page')) { 474 469 // Get all of the page content and link. 475 470 $full_page = get_extended($page->post_content); 476 471 $link = post_permalink($page->ID); 477 472 478 473 // Get info the page parent if there is one. 479 474 $parent_title = ""; 480 if ( !empty($page->post_parent)) {475 if (!empty($page->post_parent)) { 481 476 $parent = get_page($page->post_parent); 482 477 $parent_title = $parent->post_title; 483 478 } … … 491 486 $page_date_gmt = mysql2date('Ymd\TH:i:s', $page->post_date_gmt, false); 492 487 493 488 // For drafts use the GMT version of the date 494 if ( $page->post_status == 'draft')495 $page_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page->post_date ), 'Ymd\TH:i:s');489 if ($page->post_status == 'draft') 490 $page_date_gmt = get_gmt_from_date(mysql2date('Y-m-d H:i:s', $page->post_date), 'Ymd\TH:i:s'); 496 491 497 492 // Pull the categories info together. 498 493 $categories = array(); 499 foreach ( wp_get_post_categories($page->ID) as $cat_id) {494 foreach (wp_get_post_categories($page->ID) as $cat_id) { 500 495 $categories[] = get_cat_name($cat_id); 501 496 } 502 497 503 498 // Get the author info. 504 499 $author = get_userdata($page->post_author); 505 500 506 $page_template = get_post_meta( $page->ID, '_wp_page_template', true);507 if ( empty( $page_template ))501 $page_template = get_post_meta($page->ID, '_wp_page_template', true); 502 if (empty($page_template)) 508 503 $page_template = 'default'; 509 504 510 505 $page_struct = array( 511 'dateCreated'=> new IXR_Date($page_date),512 'userid'=> $page->post_author,513 'page_id'=> $page->ID,514 'page_status'=> $page->post_status,515 'description'=> $full_page['main'],516 'title'=> $page->post_title,517 'link'=> $link,518 'permaLink'=> $link,519 'categories'=> $categories,520 'excerpt'=> $page->post_excerpt,521 'text_more'=> $full_page['extended'],522 'mt_allow_comments'=> $allow_comments,523 'mt_allow_pings'=> $allow_pings,524 'wp_slug'=> $page->post_name,525 'wp_password'=> $page->post_password,526 'wp_author'=> $author->display_name,527 'wp_page_parent_id'=> $page->post_parent,528 'wp_page_parent_title'=> $parent_title,529 'wp_page_order'=> $page->menu_order,530 'wp_author_id'=> (string) $author->ID,531 'wp_author_display_name'=> $author->display_name,532 'date_created_gmt'=> new IXR_Date($page_date_gmt),533 'custom_fields'=> $this->get_custom_fields($page_id),534 'wp_page_template'=> $page_template506 'dateCreated' => new IXR_Date($page_date), 507 'userid' => $page->post_author, 508 'page_id' => $page->ID, 509 'page_status' => $page->post_status, 510 'description' => $full_page['main'], 511 'title' => $page->post_title, 512 'link' => $link, 513 'permaLink' => $link, 514 'categories' => $categories, 515 'excerpt' => $page->post_excerpt, 516 'text_more' => $full_page['extended'], 517 'mt_allow_comments' => $allow_comments, 518 'mt_allow_pings' => $allow_pings, 519 'wp_slug' => $page->post_name, 520 'wp_password' => $page->post_password, 521 'wp_author' => $author->display_name, 522 'wp_page_parent_id' => $page->post_parent, 523 'wp_page_parent_title' => $parent_title, 524 'wp_page_order' => $page->menu_order, 525 'wp_author_id' => (string) $author->ID, 526 'wp_author_display_name' => $author->display_name, 527 'date_created_gmt' => new IXR_Date($page_date_gmt), 528 'custom_fields' => $this->get_custom_fields($page_id), 529 'wp_page_template' => $page_template 535 530 ); 536 531 537 532 return($page_struct); … … 557 552 function wp_getPages($args) { 558 553 $this->escape($args); 559 554 560 $blog_id= (int) $args[0];561 $username= $args[1];562 $password= $args[2];563 $num_pages= isset($args[3]) ? (int) $args[3] : 10;555 $blog_id = (int) $args[0]; 556 $username = $args[1]; 557 $password = $args[2]; 558 $num_pages = isset($args[3]) ? (int) $args[3] : 10; 564 559 565 if ( !$user = $this->login($username, $password))560 if (!$user = $this->login($username, $password)) 566 561 return $this->error; 567 562 568 if ( !current_user_can( 'edit_pages' ))569 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ));563 if (!current_user_can('edit_pages')) 564 return new IXR_Error(401, __('Sorry, you cannot edit pages.')); 570 565 571 566 do_action('xmlrpc_call', 'wp.getPages'); 572 567 573 $pages = get_posts( array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages));568 $pages = get_posts(array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages)); 574 569 $num_pages = count($pages); 575 570 576 571 // If we have pages, put together their info. 577 if ( $num_pages >= 1) {572 if ($num_pages >= 1) { 578 573 $pages_struct = array(); 579 574 580 for ( $i = 0; $i < $num_pages; $i++) {575 for ($i = 0; $i < $num_pages; $i++) { 581 576 $page = wp_xmlrpc_server::wp_getPage(array( 582 577 $blog_id, $pages[$i]->ID, $username, $password 583 578 )); … … 602 597 */ 603 598 function wp_newPage($args) { 604 599 // Items not escaped here will be escaped in newPost. 605 $username= $this->escape($args[1]);606 $password= $this->escape($args[2]);607 $page= $args[3];608 $publish= $args[4];600 $username = $this->escape($args[1]); 601 $password = $this->escape($args[2]); 602 $page = $args[3]; 603 $publish = $args[4]; 609 604 610 if ( !$user = $this->login($username, $password))605 if (!$user = $this->login($username, $password)) 611 606 return $this->error; 612 607 613 608 do_action('xmlrpc_call', 'wp.newPage'); 614 609 615 610 // Make sure the user is allowed to add new pages. 616 if ( !current_user_can('publish_pages'))611 if (!current_user_can('publish_pages')) 617 612 return(new IXR_Error(401, __('Sorry, you cannot add new pages.'))); 618 613 619 614 // Mark this as content for a page. … … 634 629 function wp_deletePage($args) { 635 630 $this->escape($args); 636 631 637 $blog_id= (int) $args[0];638 $username= $args[1];639 $password= $args[2];640 $page_id= (int) $args[3];632 $blog_id = (int) $args[0]; 633 $username = $args[1]; 634 $password = $args[2]; 635 $page_id = (int) $args[3]; 641 636 642 if ( !$user = $this->login($username, $password))637 if (!$user = $this->login($username, $password)) 643 638 return $this->error; 644 639 645 640 do_action('xmlrpc_call', 'wp.deletePage'); … … 647 642 // Get the current page based on the page_id and 648 643 // make sure it is a page and not a post. 649 644 $actual_page = wp_get_single_post($page_id, ARRAY_A); 650 if ( !$actual_page || ($actual_page['post_type'] != 'page'))645 if (!$actual_page || ($actual_page['post_type'] != 'page')) 651 646 return(new IXR_Error(404, __('Sorry, no such page.'))); 652 647 653 648 // Make sure the user can delete pages. 654 if ( !current_user_can('delete_page', $page_id))649 if (!current_user_can('delete_page', $page_id)) 655 650 return(new IXR_Error(401, __('Sorry, you do not have the right to delete this page.'))); 656 651 657 652 // Attempt to delete the page. 658 653 $result = wp_delete_post($page_id); 659 if ( !$result)654 if (!$result) 660 655 return(new IXR_Error(500, __('Failed to delete the page.'))); 661 656 662 657 return(true); … … 672 667 */ 673 668 function wp_editPage($args) { 674 669 // Items not escaped here will be escaped in editPost. 675 $blog_id= (int) $args[0];676 $page_id= (int) $this->escape($args[1]);677 $username= $this->escape($args[2]);678 $password= $this->escape($args[3]);679 $content= $args[4];680 $publish= $args[5];670 $blog_id = (int) $args[0]; 671 $page_id = (int) $this->escape($args[1]); 672 $username = $this->escape($args[2]); 673 $password = $this->escape($args[3]); 674 $content = $args[4]; 675 $publish = $args[5]; 681 676 682 if ( !$user = $this->login($username, $password))677 if (!$user = $this->login($username, $password)) 683 678 return $this->error; 684 679 685 680 do_action('xmlrpc_call', 'wp.editPage'); 686 681 687 682 // Get the page data and make sure it is a page. 688 683 $actual_page = wp_get_single_post($page_id, ARRAY_A); 689 if ( !$actual_page || ($actual_page['post_type'] != 'page'))684 if (!$actual_page || ($actual_page['post_type'] != 'page')) 690 685 return(new IXR_Error(404, __('Sorry, no such page.'))); 691 686 692 687 // Make sure the user is allowed to edit pages. 693 if ( !current_user_can('edit_page', $page_id))688 if (!current_user_can('edit_page', $page_id)) 694 689 return(new IXR_Error(401, __('Sorry, you do not have the right to edit this page.'))); 695 690 696 691 // Mark this as content for a page. … … 722 717 723 718 $this->escape($args); 724 719 725 $blog_id= (int) $args[0];726 $username= $args[1];727 $password= $args[2];720 $blog_id = (int) $args[0]; 721 $username = $args[1]; 722 $password = $args[2]; 728 723 729 if ( !$user = $this->login($username, $password))724 if (!$user = $this->login($username, $password)) 730 725 return $this->error; 731 726 732 if ( !current_user_can( 'edit_pages' ))733 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ));727 if (!current_user_can('edit_pages')) 728 return new IXR_Error(401, __('Sorry, you cannot edit pages.')); 734 729 735 730 do_action('xmlrpc_call', 'wp.getPageList'); 736 731 … … 749 744 750 745 // The date needs to be formatted properly. 751 746 $num_pages = count($page_list); 752 for ( $i = 0; $i < $num_pages; $i++) {747 for ($i = 0; $i < $num_pages; $i++) { 753 748 $post_date = mysql2date('Ymd\TH:i:s', $page_list[$i]->post_date, false); 754 749 $post_date_gmt = mysql2date('Ymd\TH:i:s', $page_list[$i]->post_date_gmt, false); 755 750 … … 757 752 $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt); 758 753 759 754 // For drafts use the GMT version of the date 760 if ( $page_list[$i]->post_status == 'draft') {761 $page_list[$i]->date_created_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page_list[$i]->post_date ), 'Ymd\TH:i:s');762 $page_list[$i]->date_created_gmt = new IXR_Date( $page_list[$i]->date_created_gmt);755 if ($page_list[$i]->post_status == 'draft') { 756 $page_list[$i]->date_created_gmt = get_gmt_from_date(mysql2date('Y-m-d H:i:s', $page_list[$i]->post_date), 'Ymd\TH:i:s'); 757 $page_list[$i]->date_created_gmt = new IXR_Date($page_list[$i]->date_created_gmt); 763 758 } 764 759 765 760 unset($page_list[$i]->post_date_gmt); … … 782 777 783 778 $this->escape($args); 784 779 785 $blog_id= (int) $args[0];786 $username= $args[1];787 $password= $args[2];780 $blog_id = (int) $args[0]; 781 $username = $args[1]; 782 $password = $args[2]; 788 783 789 if ( !$user = $this->login($username, $password))784 if (!$user = $this->login($username, $password)) 790 785 return $this->error; 791 786 792 if ( !current_user_can('edit_posts'))787 if (!current_user_can('edit_posts')) 793 788 return(new IXR_Error(401, __('Sorry, you cannot edit posts on this site.'))); 794 789 795 790 do_action('xmlrpc_call', 'wp.getAuthors'); 796 791 797 792 $authors = array(); 798 foreach ( get_users( array( 'fields' => array('ID','user_login','display_name') ) ) as $user) {793 foreach (get_users(array('fields' => array('ID', 'user_login', 'display_name'))) as $user) { 799 794 $authors[] = array( 800 'user_id'=> $user->ID,801 'user_login'=> $user->user_login,802 'display_name'=> $user->display_name795 'user_id' => $user->ID, 796 'user_login' => $user->user_login, 797 'display_name' => $user->display_name 803 798 ); 804 799 } 805 800 … … 814 809 * @param array $args Method parameters. 815 810 * @return array 816 811 */ 817 function wp_getTags( $args) {818 $this->escape( $args);812 function wp_getTags($args) { 813 $this->escape($args); 819 814 820 $blog_id= (int) $args[0];821 $username= $args[1];822 $password= $args[2];815 $blog_id = (int) $args[0]; 816 $username = $args[1]; 817 $password = $args[2]; 823 818 824 if ( !$user = $this->login($username, $password))819 if (!$user = $this->login($username, $password)) 825 820 return $this->error; 826 821 827 if ( !current_user_can( 'edit_posts' ))828 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ));822 if (!current_user_can('edit_posts')) 823 return new IXR_Error(401, __('Sorry, you must be able to edit posts on this site in order to view tags.')); 829 824 830 do_action( 'xmlrpc_call', 'wp.getKeywords');825 do_action('xmlrpc_call', 'wp.getKeywords'); 831 826 832 $tags = array();827 $tags = array(); 833 828 834 if ( $all_tags = get_tags()) {835 foreach( (array) $all_tags as $tag) {836 $struct['tag_id']= $tag->term_id;837 $struct['name']= $tag->name;838 $struct['count']= $tag->count;839 $struct['slug']= $tag->slug;840 $struct['html_url'] = esc_html( get_tag_link( $tag->term_id ));841 $struct['rss_url'] = esc_html( get_tag_feed_link( $tag->term_id ));829 if ($all_tags = get_tags()) { 830 foreach ((array) $all_tags as $tag) { 831 $struct['tag_id'] = $tag->term_id; 832 $struct['name'] = $tag->name; 833 $struct['count'] = $tag->count; 834 $struct['slug'] = $tag->slug; 835 $struct['html_url'] = esc_html(get_tag_link($tag->term_id)); 836 $struct['rss_url'] = esc_html(get_tag_feed_link($tag->term_id)); 842 837 843 838 $tags[] = $struct; 844 839 } … … 858 853 function wp_newCategory($args) { 859 854 $this->escape($args); 860 855 861 $blog_id= (int) $args[0];862 $username= $args[1];863 $password= $args[2];864 $category= $args[3];856 $blog_id = (int) $args[0]; 857 $username = $args[1]; 858 $password = $args[2]; 859 $category = $args[3]; 865 860 866 if ( !$user = $this->login($username, $password))861 if (!$user = $this->login($username, $password)) 867 862 return $this->error; 868 863 869 864 do_action('xmlrpc_call', 'wp.newCategory'); 870 865 871 866 // Make sure the user is allowed to add a category. 872 if ( !current_user_can('manage_categories'))867 if (!current_user_can('manage_categories')) 873 868 return(new IXR_Error(401, __('Sorry, you do not have the right to add a category.'))); 874 869 875 870 // If no slug was provided make it empty so that 876 871 // WordPress will generate one. 877 if ( empty($category['slug']))872 if (empty($category['slug'])) 878 873 $category['slug'] = ''; 879 874 880 875 // If no parent_id was provided make it empty 881 876 // so that it will be a top level page (no parent). 882 if ( !isset($category['parent_id']))877 if (!isset($category['parent_id'])) 883 878 $category['parent_id'] = ''; 884 879 885 880 // If no description was provided make it empty. 886 if ( empty($category["description"]))881 if (empty($category["description"])) 887 882 $category["description"] = ""; 888 883 889 884 $new_category = array( 890 'cat_name'=> $category['name'],891 'category_nicename'=> $category['slug'],892 'category_parent'=> $category['parent_id'],893 'category_description'=> $category['description']885 'cat_name' => $category['name'], 886 'category_nicename' => $category['slug'], 887 'category_parent' => $category['parent_id'], 888 'category_description' => $category['description'] 894 889 ); 895 890 896 891 $cat_id = wp_insert_category($new_category, true); 897 if ( is_wp_error( $cat_id )) {898 if ( 'term_exists' == $cat_id->get_error_code())892 if (is_wp_error($cat_id)) { 893 if ('term_exists' == $cat_id->get_error_code()) 899 894 return (int) $cat_id->get_error_data(); 900 895 else 901 896 return(new IXR_Error(500, __('Sorry, the new category failed.'))); 902 } elseif ( ! $cat_id) {897 } elseif (!$cat_id) { 903 898 return(new IXR_Error(500, __('Sorry, the new category failed.'))); 904 899 } 905 900 … … 917 912 function wp_deleteCategory($args) { 918 913 $this->escape($args); 919 914 920 $blog_id= (int) $args[0];921 $username= $args[1];922 $password= $args[2];923 $category_id= (int) $args[3];915 $blog_id = (int) $args[0]; 916 $username = $args[1]; 917 $password = $args[2]; 918 $category_id = (int) $args[3]; 924 919 925 if ( !$user = $this->login($username, $password))920 if (!$user = $this->login($username, $password)) 926 921 return $this->error; 927 922 928 923 do_action('xmlrpc_call', 'wp.deleteCategory'); 929 924 930 if ( !current_user_can('manage_categories'))931 return new IXR_Error( 401, __( 'Sorry, you do not have the right to delete a category.' ));925 if (!current_user_can('manage_categories')) 926 return new IXR_Error(401, __('Sorry, you do not have the right to delete a category.')); 932 927 933 return wp_delete_term( $category_id, 'category');928 return wp_delete_term($category_id, 'category'); 934 929 } 935 930 936 931 /** … … 944 939 function wp_suggestCategories($args) { 945 940 $this->escape($args); 946 941 947 $blog_id= (int) $args[0];948 $username= $args[1];949 $password= $args[2];950 $category= $args[3];951 $max_results= (int) $args[4];942 $blog_id = (int) $args[0]; 943 $username = $args[1]; 944 $password = $args[2]; 945 $category = $args[3]; 946 $max_results = (int) $args[4]; 952 947 953 if ( !$user = $this->login($username, $password))948 if (!$user = $this->login($username, $password)) 954 949 return $this->error; 955 950 956 if ( !current_user_can( 'edit_posts' ))957 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this site in order to view categories.' ));951 if (!current_user_can('edit_posts')) 952 return new IXR_Error(401, __('Sorry, you must be able to edit posts to this site in order to view categories.')); 958 953 959 954 do_action('xmlrpc_call', 'wp.suggestCategories'); 960 955 961 956 $category_suggestions = array(); 962 957 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category); 963 foreach ( (array) get_categories($args) as $cat) {958 foreach ((array) get_categories($args) as $cat) { 964 959 $category_suggestions[] = array( 965 'category_id'=> $cat->term_id,966 'category_name'=> $cat->name960 'category_id' => $cat->term_id, 961 'category_name' => $cat->name 967 962 ); 968 963 } 969 964 … … 981 976 function wp_getComment($args) { 982 977 $this->escape($args); 983 978 984 $blog_id= (int) $args[0];985 $username= $args[1];986 $password= $args[2];987 $comment_id= (int) $args[3];979 $blog_id = (int) $args[0]; 980 $username = $args[1]; 981 $password = $args[2]; 982 $comment_id = (int) $args[3]; 988 983 989 if ( !$user = $this->login($username, $password))984 if (!$user = $this->login($username, $password)) 990 985 return $this->error; 991 986 992 if ( !current_user_can( 'moderate_comments' ))993 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ));987 if (!current_user_can('moderate_comments')) 988 return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); 994 989 995 990 do_action('xmlrpc_call', 'wp.getComment'); 996 991 997 if ( ! $comment = get_comment($comment_id))998 return new IXR_Error( 404, __( 'Invalid comment ID.' ));992 if (!$comment = get_comment($comment_id)) 993 return new IXR_Error(404, __('Invalid comment ID.')); 999 994 1000 995 // Format page date. 1001 996 $comment_date = mysql2date('Ymd\TH:i:s', $comment->comment_date, false); 1002 997 $comment_date_gmt = mysql2date('Ymd\TH:i:s', $comment->comment_date_gmt, false); 1003 998 1004 if ( '0' == $comment->comment_approved)999 if ('0' == $comment->comment_approved) 1005 1000 $comment_status = 'hold'; 1006 else if ( 'spam' == $comment->comment_approved)1001 else if ('spam' == $comment->comment_approved) 1007 1002 $comment_status = 'spam'; 1008 else if ( '1' == $comment->comment_approved)1003 else if ('1' == $comment->comment_approved) 1009 1004 $comment_status = 'approve'; 1010 1005 else 1011 1006 $comment_status = $comment->comment_approved; … … 1013 1008 $link = get_comment_link($comment); 1014 1009 1015 1010 $comment_struct = array( 1016 'date_created_gmt'=> new IXR_Date($comment_date_gmt),1017 'user_id'=> $comment->user_id,1018 'comment_id'=> $comment->comment_ID,1019 'parent'=> $comment->comment_parent,1020 'status'=> $comment_status,1021 'content'=> $comment->comment_content,1022 'link'=> $link,1023 'post_id'=> $comment->comment_post_ID,1024 'post_title'=> get_the_title($comment->comment_post_ID),1025 'author'=> $comment->comment_author,1026 'author_url'=> $comment->comment_author_url,1027 'author_email'=> $comment->comment_author_email,1028 'author_ip'=> $comment->comment_author_IP,1029 'type'=> $comment->comment_type,1011 'date_created_gmt' => new IXR_Date($comment_date_gmt), 1012 'user_id' => $comment->user_id, 1013 'comment_id' => $comment->comment_ID, 1014 'parent' => $comment->comment_parent, 1015 'status' => $comment_status, 1016 'content' => $comment->comment_content, 1017 'link' => $link, 1018 'post_id' => $comment->comment_post_ID, 1019 'post_title' => get_the_title($comment->comment_post_ID), 1020 'author' => $comment->comment_author, 1021 'author_url' => $comment->comment_author_url, 1022 'author_email' => $comment->comment_author_email, 1023 'author_ip' => $comment->comment_author_IP, 1024 'type' => $comment->comment_type, 1030 1025 ); 1031 1026 1032 1027 return $comment_struct; … … 1055 1050 $raw_args = $args; 1056 1051 $this->escape($args); 1057 1052 1058 $blog_id= (int) $args[0];1059 $username= $args[1];1060 $password= $args[2];1061 $struct= $args[3];1053 $blog_id = (int) $args[0]; 1054 $username = $args[1]; 1055 $password = $args[2]; 1056 $struct = $args[3]; 1062 1057 1063 if ( !$user = $this->login($username, $password))1058 if (!$user = $this->login($username, $password)) 1064 1059 return $this->error; 1065 1060 1066 if ( !current_user_can( 'moderate_comments' ))1067 return new IXR_Error( 401, __( 'Sorry, you cannot edit comments.' ));1061 if (!current_user_can('moderate_comments')) 1062 return new IXR_Error(401, __('Sorry, you cannot edit comments.')); 1068 1063 1069 1064 do_action('xmlrpc_call', 'wp.getComments'); 1070 1065 1071 if ( isset($struct['status']))1066 if (isset($struct['status'])) 1072 1067 $status = $struct['status']; 1073 1068 else 1074 1069 $status = ''; 1075 1070 1076 1071 $post_id = ''; 1077 if ( isset($struct['post_id']))1072 if (isset($struct['post_id'])) 1078 1073 $post_id = absint($struct['post_id']); 1079 1074 1080 1075 $offset = 0; 1081 if ( isset($struct['offset']))1076 if (isset($struct['offset'])) 1082 1077 $offset = absint($struct['offset']); 1083 1078 1084 1079 $number = 10; 1085 if ( isset($struct['number']))1080 if (isset($struct['number'])) 1086 1081 $number = absint($struct['number']); 1087 1082 1088 $comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ));1083 $comments = get_comments(array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number)); 1089 1084 $num_comments = count($comments); 1090 1085 1091 if ( ! $num_comments)1086 if (!$num_comments) 1092 1087 return array(); 1093 1088 1094 1089 $comments_struct = array(); 1095 1090 1096 1091 // FIXME: we already have the comments, why query them again? 1097 for ( $i = 0; $i < $num_comments; $i++) {1092 for ($i = 0; $i < $num_comments; $i++) { 1098 1093 $comment = wp_xmlrpc_server::wp_getComment(array( 1099 1094 $raw_args[0], $raw_args[1], $raw_args[2], $comments[$i]->comment_ID, 1100 1095 )); … … 1123 1118 function wp_deleteComment($args) { 1124 1119 $this->escape($args); 1125 1120 1126 $blog_id= (int) $args[0];1127 $username= $args[1];1128 $password= $args[2];1129 $comment_ID= (int) $args[3];1121 $blog_id = (int) $args[0]; 1122 $username = $args[1]; 1123 $password = $args[2]; 1124 $comment_ID = (int) $args[3]; 1130 1125 1131 if ( !$user = $this->login($username, $password))1126 if (!$user = $this->login($username, $password)) 1132 1127 return $this->error; 1133 1128 1134 if ( !current_user_can( 'moderate_comments' ))1135 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ));1129 if (!current_user_can('moderate_comments')) 1130 return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); 1136 1131 1137 if ( ! get_comment($comment_ID))1138 return new IXR_Error( 404, __( 'Invalid comment ID.' ));1132 if (!get_comment($comment_ID)) 1133 return new IXR_Error(404, __('Invalid comment ID.')); 1139 1134 1140 if ( !current_user_can( 'edit_comment', $comment_ID ))1141 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ));1135 if (!current_user_can('edit_comment', $comment_ID)) 1136 return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); 1142 1137 1143 1138 do_action('xmlrpc_call', 'wp.deleteComment'); 1144 1139 … … 1172 1167 function wp_editComment($args) { 1173 1168 $this->escape($args); 1174 1169 1175 $blog_id= (int) $args[0];1176 $username= $args[1];1177 $password= $args[2];1178 $comment_ID= (int) $args[3];1170 $blog_id = (int) $args[0]; 1171 $username = $args[1]; 1172 $password = $args[2]; 1173 $comment_ID = (int) $args[3]; 1179 1174 $content_struct = $args[4]; 1180 1175 1181 if ( !$user = $this->login($username, $password))1176 if (!$user = $this->login($username, $password)) 1182 1177 return $this->error; 1183 1178 1184 if ( !current_user_can( 'moderate_comments' ))1185 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ));1179 if (!current_user_can('moderate_comments')) 1180 return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); 1186 1181 1187 if ( ! get_comment($comment_ID))1188 return new IXR_Error( 404, __( 'Invalid comment ID.' ));1182 if (!get_comment($comment_ID)) 1183 return new IXR_Error(404, __('Invalid comment ID.')); 1189 1184 1190 if ( !current_user_can( 'edit_comment', $comment_ID ))1191 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ));1185 if (!current_user_can('edit_comment', $comment_ID)) 1186 return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); 1192 1187 1193 1188 do_action('xmlrpc_call', 'wp.editComment'); 1194 1189 1195 if ( isset($content_struct['status'])) {1190 if (isset($content_struct['status'])) { 1196 1191 $statuses = get_comment_statuses(); 1197 1192 $statuses = array_keys($statuses); 1198 1193 1199 if ( ! in_array($content_struct['status'], $statuses))1200 return new IXR_Error( 401, __( 'Invalid comment status.' ));1194 if (!in_array($content_struct['status'], $statuses)) 1195 return new IXR_Error(401, __('Invalid comment status.')); 1201 1196 $comment_approved = $content_struct['status']; 1202 1197 } 1203 1198 1204 1199 // Do some timestamp voodoo 1205 if ( !empty( $content_struct['date_created_gmt'] )) {1206 $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso()) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force1200 if (!empty($content_struct['date_created_gmt'])) { 1201 $dateCreated = str_replace('Z', '', $content_struct['date_created_gmt']->getIso()) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force 1207 1202 $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 1208 1203 $comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); 1209 1204 } 1210 1205 1211 if ( isset($content_struct['content']))1206 if (isset($content_struct['content'])) 1212 1207 $comment_content = $content_struct['content']; 1213 1208 1214 if ( isset($content_struct['author']))1209 if (isset($content_struct['author'])) 1215 1210 $comment_author = $content_struct['author']; 1216 1211 1217 if ( isset($content_struct['author_url']))1212 if (isset($content_struct['author_url'])) 1218 1213 $comment_author_url = $content_struct['author_url']; 1219 1214 1220 if ( isset($content_struct['author_email']))1215 if (isset($content_struct['author_email'])) 1221 1216 $comment_author_email = $content_struct['author_email']; 1222 1217 1223 1218 // We've got all the data -- post it: 1224 1219 $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url'); 1225 1220 1226 1221 $result = wp_update_comment($comment); 1227 if ( is_wp_error( $result ))1222 if (is_wp_error($result)) 1228 1223 return new IXR_Error(500, $result->get_error_message()); 1229 1224 1230 if ( !$result)1225 if (!$result) 1231 1226 return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.')); 1232 1227 1233 1228 return true; … … 1246 1241 1247 1242 $this->escape($args); 1248 1243 1249 $blog_id= (int) $args[0];1250 $username= $args[1];1251 $password= $args[2];1252 $post= $args[3];1244 $blog_id = (int) $args[0]; 1245 $username = $args[1]; 1246 $password = $args[2]; 1247 $post = $args[3]; 1253 1248 $content_struct = $args[4]; 1254 1249 1255 1250 $allow_anon = apply_filters('xmlrpc_allow_anonymous_comments', false); 1256 1251 1257 1252 $user = $this->login($username, $password); 1258 1253 1259 if ( !$user) {1254 if (!$user) { 1260 1255 $logged_in = false; 1261 if ( $allow_anon && get_option('comment_registration'))1262 return new IXR_Error( 403, __( 'You must be registered to comment' ));1263 else if ( !$allow_anon)1256 if ($allow_anon && get_option('comment_registration')) 1257 return new IXR_Error(403, __('You must be registered to comment')); 1258 else if (!$allow_anon) 1264 1259 return $this->error; 1265 1260 } else { 1266 1261 $logged_in = true; 1267 1262 } 1268 1263 1269 if ( is_numeric($post))1264 if (is_numeric($post)) 1270 1265 $post_id = absint($post); 1271 1266 else 1272 1267 $post_id = url_to_postid($post); 1273 1268 1274 if ( ! $post_id)1275 return new IXR_Error( 404, __( 'Invalid post ID.' ));1269 if (!$post_id) 1270 return new IXR_Error(404, __('Invalid post ID.')); 1276 1271 1277 if ( ! get_post($post_id))1278 return new IXR_Error( 404, __( 'Invalid post ID.' ));1272 if (!get_post($post_id)) 1273 return new IXR_Error(404, __('Invalid post ID.')); 1279 1274 1280 1275 $comment['comment_post_ID'] = $post_id; 1281 1276 1282 if ( $logged_in) {1283 $comment['comment_author'] = $wpdb->escape( $user->display_name);1284 $comment['comment_author_email'] = $wpdb->escape( $user->user_email);1285 $comment['comment_author_url'] = $wpdb->escape( $user->user_url);1277 if ($logged_in) { 1278 $comment['comment_author'] = $wpdb->escape($user->display_name); 1279 $comment['comment_author_email'] = $wpdb->escape($user->user_email); 1280 $comment['comment_author_url'] = $wpdb->escape($user->user_url); 1286 1281 $comment['user_ID'] = $user->ID; 1287 1282 } else { 1288 1283 $comment['comment_author'] = ''; 1289 if ( isset($content_struct['author']))1284 if (isset($content_struct['author'])) 1290 1285 $comment['comment_author'] = $content_struct['author']; 1291 1286 1292 1287 $comment['comment_author_email'] = ''; 1293 if ( isset($content_struct['author_email']))1288 if (isset($content_struct['author_email'])) 1294 1289 $comment['comment_author_email'] = $content_struct['author_email']; 1295 1290 1296 1291 $comment['comment_author_url'] = ''; 1297 if ( isset($content_struct['author_url']))1292 if (isset($content_struct['author_url'])) 1298 1293 $comment['comment_author_url'] = $content_struct['author_url']; 1299 1294 1300 1295 $comment['user_ID'] = 0; 1301 1296 1302 if ( get_option('require_name_email')) {1303 if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'])1304 return new IXR_Error( 403, __( 'Comment author name and email are required' ));1305 elseif ( !is_email($comment['comment_author_email']))1306 return new IXR_Error( 403, __( 'A valid email address is required' ));1297 if (get_option('require_name_email')) { 1298 if (6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author']) 1299 return new IXR_Error(403, __('Comment author name and email are required')); 1300 elseif (!is_email($comment['comment_author_email'])) 1301 return new IXR_Error(403, __('A valid email address is required')); 1307 1302 } 1308 1303 } 1309 1304 1310 1305 $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0; 1311 1306 1312 $comment['comment_content'] =isset($content_struct['content']) ? $content_struct['content'] : null;1307 $comment['comment_content'] = isset($content_struct['content']) ? $content_struct['content'] : null; 1313 1308 1314 1309 do_action('xmlrpc_call', 'wp.newComment'); 1315 1310 … … 1325 1320 * @return array 1326 1321 */ 1327 1322 function wp_getCommentStatusList($args) { 1328 $this->escape( $args);1323 $this->escape($args); 1329 1324 1330 $blog_id= (int) $args[0];1331 $username= $args[1];1332 $password= $args[2];1325 $blog_id = (int) $args[0]; 1326 $username = $args[1]; 1327 $password = $args[2]; 1333 1328 1334 if ( !$user = $this->login($username, $password))1329 if (!$user = $this->login($username, $password)) 1335 1330 return $this->error; 1336 1331 1337 if ( !current_user_can( 'moderate_comments' ))1338 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ));1332 if (!current_user_can('moderate_comments')) 1333 return new IXR_Error(403, __('You are not allowed access to details about this site.')); 1339 1334 1340 1335 do_action('xmlrpc_call', 'wp.getCommentStatusList'); 1341 1336 1342 return get_comment_statuses();1337 return get_comment_statuses(); 1343 1338 } 1344 1339 1345 1340 /** … … 1350 1345 * @param array $args Method parameters. 1351 1346 * @return array 1352 1347 */ 1353 function wp_getCommentCount( $args) {1348 function wp_getCommentCount($args) { 1354 1349 $this->escape($args); 1355 1350 1356 $blog_id= (int) $args[0];1357 $username= $args[1];1358 $password= $args[2];1359 $post_id= (int) $args[3];1351 $blog_id = (int) $args[0]; 1352 $username = $args[1]; 1353 $password = $args[2]; 1354 $post_id = (int) $args[3]; 1360 1355 1361 if ( !$user = $this->login($username, $password))1356 if (!$user = $this->login($username, $password)) 1362 1357 return $this->error; 1363 1358 1364 if ( !current_user_can( 'edit_posts' ))1365 return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ));1359 if (!current_user_can('edit_posts')) 1360 return new IXR_Error(403, __('You are not allowed access to details about comments.')); 1366 1361 1367 1362 do_action('xmlrpc_call', 'wp.getCommentCount'); 1368 1363 1369 $count = wp_count_comments( $post_id);1364 $count = wp_count_comments($post_id); 1370 1365 return array( 1371 1366 'approved' => $count->approved, 1372 1367 'awaiting_moderation' => $count->moderated, … … 1383 1378 * @param array $args Method parameters. 1384 1379 * @return array 1385 1380 */ 1386 function wp_getPostStatusList( $args) {1387 $this->escape( $args);1381 function wp_getPostStatusList($args) { 1382 $this->escape($args); 1388 1383 1389 $blog_id= (int) $args[0];1390 $username= $args[1];1391 $password= $args[2];1384 $blog_id = (int) $args[0]; 1385 $username = $args[1]; 1386 $password = $args[2]; 1392 1387 1393 if ( !$user = $this->login($username, $password))1388 if (!$user = $this->login($username, $password)) 1394 1389 return $this->error; 1395 1390 1396 if ( !current_user_can( 'edit_posts' ))1397 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ));1391 if (!current_user_can('edit_posts')) 1392 return new IXR_Error(403, __('You are not allowed access to details about this site.')); 1398 1393 1399 1394 do_action('xmlrpc_call', 'wp.getPostStatusList'); 1400 1395 1401 return get_post_statuses();1396 return get_post_statuses(); 1402 1397 } 1403 1398 1404 1399 /** … … 1409 1404 * @param array $args Method parameters. 1410 1405 * @return array 1411 1406 */ 1412 function wp_getPageStatusList( $args) {1413 $this->escape( $args);1407 function wp_getPageStatusList($args) { 1408 $this->escape($args); 1414 1409 1415 $blog_id= (int) $args[0];1416 $username= $args[1];1417 $password= $args[2];1410 $blog_id = (int) $args[0]; 1411 $username = $args[1]; 1412 $password = $args[2]; 1418 1413 1419 if ( !$user = $this->login($username, $password))1414 if (!$user = $this->login($username, $password)) 1420 1415 return $this->error; 1421 1416 1422 if ( !current_user_can( 'edit_pages' ))1423 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ));1417 if (!current_user_can('edit_pages')) 1418 return new IXR_Error(403, __('You are not allowed access to details about this site.')); 1424 1419 1425 1420 do_action('xmlrpc_call', 'wp.getPageStatusList'); 1426 1421 1427 return get_page_statuses();1422 return get_page_statuses(); 1428 1423 } 1429 1424 1430 1425 /** … … 1435 1430 * @param array $args Method parameters. 1436 1431 * @return array 1437 1432 */ 1438 function wp_getPageTemplates( $args) {1439 $this->escape( $args);1433 function wp_getPageTemplates($args) { 1434 $this->escape($args); 1440 1435 1441 $blog_id= (int) $args[0];1442 $username= $args[1];1443 $password= $args[2];1436 $blog_id = (int) $args[0]; 1437 $username = $args[1]; 1438 $password = $args[2]; 1444 1439 1445 if ( !$user = $this->login($username, $password))1440 if (!$user = $this->login($username, $password)) 1446 1441 return $this->error; 1447 1442 1448 if ( !current_user_can( 'edit_pages' ))1449 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ));1443 if (!current_user_can('edit_pages')) 1444 return new IXR_Error(403, __('You are not allowed access to details about this site.')); 1450 1445 1451 $templates = get_page_templates();1446 $templates = get_page_templates(); 1452 1447 $templates['Default'] = 'default'; 1453 1448 1454 1449 return $templates; … … 1462 1457 * @param array $args Method parameters. 1463 1458 * @return array 1464 1459 */ 1465 function wp_getOptions( $args) {1466 $this->escape( $args);1460 function wp_getOptions($args) { 1461 $this->escape($args); 1467 1462 1468 $blog_id= (int) $args[0];1469 $username= $args[1];1470 $password= $args[2];1471 $options = isset( $args[3]) ? (array) $args[3] : array();1463 $blog_id = (int) $args[0]; 1464 $username = $args[1]; 1465 $password = $args[2]; 1466 $options = isset($args[3]) ? (array) $args[3] : array(); 1472 1467 1473 if ( !$user = $this->login($username, $password))1468 if (!$user = $this->login($username, $password)) 1474 1469 return $this->error; 1475 1470 1476 1471 // If no specific options where asked for, return all of them 1477 if ( count( $options ) == 0)1472 if (count($options) == 0) 1478 1473 $options = array_keys($this->blog_options); 1479 1474 1480 1475 return $this->_getOptions($options); … … 1489 1484 * @return array 1490 1485 */ 1491 1486 function _getOptions($options) { 1492 $data = array();1493 foreach ( $options as $option) {1494 if ( array_key_exists( $option, $this->blog_options )) {1487 $data = array(); 1488 foreach ($options as $option) { 1489 if (array_key_exists($option, $this->blog_options)) { 1495 1490 $data[$option] = $this->blog_options[$option]; 1496 1491 //Is the value static or dynamic? 1497 if ( isset( $data[$option]['option'] )) {1498 $data[$option]['value'] = get_option( $data[$option]['option']);1492 if (isset($data[$option]['option'])) { 1493 $data[$option]['value'] = get_option($data[$option]['option']); 1499 1494 unset($data[$option]['option']); 1500 1495 } 1501 1496 } … … 1512 1507 * @param array $args Method parameters. 1513 1508 * @return unknown 1514 1509 */ 1515 function wp_setOptions( $args) {1516 $this->escape( $args);1510 function wp_setOptions($args) { 1511 $this->escape($args); 1517 1512 1518 $blog_id= (int) $args[0];1519 $username= $args[1];1520 $password= $args[2];1521 $options= (array) $args[3];1513 $blog_id = (int) $args[0]; 1514 $username = $args[1]; 1515 $password = $args[2]; 1516 $options = (array) $args[3]; 1522 1517 1523 if ( !$user = $this->login($username, $password))1518 if (!$user = $this->login($username, $password)) 1524 1519 return $this->error; 1525 1520 1526 if ( !current_user_can( 'manage_options' ))1527 return new IXR_Error( 403, __( 'You are not allowed to update options.' ));1521 if (!current_user_can('manage_options')) 1522 return new IXR_Error(403, __('You are not allowed to update options.')); 1528 1523 1529 foreach ( $options as $o_name => $o_value) {1524 foreach ($options as $o_name => $o_value) { 1530 1525 $option_names[] = $o_name; 1531 if ( !array_key_exists( $o_name, $this->blog_options ))1526 if (!array_key_exists($o_name, $this->blog_options)) 1532 1527 continue; 1533 1528 1534 if ( $this->blog_options[$o_name]['readonly'] == true)1529 if ($this->blog_options[$o_name]['readonly'] == true) 1535 1530 continue; 1536 1531 1537 update_option( $this->blog_options[$o_name]['option'], $o_value);1532 update_option($this->blog_options[$o_name]['option'], $o_value); 1538 1533 } 1539 1534 1540 1535 //Now return the updated values … … 1564 1559 function wp_getMediaItem($args) { 1565 1560 $this->escape($args); 1566 1561 1567 $blog_id= (int) $args[0];1568 $username= $args[1];1569 $password= $args[2];1570 $attachment_id= (int) $args[3];1562 $blog_id = (int) $args[0]; 1563 $username = $args[1]; 1564 $password = $args[2]; 1565 $attachment_id = (int) $args[3]; 1571 1566 1572 if ( !$user = $this->login($username, $password))1567 if (!$user = $this->login($username, $password)) 1573 1568 return $this->error; 1574 1569 1575 if ( !current_user_can( 'upload_files' ))1576 return new IXR_Error( 403, __( 'You are not allowed to upload files to this site.' ));1570 if (!current_user_can('upload_files')) 1571 return new IXR_Error(403, __('You are not allowed to upload files to this site.')); 1577 1572 1578 1573 do_action('xmlrpc_call', 'wp.getMediaItem'); 1579 1574 1580 if ( ! $attachment = get_post($attachment_id))1581 return new IXR_Error( 404, __( 'Invalid attachment ID.' ));1575 if (!$attachment = get_post($attachment_id)) 1576 return new IXR_Error(404, __('Invalid attachment ID.')); 1582 1577 1583 1578 // Format page date. 1584 1579 $attachment_date = mysql2date('Ymd\TH:i:s', $attachment->post_date, false); … … 1588 1583 $thumbnail_link = wp_get_attachment_thumb_url($attachment->ID); 1589 1584 1590 1585 $attachment_struct = array( 1591 'date_created_gmt'=> new IXR_Date($attachment_date_gmt),1592 'parent'=> $attachment->post_parent,1593 'link'=> $link,1594 'thumbnail'=> $thumbnail_link,1595 'title'=> $attachment->post_title,1596 'caption'=> $attachment->post_excerpt,1597 'description'=> $attachment->post_content,1598 'metadata'=> wp_get_attachment_metadata($attachment->ID),1586 'date_created_gmt' => new IXR_Date($attachment_date_gmt), 1587 'parent' => $attachment->post_parent, 1588 'link' => $link, 1589 'thumbnail' => $thumbnail_link, 1590 'title' => $attachment->post_title, 1591 'caption' => $attachment->post_excerpt, 1592 'description' => $attachment->post_content, 1593 'metadata' => wp_get_attachment_metadata($attachment->ID), 1599 1594 ); 1600 1595 1601 1596 return $attachment_struct; … … 1628 1623 $raw_args = $args; 1629 1624 $this->escape($args); 1630 1625 1631 $blog_id= (int) $args[0];1632 $username= $args[1];1633 $password= $args[2];1634 $struct = isset( $args[3] ) ? $args[3] : array();1626 $blog_id = (int) $args[0]; 1627 $username = $args[1]; 1628 $password = $args[2]; 1629 $struct = isset($args[3]) ? $args[3] : array(); 1635 1630 1636 if ( !$user = $this->login($username, $password))1631 if (!$user = $this->login($username, $password)) 1637 1632 return $this->error; 1638 1633 1639 if ( !current_user_can( 'upload_files' ))1640 return new IXR_Error( 401, __( 'Sorry, you cannot upload files.' ));1634 if (!current_user_can('upload_files')) 1635 return new IXR_Error(401, __('Sorry, you cannot upload files.')); 1641 1636 1642 1637 do_action('xmlrpc_call', 'wp.getMediaLibrary'); 1643 1638 1644 $parent_id = ( isset($struct['parent_id']) ) ? absint($struct['parent_id']) : '';1645 $mime_type = ( isset($struct['mime_type']) ) ? $struct['mime_type'] : '';1646 $offset = ( isset($struct['offset']) ) ? absint($struct['offset']) : 0;1647 $number = ( isset($struct['number']) ) ? absint($struct['number']) : -1;1639 $parent_id = ( isset($struct['parent_id']) ) ? absint($struct['parent_id']) : ''; 1640 $mime_type = ( isset($struct['mime_type']) ) ? $struct['mime_type'] : ''; 1641 $offset = ( isset($struct['offset']) ) ? absint($struct['offset']) : 0; 1642 $number = ( isset($struct['number']) ) ? absint($struct['number']) : -1; 1648 1643 1649 $attachments = get_posts( array('post_type' => 'attachment', 'post_parent' => $parent_id, 'offset' => $offset, 'numberposts' => $number, 'post_mime_type' => $mime_type ));1644 $attachments = get_posts(array('post_type' => 'attachment', 'post_parent' => $parent_id, 'offset' => $offset, 'numberposts' => $number, 'post_mime_type' => $mime_type)); 1650 1645 $num_attachments = count($attachments); 1651 1646 1652 if ( ! $num_attachments)1647 if (!$num_attachments) 1653 1648 return array(); 1654 1649 1655 1650 $attachments_struct = array(); 1656 1651 1657 foreach ($attachments as $attachment)1658 $attachments_struct[] = $this->wp_getMediaItem( array( $raw_args[0], $raw_args[1], $raw_args[2], $attachment->ID ));1652 foreach ($attachments as $attachment) 1653 $attachments_struct[] = $this->wp_getMediaItem(array($raw_args[0], $raw_args[1], $raw_args[2], $attachment->ID)); 1659 1654 1660 1655 return $attachments_struct; 1661 1656 } … … 1671 1666 * - password 1672 1667 * @return array 1673 1668 */ 1674 function wp_getPostFormats( $args) {1675 $this->escape( $args);1669 function wp_getPostFormats($args) { 1670 $this->escape($args); 1676 1671 1677 1672 $blog_id = (int) $args[0]; 1678 1673 $username = $args[1]; 1679 1674 $password = $args[2]; 1680 1675 1681 if ( !$user = $this->login( $username, $password ))1676 if (!$user = $this->login($username, $password)) 1682 1677 return $this->error; 1683 1678 1684 do_action( 'xmlrpc_call', 'wp.getPostFormats');1679 do_action('xmlrpc_call', 'wp.getPostFormats'); 1685 1680 1686 1681 $formats = get_post_format_strings(); 1687 1682 1688 1683 # find out if they want a list of currently supports formats 1689 if ( isset( $args[3] ) && is_array( $args[3] )) {1690 if ( $args[3]['show-supported']) {1691 if ( current_theme_supports( 'post-formats' )) {1692 $supported = get_theme_support( 'post-formats');1684 if (isset($args[3]) && is_array($args[3])) { 1685 if ($args[3]['show-supported']) { 1686 if (current_theme_supports('post-formats')) { 1687 $supported = get_theme_support('post-formats'); 1693 1688 1694 1689 $data['all'] = $formats; 1695 1690 $data['supported'] = $supported[0]; … … 1702 1697 return $formats; 1703 1698 } 1704 1699 1700 /** 1701 * Delete a user 1702 * 1703 * @uses wp_delete_user() 1704 * @param array $args Method parameters. Contains: 1705 * - int $blog_id 1706 * - string $username 1707 * - string $password 1708 * - int $user_id 1709 * - int $reassign_id 1710 * @return True when user is deleted. 1711 */ 1712 function wp_deleteUser($args) { 1713 $this->escape($args); 1714 1715 $blog_id = (int) $args[0]; 1716 $username = $args[1]; 1717 $password = $args[2]; 1718 $user_id = (int) $args[3]; 1719 1720 if (!$user = $this->login($username, $password)) 1721 return $this->error; 1722 1723 do_action('xmlrpc_call', 'wp.deleteUser'); 1724 1725 if (!current_user_can('delete_users')) 1726 return new IXR_Error(401, __('You are not allowed to delete users.')); 1727 1728 if (!get_userdata($user_id)) 1729 return new IXR_Error(404, __('Invalid user ID.')); 1730 1731 if ($user->ID == $user_id) 1732 return new IXR_Error(401, __('You cannot delete yourself.')); 1733 1734 if (isset($args[4])) { 1735 $reassign_id = (int) $args[4]; 1736 if (!get_userdata($user_id)) 1737 return new IXR_Error(404, __('Invalid reassign user ID.')); 1738 if($reassign_id == $user_id) 1739 return new IXR_Error(404, __('Cannot reassign for a deleting user.')); 1740 } else { 1741 $reassign_id = 'novalue'; 1742 } 1743 1744 $result = wp_delete_user($user_id, $reassign_id); 1745 1746 if (!$result) 1747 return new IXR_Error(500, __('Cannot delete user.')); 1748 1749 return true; 1750 } 1751 1705 1752 /* Blogger API functions. 1706 1753 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/ 1707 1754 */ … … 1717 1764 * @return array 1718 1765 */ 1719 1766 function blogger_getUsersBlogs($args) { 1720 if ( is_multisite())1767 if (is_multisite()) 1721 1768 return $this->_multisite_getUsersBlogs($args); 1722 1769 1723 1770 $this->escape($args); 1724 1771 1725 1772 $username = $args[1]; 1726 $password= $args[2];1773 $password = $args[2]; 1727 1774 1728 if ( !$user = $this->login($username, $password))1775 if (!$user = $this->login($username, $password)) 1729 1776 return $this->error; 1730 1777 1731 1778 do_action('xmlrpc_call', 'blogger.getUsersBlogs'); … … 1733 1780 $is_admin = current_user_can('manage_options'); 1734 1781 1735 1782 $struct = array( 1736 'isAdmin'=> $is_admin,1737 'url'=> get_option('home') . '/',1738 'blogid'=> '1',1783 'isAdmin' => $is_admin, 1784 'url' => get_option('home') . '/', 1785 'blogid' => '1', 1739 1786 'blogName' => get_option('blogname'), 1740 'xmlrpc' => site_url( 'xmlrpc.php')1787 'xmlrpc' => site_url('xmlrpc.php') 1741 1788 ); 1742 1789 1743 1790 return array($struct); … … 1758 1805 $rpc->query('wp.getUsersBlogs', $args[1], $args[2]); 1759 1806 $blogs = $rpc->getResponse(); 1760 1807 1761 if ( isset($blogs['faultCode']))1808 if (isset($blogs['faultCode'])) 1762 1809 return new IXR_Error($blogs['faultCode'], $blogs['faultString']); 1763 1810 1764 if ( $_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path) {1811 if ($_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path) { 1765 1812 return $blogs; 1766 1813 } else { 1767 foreach ( (array) $blogs as $blog) {1768 if ( strpos($blog['url'], $_SERVER['HTTP_HOST']))1814 foreach ((array) $blogs as $blog) { 1815 if (strpos($blog['url'], $_SERVER['HTTP_HOST'])) 1769 1816 return array($blog); 1770 1817 } 1771 1818 return array(); … … 1787 1834 $this->escape($args); 1788 1835 1789 1836 $username = $args[1]; 1790 $password= $args[2];1837 $password = $args[2]; 1791 1838 1792 if ( !$user = $this->login($username, $password))1839 if (!$user = $this->login($username, $password)) 1793 1840 return $this->error; 1794 1841 1795 if ( !current_user_can( 'edit_posts' ))1796 return new IXR_Error( 401, __( 'Sorry, you do not have access to user data on this site.' ));1842 if (!current_user_can('edit_posts')) 1843 return new IXR_Error(401, __('Sorry, you do not have access to user data on this site.')); 1797 1844 1798 1845 do_action('xmlrpc_call', 'blogger.getUserInfo'); 1799 1846 1800 1847 $struct = array( 1801 'nickname'=> $user->nickname,1802 'userid'=> $user->ID,1803 'url'=> $user->user_url,1804 'lastname'=> $user->last_name,1848 'nickname' => $user->nickname, 1849 'userid' => $user->ID, 1850 'url' => $user->user_url, 1851 'lastname' => $user->last_name, 1805 1852 'firstname' => $user->first_name 1806 1853 ); 1807 1854 … … 1820 1867 1821 1868 $this->escape($args); 1822 1869 1823 $post_ID= (int) $args[1];1870 $post_ID = (int) $args[1]; 1824 1871 $username = $args[2]; 1825 $password= $args[3];1872 $password = $args[3]; 1826 1873 1827 if ( !$user = $this->login($username, $password))1874 if (!$user = $this->login($username, $password)) 1828 1875 return $this->error; 1829 1876 1830 if ( !current_user_can( 'edit_post', $post_ID ))1831 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ));1877 if (!current_user_can('edit_post', $post_ID)) 1878 return new IXR_Error(401, __('Sorry, you cannot edit this post.')); 1832 1879 1833 1880 do_action('xmlrpc_call', 'blogger.getPost'); 1834 1881 … … 1836 1883 1837 1884 $categories = implode(',', wp_get_post_categories($post_ID)); 1838 1885 1839 $content = '<title>'.stripslashes($post_data['post_title']).'</title>';1840 $content .= '<category>'.$categories.'</category>';1886 $content = '<title>' . stripslashes($post_data['post_title']) . '</title>'; 1887 $content .= '<category>' . $categories . '</category>'; 1841 1888 $content .= stripslashes($post_data['post_content']); 1842 1889 1843 1890 $struct = array( 1844 'userid'=> $post_data['post_author'],1891 'userid' => $post_data['post_author'], 1845 1892 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'], false)), 1846 'content'=> $content,1847 'postid'=> (string) $post_data['ID']1893 'content' => $content, 1894 'postid' => (string) $post_data['ID'] 1848 1895 ); 1849 1896 1850 1897 return $struct; … … 1863 1910 $this->escape($args); 1864 1911 1865 1912 // $args[0] = appkey - ignored 1866 $blog_ID= (int) $args[1]; /* though we don't use it yet */1913 $blog_ID = (int) $args[1]; /* though we don't use it yet */ 1867 1914 $username = $args[2]; 1868 $password= $args[3];1869 if ( isset( $args[4] ))1870 $query = array( 'numberposts' => absint( $args[4] ));1915 $password = $args[3]; 1916 if (isset($args[4])) 1917 $query = array('numberposts' => absint($args[4])); 1871 1918 else 1872 1919 $query = array(); 1873 1920 1874 if ( !$user = $this->login($username, $password))1921 if (!$user = $this->login($username, $password)) 1875 1922 return $this->error; 1876 1923 1877 1924 do_action('xmlrpc_call', 'blogger.getRecentPosts'); 1878 1925 1879 $posts_list = wp_get_recent_posts( $query);1926 $posts_list = wp_get_recent_posts($query); 1880 1927 1881 if ( !$posts_list) {1928 if (!$posts_list) { 1882 1929 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); 1883 1930 return $this->error; 1884 1931 } 1885 1932 1886 1933 foreach ($posts_list as $entry) { 1887 if ( !current_user_can( 'edit_post', $entry['ID'] ))1934 if (!current_user_can('edit_post', $entry['ID'])) 1888 1935 continue; 1889 1936 1890 1937 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false); 1891 1938 $categories = implode(',', wp_get_post_categories($entry['ID'])); 1892 1939 1893 $content = '<title>'.stripslashes($entry['post_title']).'</title>';1894 $content .= '<category>'.$categories.'</category>';1940 $content = '<title>' . stripslashes($entry['post_title']) . '</title>'; 1941 $content .= '<category>' . $categories . '</category>'; 1895 1942 $content .= stripslashes($entry['post_content']); 1896 1943 1897 1944 $struct[] = array( … … 1900 1947 'content' => $content, 1901 1948 'postid' => (string) $entry['ID'], 1902 1949 ); 1903 1904 1950 } 1905 1951 1906 1952 $recent_posts = array(); 1907 for ( $j=0; $j<count($struct); $j++) {1953 for ($j = 0; $j < count($struct); $j++) { 1908 1954 array_push($recent_posts, $struct[$j]); 1909 1955 } 1910 1956 … … 1923 1969 1924 1970 $this->escape($args); 1925 1971 1926 $blog_ID= (int) $args[1];1972 $blog_ID = (int) $args[1]; 1927 1973 $username = $args[2]; 1928 $password= $args[3];1929 $template= $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */1974 $password = $args[3]; 1975 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */ 1930 1976 1931 if ( !$user = $this->login($username, $password))1977 if (!$user = $this->login($username, $password)) 1932 1978 return $this->error; 1933 1979 1934 1980 do_action('xmlrpc_call', 'blogger.getTemplate'); 1935 1981 1936 if ( !current_user_can('edit_themes'))1982 if (!current_user_can('edit_themes')) 1937 1983 return new IXR_Error(401, __('Sorry, this user can not edit the template.')); 1938 1984 1939 1985 /* warning: here we make the assumption that the blog's URL is on the same server */ 1940 1986 $filename = get_option('home') . '/'; 1941 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);1987 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'] . '/', $filename); 1942 1988 1943 1989 $f = fopen($filename, 'r'); 1944 1990 $content = fread($f, filesize($filename)); … … 1962 2008 1963 2009 $this->escape($args); 1964 2010 1965 $blog_ID= (int) $args[1];2011 $blog_ID = (int) $args[1]; 1966 2012 $username = $args[2]; 1967 $password= $args[3];1968 $content= $args[4];1969 $template= $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */2013 $password = $args[3]; 2014 $content = $args[4]; 2015 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */ 1970 2016 1971 if ( !$user = $this->login($username, $password))2017 if (!$user = $this->login($username, $password)) 1972 2018 return $this->error; 1973 2019 1974 2020 do_action('xmlrpc_call', 'blogger.setTemplate'); 1975 2021 1976 if ( !current_user_can('edit_themes'))2022 if (!current_user_can('edit_themes')) 1977 2023 return new IXR_Error(401, __('Sorry, this user cannot edit the template.')); 1978 2024 1979 2025 /* warning: here we make the assumption that the blog's URL is on the same server */ 1980 2026 $filename = get_option('home') . '/'; 1981 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);2027 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'] . '/', $filename); 1982 2028 1983 2029 if ($f = fopen($filename, 'w+')) { 1984 2030 fwrite($f, $content); … … 2002 2048 2003 2049 $this->escape($args); 2004 2050 2005 $blog_ID= (int) $args[1]; /* though we don't use it yet */2051 $blog_ID = (int) $args[1]; /* though we don't use it yet */ 2006 2052 $username = $args[2]; 2007 $password= $args[3];2008 $content= $args[4];2009 $publish= $args[5];2053 $password = $args[3]; 2054 $content = $args[4]; 2055 $publish = $args[5]; 2010 2056 2011 if ( !$user = $this->login($username, $password))2057 if (!$user = $this->login($username, $password)) 2012 2058 return $this->error; 2013 2059 2014 2060 do_action('xmlrpc_call', 'blogger.newPost'); 2015 2061 2016 2062 $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 2017 if ( !current_user_can($cap))2063 if (!current_user_can($cap)) 2018 2064 return new IXR_Error(401, __('Sorry, you are not allowed to post on this site.')); 2019 2065 2020 2066 $post_status = ($publish) ? 'publish' : 'draft'; … … 2031 2077 $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status'); 2032 2078 2033 2079 $post_ID = wp_insert_post($post_data); 2034 if ( is_wp_error( $post_ID ))2080 if (is_wp_error($post_ID)) 2035 2081 return new IXR_Error(500, $post_ID->get_error_message()); 2036 2082 2037 if ( !$post_ID)2083 if (!$post_ID) 2038 2084 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); 2039 2085 2040 $this->attach_uploads( $post_ID, $post_content);2086 $this->attach_uploads($post_ID, $post_content); 2041 2087 2042 2088 logIO('O', "Posted ! ID: $post_ID"); 2043 2089 … … 2056 2102 2057 2103 $this->escape($args); 2058 2104 2059 $post_ID= (int) $args[1];2060 $username= $args[2];2061 $password= $args[3];2062 $content= $args[4];2063 $publish= $args[5];2105 $post_ID = (int) $args[1]; 2106 $username = $args[2]; 2107 $password = $args[3]; 2108 $content = $args[4]; 2109 $publish = $args[5]; 2064 2110 2065 if ( !$user = $this->login($username, $password))2111 if (!$user = $this->login($username, $password)) 2066 2112 return $this->error; 2067 2113 2068 2114 do_action('xmlrpc_call', 'blogger.editPost'); 2069 2115 2070 $actual_post = wp_get_single_post($post_ID,ARRAY_A);2116 $actual_post = wp_get_single_post($post_ID, ARRAY_A); 2071 2117 2072 if ( !$actual_post || $actual_post['post_type'] != 'post')2118 if (!$actual_post || $actual_post['post_type'] != 'post') 2073 2119 return new IXR_Error(404, __('Sorry, no such post.')); 2074 2120 2075 2121 $this->escape($actual_post); 2076 2122 2077 if ( !current_user_can('edit_post', $post_ID))2123 if (!current_user_can('edit_post', $post_ID)) 2078 2124 return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.')); 2079 2125 2080 2126 extract($actual_post, EXTR_SKIP); 2081 2127 2082 if ( ('publish' == $post_status) && !current_user_can('publish_posts'))2128 if (('publish' == $post_status) && !current_user_can('publish_posts')) 2083 2129 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.')); 2084 2130 2085 2131 $post_title = xmlrpc_getposttitle($content); … … 2090 2136 2091 2137 $result = wp_update_post($postdata); 2092 2138 2093 if ( !$result)2139 if (!$result) 2094 2140 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.')); 2095 2141 2096 $this->attach_uploads( $ID, $post_content);2142 $this->attach_uploads($ID, $post_content); 2097 2143 2098 2144 return true; 2099 2145 } … … 2109 2155 function blogger_deletePost($args) { 2110 2156 $this->escape($args); 2111 2157 2112 $post_ID= (int) $args[1];2113 $username= $args[2];2114 $password= $args[3];2115 $publish= $args[4];2158 $post_ID = (int) $args[1]; 2159 $username = $args[2]; 2160 $password = $args[3]; 2161 $publish = $args[4]; 2116 2162 2117 if ( !$user = $this->login($username, $password))2163 if (!$user = $this->login($username, $password)) 2118 2164 return $this->error; 2119 2165 2120 2166 do_action('xmlrpc_call', 'blogger.deletePost'); 2121 2167 2122 $actual_post = wp_get_single_post($post_ID,ARRAY_A);2168 $actual_post = wp_get_single_post($post_ID, ARRAY_A); 2123 2169 2124 if ( !$actual_post || $actual_post['post_type'] != 'post')2170 if (!$actual_post || $actual_post['post_type'] != 'post') 2125 2171 return new IXR_Error(404, __('Sorry, no such post.')); 2126 2172 2127 if ( !current_user_can('delete_post', $post_ID))2173 if (!current_user_can('delete_post', $post_ID)) 2128 2174 return new IXR_Error(401, __('Sorry, you do not have the right to delete this post.')); 2129 2175 2130 2176 $result = wp_delete_post($post_ID); 2131 2177 2132 if ( !$result)2178 if (!$result) 2133 2179 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.')); 2134 2180 2135 2181 return true; … … 2176 2222 function mw_newPost($args) { 2177 2223 $this->escape($args); 2178 2224 2179 $blog_ID= (int) $args[0]; // we will support this in the near future2180 $username= $args[1];2181 $password= $args[2];2225 $blog_ID = (int) $args[0]; // we will support this in the near future 2226 $username = $args[1]; 2227 $password = $args[2]; 2182 2228 $content_struct = $args[3]; 2183 $publish = isset( $args[4]) ? $args[4] : 0;2229 $publish = isset($args[4]) ? $args[4] : 0; 2184 2230 2185 if ( !$user = $this->login($username, $password))2231 if (!$user = $this->login($username, $password)) 2186 2232 return $this->error; 2187 2233 2188 2234 do_action('xmlrpc_call', 'metaWeblog.newPost'); 2189 2235 2190 2236 $page_template = ''; 2191 if ( !empty( $content_struct['post_type'] )) {2192 if ( $content_struct['post_type'] == 'page') {2193 if ( $publish)2194 $cap= 'publish_pages';2237 if (!empty($content_struct['post_type'])) { 2238 if ($content_struct['post_type'] == 'page') { 2239 if ($publish) 2240 $cap = 'publish_pages'; 2195 2241 elseif ('publish' == $content_struct['page_status']) 2196 $cap= 'publish_pages';2242 $cap = 'publish_pages'; 2197 2243 else 2198 2244 $cap = 'edit_pages'; 2199 $error_message = __( 'Sorry, you are not allowed to publish pages on this site.');2245 $error_message = __('Sorry, you are not allowed to publish pages on this site.'); 2200 2246 $post_type = 'page'; 2201 if ( !empty( $content_struct['wp_page_template'] ))2247 if (!empty($content_struct['wp_page_template'])) 2202 2248 $page_template = $content_struct['wp_page_template']; 2203 } elseif ( $content_struct['post_type'] == 'post') {2204 if ( $publish)2205 $cap= 'publish_posts';2249 } elseif ($content_struct['post_type'] == 'post') { 2250 if ($publish) 2251 $cap = 'publish_posts'; 2206 2252 elseif ('publish' == $content_struct['post_status']) 2207 $cap= 'publish_posts';2253 $cap = 'publish_posts'; 2208 2254 else 2209 2255 $cap = 'edit_posts'; 2210 $error_message = __( 'Sorry, you are not allowed to publish posts on this site.');2256 $error_message = __('Sorry, you are not allowed to publish posts on this site.'); 2211 2257 $post_type = 'post'; 2212 2258 } else { 2213 2259 // No other post_type values are allowed here 2214 return new IXR_Error( 401, __( 'Invalid post type.' ));2260 return new IXR_Error(401, __('Invalid post type.')); 2215 2261 } 2216 2262 } else { 2217 if ( $publish)2218 $cap= 'publish_posts';2263 if ($publish) 2264 $cap = 'publish_posts'; 2219 2265 elseif ('publish' == $content_struct['post_status']) 2220 $cap= 'publish_posts';2266 $cap = 'publish_posts'; 2221 2267 else 2222 2268 $cap = 'edit_posts'; 2223 $error_message = __( 'Sorry, you are not allowed to publish posts on this site.');2269 $error_message = __('Sorry, you are not allowed to publish posts on this site.'); 2224 2270 $post_type = 'post'; 2225 2271 } 2226 2272 2227 if ( !current_user_can( $cap ))2228 return new IXR_Error( 401, $error_message);2273 if (!current_user_can($cap)) 2274 return new IXR_Error(401, $error_message); 2229 2275 2230 2276 // Check for a valid post format if one was given 2231 if ( isset( $content_struct['wp_post_format'] )) {2232 $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format']);2233 if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() )) {2234 return new IXR_Error( 404, __( 'Invalid post format' ));2277 if (isset($content_struct['wp_post_format'])) { 2278 $content_struct['wp_post_format'] = sanitize_key($content_struct['wp_post_format']); 2279 if (!array_key_exists($content_struct['wp_post_format'], get_post_format_strings())) { 2280 return new IXR_Error(404, __('Invalid post format')); 2235 2281 } 2236 2282 } 2237 2283 2238 2284 // Let WordPress generate the post_name (slug) unless 2239 2285 // one has been provided. 2240 2286 $post_name = ""; 2241 if ( isset($content_struct['wp_slug']))2287 if (isset($content_struct['wp_slug'])) 2242 2288 $post_name = $content_struct['wp_slug']; 2243 2289 2244 2290 // Only use a password if one was given. 2245 if ( isset($content_struct['wp_password']))2291 if (isset($content_struct['wp_password'])) 2246 2292 $post_password = $content_struct['wp_password']; 2247 2293 2248 2294 // Only set a post parent if one was provided. 2249 if ( isset($content_struct['wp_page_parent_id']))2295 if (isset($content_struct['wp_page_parent_id'])) 2250 2296 $post_parent = $content_struct['wp_page_parent_id']; 2251 2297 2252 2298 // Only set the menu_order if it was provided. 2253 if ( isset($content_struct['wp_page_order']))2299 if (isset($content_struct['wp_page_order'])) 2254 2300 $menu_order = $content_struct['wp_page_order']; 2255 2301 2256 2302 $post_author = $user->ID; 2257 2303 2258 2304 // If an author id was provided then use it instead. 2259 if ( isset($content_struct['wp_author_id']) && ($user->ID != $content_struct['wp_author_id'])) {2260 switch ( $post_type) {2305 if (isset($content_struct['wp_author_id']) && ($user->ID != $content_struct['wp_author_id'])) { 2306 switch ($post_type) { 2261 2307 case "post": 2262 if ( !current_user_can('edit_others_posts'))2308 if (!current_user_can('edit_others_posts')) 2263 2309 return(new IXR_Error(401, __('You are not allowed to post as this user'))); 2264 2310 break; 2265 2311 case "page": 2266 if ( !current_user_can('edit_others_pages'))2312 if (!current_user_can('edit_others_pages')) 2267 2313 return(new IXR_Error(401, __('You are not allowed to create pages as this user'))); 2268 2314 break; 2269 2315 default: … … 2273 2319 $post_author = $content_struct['wp_author_id']; 2274 2320 } 2275 2321 2276 $post_title = isset( $content_struct['title']) ? $content_struct['title'] : null;2277 $post_content = isset( $content_struct['description']) ? $content_struct['description'] : null;2322 $post_title = isset($content_struct['title']) ? $content_struct['title'] : null; 2323 $post_content = isset($content_struct['description']) ? $content_struct['description'] : null; 2278 2324 2279 2325 $post_status = $publish ? 'publish' : 'draft'; 2280 2326 2281 if ( isset( $content_struct["{$post_type}_status"] )) {2282 switch ( $content_struct["{$post_type}_status"]) {2327 if (isset($content_struct["{$post_type}_status"])) { 2328 switch ($content_struct["{$post_type}_status"]) { 2283 2329 case 'draft': 2284 2330 case 'pending': 2285 2331 case 'private': … … 2297 2343 2298 2344 $tags_input = isset($content_struct['mt_keywords']) ? $content_struct['mt_keywords'] : null; 2299 2345 2300 if ( isset($content_struct['mt_allow_comments'])) {2301 if ( !is_numeric($content_struct['mt_allow_comments'])) {2302 switch ( $content_struct['mt_allow_comments']) {2346 if (isset($content_struct['mt_allow_comments'])) { 2347 if (!is_numeric($content_struct['mt_allow_comments'])) { 2348 switch ($content_struct['mt_allow_comments']) { 2303 2349 case 'closed': 2304 2350 $comment_status = 'closed'; 2305 2351 break; … … 2311 2357 break; 2312 2358 } 2313 2359 } else { 2314 switch ( (int) $content_struct['mt_allow_comments']) {2360 switch ((int) $content_struct['mt_allow_comments']) { 2315 2361 case 0: 2316 2362 case 2: 2317 2363 $comment_status = 'closed'; … … 2328 2374 $comment_status = get_option('default_comment_status'); 2329 2375 } 2330 2376 2331 if ( isset($content_struct['mt_allow_pings'])) {2332 if ( !is_numeric($content_struct['mt_allow_pings'])) {2333 switch ( $content_struct['mt_allow_pings']) {2377 if (isset($content_struct['mt_allow_pings'])) { 2378 if (!is_numeric($content_struct['mt_allow_pings'])) { 2379 switch ($content_struct['mt_allow_pings']) { 2334 2380 case 'closed': 2335 2381 $ping_status = 'closed'; 2336 2382 break; … … 2342 2388 break; 2343 2389 } 2344 2390 } else { 2345 switch ( (int) $content_struct['mt_allow_pings']) {2391 switch ((int) $content_struct['mt_allow_pings']) { 2346 2392 case 0: 2347 2393 $ping_status = 'closed'; 2348 2394 break; … … 2358 2404 $ping_status = get_option('default_ping_status'); 2359 2405 } 2360 2406 2361 if ( $post_more)2407 if ($post_more) 2362 2408 $post_content = $post_content . '<!--more-->' . $post_more; 2363 2409 2364 2410 $to_ping = null; 2365 if ( isset( $content_struct['mt_tb_ping_urls'] )) {2411 if (isset($content_struct['mt_tb_ping_urls'])) { 2366 2412 $to_ping = $content_struct['mt_tb_ping_urls']; 2367 if ( is_array($to_ping))2413 if (is_array($to_ping)) 2368 2414 $to_ping = implode(' ', $to_ping); 2369 2415 } 2370 2416 2371 2417 // Do some timestamp voodoo 2372 if ( !empty( $content_struct['date_created_gmt'] ))2373 $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso()) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force2374 elseif ( !empty( $content_struct['dateCreated']))2418 if (!empty($content_struct['date_created_gmt'])) 2419 $dateCreated = str_replace('Z', '', $content_struct['date_created_gmt']->getIso()) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force 2420 elseif (!empty($content_struct['dateCreated'])) 2375 2421 $dateCreated = $content_struct['dateCreated']->getIso(); 2376 2422 2377 if ( !empty( $dateCreated )) {2423 if (!empty($dateCreated)) { 2378 2424 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 2379 2425 $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); 2380 2426 } else { … … 2383 2429 } 2384 2430 2385 2431 $post_category = array(); 2386 if ( isset( $content_struct['categories'] )) {2432 if (isset($content_struct['categories'])) { 2387 2433 $catnames = $content_struct['categories']; 2388 logIO('O', 'Post cats: ' . var_export($catnames,true));2434 logIO('O', 'Post cats: ' . var_export($catnames, true)); 2389 2435 2390 if ( is_array($catnames)) {2436 if (is_array($catnames)) { 2391 2437 foreach ($catnames as $cat) { 2392 2438 $post_category[] = get_cat_ID($cat); 2393 2439 } … … 2396 2442 2397 2443 $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', 'page_template'); 2398 2444 2399 $post_ID = $postdata['ID'] = get_default_post_to_edit( $post_type, true)->ID;2445 $post_ID = $postdata['ID'] = get_default_post_to_edit($post_type, true)->ID; 2400 2446 2401 2447 // Only posts can be sticky 2402 if ( $post_type == 'post' && isset( $content_struct['sticky'] )) {2403 if ( $content_struct['sticky'] == true)2404 stick_post( $post_ID);2405 elseif ( $content_struct['sticky'] == false)2406 unstick_post( $post_ID);2448 if ($post_type == 'post' && isset($content_struct['sticky'])) { 2449 if ($content_struct['sticky'] == true) 2450 stick_post($post_ID); 2451 elseif ($content_struct['sticky'] == false) 2452 unstick_post($post_ID); 2407 2453 } 2408 2454 2409 if ( isset($content_struct['custom_fields']))2455 if (isset($content_struct['custom_fields'])) 2410 2456 $this->set_custom_fields($post_ID, $content_struct['custom_fields']); 2411 2457 2412 2458 // Handle enclosures 2413 2459 $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; 2414 2460 $this->add_enclosure_if_new($post_ID, $thisEnclosure); 2415 2461 2416 $this->attach_uploads( $post_ID, $post_content);2462 $this->attach_uploads($post_ID, $post_content); 2417 2463 2418 2464 // Handle post formats if assigned, value is validated earlier 2419 2465 // in this function 2420 if ( isset( $content_struct['wp_post_format'] ))2421 wp_set_post_terms( $post_ID, array( 'post-format-' . $content_struct['wp_post_format'] ), 'post_format');2466 if (isset($content_struct['wp_post_format'])) 2467 wp_set_post_terms($post_ID, array('post-format-' . $content_struct['wp_post_format']), 'post_format'); 2422 2468 2423 $post_ID = wp_insert_post( $postdata, true);2424 if ( is_wp_error( $post_ID ))2469 $post_ID = wp_insert_post($postdata, true); 2470 if (is_wp_error($post_ID)) 2425 2471 return new IXR_Error(500, $post_ID->get_error_message()); 2426 2472 2427 if ( !$post_ID)2473 if (!$post_ID) 2428 2474 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); 2429 2475 2430 2476 logIO('O', "Posted ! ID: $post_ID"); … … 2433 2479 } 2434 2480 2435 2481 function add_enclosure_if_new($post_ID, $enclosure) { 2436 if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] )) {2482 if (is_array($enclosure) && isset($enclosure['url']) && isset($enclosure['length']) && isset($enclosure['type'])) { 2437 2483 2438 2484 $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type']; 2439 2485 $found = false; 2440 foreach ((array) get_post_custom($post_ID) as $key => $val) {2486 foreach ((array) get_post_custom($post_ID) as $key => $val) { 2441 2487 if ($key == 'enclosure') { 2442 foreach ( (array) $val as $enc) {2488 foreach ((array) $val as $enc) { 2443 2489 if ($enc == $encstring) { 2444 2490 $found = true; 2445 2491 break 2; … … 2448 2494 } 2449 2495 } 2450 2496 if (!$found) 2451 add_post_meta( $post_ID, 'enclosure', $encstring);2497 add_post_meta($post_ID, 'enclosure', $encstring); 2452 2498 } 2453 2499 } 2454 2500 … … 2460 2506 * @param int $post_ID Post ID. 2461 2507 * @param string $post_content Post Content for attachment. 2462 2508 */ 2463 function attach_uploads( $post_ID, $post_content) {2509 function attach_uploads($post_ID, $post_content) { 2464 2510 global $wpdb; 2465 2511 2466 2512 // find any unattached files 2467 $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'");2468 if ( is_array( $attachments )) {2469 foreach ( $attachments as $file) {2470 if ( strpos( $post_content, $file->guid ) !== false)2471 $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID));2513 $attachments = $wpdb->get_results("SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'"); 2514 if (is_array($attachments)) { 2515 foreach ($attachments as $file) { 2516 if (strpos($post_content, $file->guid) !== false) 2517 $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID)); 2472 2518 } 2473 2519 } 2474 2520 } … … 2485 2531 2486 2532 $this->escape($args); 2487 2533 2488 $post_ID= (int) $args[0];2489 $username= $args[1];2490 $password= $args[2];2534 $post_ID = (int) $args[0]; 2535 $username = $args[1]; 2536 $password = $args[2]; 2491 2537 $content_struct = $args[3]; 2492 $publish= $args[4];2538 $publish = $args[4]; 2493 2539 2494 if ( !$user = $this->login($username, $password))2540 if (!$user = $this->login($username, $password)) 2495 2541 return $this->error; 2496 2542 2497 2543 do_action('xmlrpc_call', 'metaWeblog.editPost'); 2498 2544 2499 2545 $cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; 2500 $error_message = __( 'Sorry, you are not allowed to publish posts on this site.');2546 $error_message = __('Sorry, you are not allowed to publish posts on this site.'); 2501 2547 $post_type = 'post'; 2502 2548 $page_template = ''; 2503 if ( !empty( $content_struct['post_type'] )) {2504 if ( $content_struct['post_type'] == 'page') {2505 if ( $publish || 'publish' == $content_struct['page_status'])2506 $cap= 'publish_pages';2549 if (!empty($content_struct['post_type'])) { 2550 if ($content_struct['post_type'] == 'page') { 2551 if ($publish || 'publish' == $content_struct['page_status']) 2552 $cap = 'publish_pages'; 2507 2553 else 2508 2554 $cap = 'edit_pages'; 2509 $error_message = __( 'Sorry, you are not allowed to publish pages on this site.');2555 $error_message = __('Sorry, you are not allowed to publish pages on this site.'); 2510 2556 $post_type = 'page'; 2511 if ( !empty( $content_struct['wp_page_template'] ))2557 if (!empty($content_struct['wp_page_template'])) 2512 2558 $page_template = $content_struct['wp_page_template']; 2513 } elseif ( $content_struct['post_type'] == 'post') {2514 if ( $publish || 'publish' == $content_struct['post_status'])2515 $cap= 'publish_posts';2559 } elseif ($content_struct['post_type'] == 'post') { 2560 if ($publish || 'publish' == $content_struct['post_status']) 2561 $cap = 'publish_posts'; 2516 2562 else 2517 2563 $cap = 'edit_posts'; 2518 $error_message = __( 'Sorry, you are not allowed to publish posts on this site.');2564 $error_message = __('Sorry, you are not allowed to publish posts on this site.'); 2519 2565 $post_type = 'post'; 2520 2566 } else { 2521 2567 // No other post_type values are allowed here 2522 return new IXR_Error( 401, __( 'Invalid post type.' ));2568 return new IXR_Error(401, __('Invalid post type.')); 2523 2569 } 2524 2570 } else { 2525 if ( $publish || 'publish' == $content_struct['post_status'])2526 $cap= 'publish_posts';2571 if ($publish || 'publish' == $content_struct['post_status']) 2572 $cap = 'publish_posts'; 2527 2573 else 2528 2574 $cap = 'edit_posts'; 2529 $error_message = __( 'Sorry, you are not allowed to publish posts on this site.');2575 $error_message = __('Sorry, you are not allowed to publish posts on this site.'); 2530 2576 $post_type = 'post'; 2531 2577 } 2532 2578 2533 if ( !current_user_can( $cap ))2534 return new IXR_Error( 401, $error_message);2579 if (!current_user_can($cap)) 2580 return new IXR_Error(401, $error_message); 2535 2581 2536 2582 // Check for a valid post format if one was given 2537 if ( isset( $content_struct['wp_post_format'] )) {2538 $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format']);2539 if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() )) {2540 return new IXR_Error( 404, __( 'Invalid post format' ));2583 if (isset($content_struct['wp_post_format'])) { 2584 $content_struct['wp_post_format'] = sanitize_key($content_struct['wp_post_format']); 2585 if (!array_key_exists($content_struct['wp_post_format'], get_post_format_strings())) { 2586 return new IXR_Error(404, __('Invalid post format')); 2541 2587 } 2542 2588 } 2543 2589 … … 2546 2592 // If there is no post data for the give post id, stop 2547 2593 // now and return an error. Other wise a new post will be 2548 2594 // created (which was the old behavior). 2549 if ( empty($postdata["ID"]))2595 if (empty($postdata["ID"])) 2550 2596 return(new IXR_Error(404, __('Invalid post ID.'))); 2551 2597 2552 2598 $this->escape($postdata); … … 2555 2601 // Let WordPress manage slug if none was provided. 2556 2602 $post_name = ""; 2557 2603 $post_name = $postdata['post_name']; 2558 if ( isset($content_struct['wp_slug']))2604 if (isset($content_struct['wp_slug'])) 2559 2605 $post_name = $content_struct['wp_slug']; 2560 2606 2561 2607 // Only use a password if one was given. 2562 if ( isset($content_struct['wp_password']))2608 if (isset($content_struct['wp_password'])) 2563 2609 $post_password = $content_struct['wp_password']; 2564 2610 2565 2611 // Only set a post parent if one was given. 2566 if ( isset($content_struct['wp_page_parent_id']))2612 if (isset($content_struct['wp_page_parent_id'])) 2567 2613 $post_parent = $content_struct['wp_page_parent_id']; 2568 2614 2569 2615 // Only set the menu_order if it was given. 2570 if ( isset($content_struct['wp_page_order']))2616 if (isset($content_struct['wp_page_order'])) 2571 2617 $menu_order = $content_struct['wp_page_order']; 2572 2618 2573 2619 $post_author = $postdata['post_author']; 2574 2620 2575 2621 // Only set the post_author if one is set. 2576 if ( isset($content_struct['wp_author_id']) && ($user->ID != $content_struct['wp_author_id'])) {2577 switch ( $post_type) {2622 if (isset($content_struct['wp_author_id']) && ($user->ID != $content_struct['wp_author_id'])) { 2623 switch ($post_type) { 2578 2624 case 'post': 2579 if ( !current_user_can('edit_others_posts'))2625 if (!current_user_can('edit_others_posts')) 2580 2626 return(new IXR_Error(401, __('You are not allowed to change the post author as this user.'))); 2581 2627 break; 2582 2628 case 'page': 2583 if ( !current_user_can('edit_others_pages'))2629 if (!current_user_can('edit_others_pages')) 2584 2630 return(new IXR_Error(401, __('You are not allowed to change the page author as this user.'))); 2585 2631 break; 2586 2632 default: … … 2590 2636 $post_author = $content_struct['wp_author_id']; 2591 2637 } 2592 2638 2593 if ( isset($content_struct['mt_allow_comments'])) {2594 if ( !is_numeric($content_struct['mt_allow_comments'])) {2595 switch ( $content_struct['mt_allow_comments']) {2639 if (isset($content_struct['mt_allow_comments'])) { 2640 if (!is_numeric($content_struct['mt_allow_comments'])) { 2641 switch ($content_struct['mt_allow_comments']) { 2596 2642 case 'closed': 2597 2643 $comment_status = 'closed'; 2598 2644 break; … … 2604 2650 break; 2605 2651 } 2606 2652 } else { 2607 switch ( (int) $content_struct['mt_allow_comments']) {2653 switch ((int) $content_struct['mt_allow_comments']) { 2608 2654 case 0: 2609 2655 case 2: 2610 2656 $comment_status = 'closed'; … … 2619 2665 } 2620 2666 } 2621 2667 2622 if ( isset($content_struct['mt_allow_pings'])) {2623 if ( !is_numeric($content_struct['mt_allow_pings'])) {2624 switch ( $content_struct['mt_allow_pings']) {2668 if (isset($content_struct['mt_allow_pings'])) { 2669 if (!is_numeric($content_struct['mt_allow_pings'])) { 2670 switch ($content_struct['mt_allow_pings']) { 2625 2671 case 'closed': 2626 2672 $ping_status = 'closed'; 2627 2673 break; … … 2633 2679 break; 2634 2680 } 2635 2681 } else { 2636 switch ( (int) $content_struct["mt_allow_pings"]) {2682 switch ((int) $content_struct["mt_allow_pings"]) { 2637 2683 case 0: 2638 2684 $ping_status = 'closed'; 2639 2685 break; … … 2647 2693 } 2648 2694 } 2649 2695 2650 $post_title = isset( $content_struct['title']) ? $content_struct['title'] : null;2651 $post_content = isset( $content_struct['description']) ? $content_struct['description'] : null;2696 $post_title = isset($content_struct['title']) ? $content_struct['title'] : null; 2697 $post_content = isset($content_struct['description']) ? $content_struct['description'] : null; 2652 2698 2653 2699 $post_category = array(); 2654 if ( isset( $content_struct['categories'] )) {2700 if (isset($content_struct['categories'])) { 2655 2701 $catnames = $content_struct['categories']; 2656 if ( is_array($catnames)) {2702 if (is_array($catnames)) { 2657 2703 foreach ($catnames as $cat) { 2658 2704 $post_category[] = get_cat_ID($cat); 2659 2705 } 2660 2706 } 2661 2707 } 2662 2708 2663 $post_excerpt = isset( $content_struct['mt_excerpt']) ? $content_struct['mt_excerpt'] : null;2664 $post_more = isset( $content_struct['mt_text_more']) ? $content_struct['mt_text_more'] : null;2709 $post_excerpt = isset($content_struct['mt_excerpt']) ? $content_struct['mt_excerpt'] : null; 2710 $post_more = isset($content_struct['mt_text_more']) ? $content_struct['mt_text_more'] : null; 2665 2711 2666 2712 $post_status = $publish ? 'publish' : 'draft'; 2667 if ( isset( $content_struct["{$post_type}_status"] )) {2668 switch( $content_struct["{$post_type}_status"]) {2713 if (isset($content_struct["{$post_type}_status"])) { 2714 switch ($content_struct["{$post_type}_status"]) { 2669 2715 case 'draft': 2670 2716 case 'pending': 2671 2717 case 'private': … … 2678 2724 } 2679 2725 } 2680 2726 2681 $tags_input = isset( $content_struct['mt_keywords']) ? $content_struct['mt_keywords'] : null;2727 $tags_input = isset($content_struct['mt_keywords']) ? $content_struct['mt_keywords'] : null; 2682 2728 2683 if ( ('publish' == $post_status)) {2684 if ( ( 'page' == $post_type ) && !current_user_can('publish_pages'))2729 if (('publish' == $post_status)) { 2730 if (( 'page' == $post_type ) && !current_user_can('publish_pages')) 2685 2731 return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.')); 2686 else if ( !current_user_can('publish_posts'))2732 else if (!current_user_can('publish_posts')) 2687 2733 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.')); 2688 2734 } 2689 2735 2690 if ( $post_more)2736 if ($post_more) 2691 2737 $post_content = $post_content . "<!--more-->" . $post_more; 2692 2738 2693 2739 $to_ping = null; 2694 if ( isset( $content_struct['mt_tb_ping_urls'] )) {2740 if (isset($content_struct['mt_tb_ping_urls'])) { 2695 2741 $to_ping = $content_struct['mt_tb_ping_urls']; 2696 if ( is_array($to_ping))2742 if (is_array($to_ping)) 2697 2743 $to_ping = implode(' ', $to_ping); 2698 2744 } 2699 2745 2700 2746 // Do some timestamp voodoo 2701 if ( !empty( $content_struct['date_created_gmt'] ))2702 $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso()) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force2703 elseif ( !empty( $content_struct['dateCreated']))2747 if (!empty($content_struct['date_created_gmt'])) 2748 $dateCreated = str_replace('Z', '', $content_struct['date_created_gmt']->getIso()) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force 2749 elseif (!empty($content_struct['dateCreated'])) 2704 2750 $dateCreated = $content_struct['dateCreated']->getIso(); 2705 2751 2706 if ( !empty( $dateCreated )) {2752 if (!empty($dateCreated)) { 2707 2753 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 2708 2754 $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); 2709 2755 } else { 2710 $post_date= $postdata['post_date'];2756 $post_date = $postdata['post_date']; 2711 2757 $post_date_gmt = $postdata['post_date_gmt']; 2712 2758 } 2713 2759 … … 2715 2761 $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template'); 2716 2762 2717 2763 $result = wp_update_post($newpost, true); 2718 if ( is_wp_error( $result ))2764 if (is_wp_error($result)) 2719 2765 return new IXR_Error(500, $result->get_error_message()); 2720 2766 2721 if ( !$result)2767 if (!$result) 2722 2768 return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.')); 2723 2769 2724 2770 // Only posts can be sticky 2725 if ( $post_type == 'post' && isset( $content_struct['sticky'] )) {2726 if ( $content_struct['sticky'] == true)2727 stick_post( $post_ID);2728 elseif ( $content_struct['sticky'] == false)2729 unstick_post( $post_ID);2771 if ($post_type == 'post' && isset($content_struct['sticky'])) { 2772 if ($content_struct['sticky'] == true) 2773 stick_post($post_ID); 2774 elseif ($content_struct['sticky'] == false) 2775 unstick_post($post_ID); 2730 2776 } 2731 2777 2732 if ( isset($content_struct['custom_fields']))2778 if (isset($content_struct['custom_fields'])) 2733 2779 $this->set_custom_fields($post_ID, $content_struct['custom_fields']); 2734 2780 2735 2781 // Handle enclosures 2736 2782 $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; 2737 2783 $this->add_enclosure_if_new($post_ID, $thisEnclosure); 2738 2784 2739 $this->attach_uploads( $ID, $post_content);2785 $this->attach_uploads($ID, $post_content); 2740 2786 2741 2787 // Handle post formats if assigned, validation is handled 2742 2788 // earlier in this function 2743 if ( isset( $content_struct['wp_post_format'] ))2744 wp_set_post_terms( $post_ID, array( 'post-format-' . $content_struct['wp_post_format'] ), 'post_format');2789 if (isset($content_struct['wp_post_format'])) 2790 wp_set_post_terms($post_ID, array('post-format-' . $content_struct['wp_post_format']), 'post_format'); 2745 2791 2746 logIO('O',"(MW) Edited ! ID: $post_ID");2792 logIO('O', "(MW) Edited ! ID: $post_ID"); 2747 2793 2748 2794 return true; 2749 2795 } … … 2760 2806 2761 2807 $this->escape($args); 2762 2808 2763 $post_ID= (int) $args[0];2764 $username= $args[1];2765 $password= $args[2];2809 $post_ID = (int) $args[0]; 2810 $username = $args[1]; 2811 $password = $args[2]; 2766 2812 2767 if ( !$user = $this->login($username, $password))2813 if (!$user = $this->login($username, $password)) 2768 2814 return $this->error; 2769 2815 2770 if ( !current_user_can( 'edit_post', $post_ID ))2771 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ));2816 if (!current_user_can('edit_post', $post_ID)) 2817 return new IXR_Error(401, __('Sorry, you cannot edit this post.')); 2772 2818 2773 2819 do_action('xmlrpc_call', 'metaWeblog.getPost'); 2774 2820 … … 2779 2825 $post_date_gmt = mysql2date('Ymd\TH:i:s', $postdata['post_date_gmt'], false); 2780 2826 2781 2827 // For drafts use the GMT version of the post date 2782 if ( $postdata['post_status'] == 'draft')2783 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ), 'Ymd\TH:i:s');2828 if ($postdata['post_status'] == 'draft') 2829 $post_date_gmt = get_gmt_from_date(mysql2date('Y-m-d H:i:s', $postdata['post_date']), 'Ymd\TH:i:s'); 2784 2830 2785 2831 $categories = array(); 2786 2832 $catids = wp_get_post_categories($post_ID); 2787 foreach($catids as $catid)2833 foreach ($catids as $catid) 2788 2834 $categories[] = get_cat_name($catid); 2789 2835 2790 2836 $tagnames = array(); 2791 $tags = wp_get_post_tags( $post_ID);2792 if ( !empty( $tags )) {2793 foreach ( $tags as $tag)2837 $tags = wp_get_post_tags($post_ID); 2838 if (!empty($tags)) { 2839 foreach ($tags as $tag) 2794 2840 $tagnames[] = $tag->name; 2795 $tagnames = implode( ', ', $tagnames);2841 $tagnames = implode(', ', $tagnames); 2796 2842 } else { 2797 2843 $tagnames = ''; 2798 2844 } … … 2807 2853 $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0; 2808 2854 2809 2855 // Consider future posts as published 2810 if ( $postdata['post_status'] === 'future')2856 if ($postdata['post_status'] === 'future') 2811 2857 $postdata['post_status'] = 'publish'; 2812 2858 2813 2859 // Get post format 2814 $post_format = get_post_format( $post_ID);2815 if ( empty( $post_format ))2860 $post_format = get_post_format($post_ID); 2861 if (empty($post_format)) 2816 2862 $post_format = 'standard'; 2817 2863 2818 2864 $sticky = false; 2819 if ( is_sticky( $post_ID ))2865 if (is_sticky($post_ID)) 2820 2866 $sticky = true; 2821 2867 2822 2868 $enclosure = array(); 2823 foreach ((array) get_post_custom($post_ID) as $key => $val) {2869 foreach ((array) get_post_custom($post_ID) as $key => $val) { 2824 2870 if ($key == 'enclosure') { 2825 foreach ( (array) $val as $enc) {2871 foreach ((array) $val as $enc) { 2826 2872 $encdata = split("\n", $enc); 2827 2873 $enclosure['url'] = trim(htmlspecialchars($encdata[0])); 2828 2874 $enclosure['length'] = (int) trim($encdata[1]); … … 2851 2897 'wp_slug' => $postdata['post_name'], 2852 2898 'wp_password' => $postdata['post_password'], 2853 2899 'wp_author_id' => (string) $author->ID, 2854 'wp_author_display_name'=> $author->display_name,2900 'wp_author_display_name' => $author->display_name, 2855 2901 'date_created_gmt' => new IXR_Date($post_date_gmt), 2856 2902 'post_status' => $postdata['post_status'], 2857 2903 'custom_fields' => $this->get_custom_fields($post_ID), … … 2859 2905 'sticky' => $sticky 2860 2906 ); 2861 2907 2862 if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure; 2908 if (!empty($enclosure)) 2909 $resp['enclosure'] = $enclosure; 2863 2910 2864 2911 return $resp; 2865 2912 } else { … … 2879 2926 2880 2927 $this->escape($args); 2881 2928 2882 $blog_ID= (int) $args[0];2883 $username= $args[1];2884 $password= $args[2];2885 if ( isset( $args[3] ))2886 $query = array( 'numberposts' => absint( $args[3] ));2929 $blog_ID = (int) $args[0]; 2930 $username = $args[1]; 2931 $password = $args[2]; 2932 if (isset($args[3])) 2933 $query = array('numberposts' => absint($args[3])); 2887 2934 else 2888 2935 $query = array(); 2889 2936 2890 if ( !$user = $this->login($username, $password))2937 if (!$user = $this->login($username, $password)) 2891 2938 return $this->error; 2892 2939 2893 2940 do_action('xmlrpc_call', 'metaWeblog.getRecentPosts'); 2894 2941 2895 $posts_list = wp_get_recent_posts( $query);2942 $posts_list = wp_get_recent_posts($query); 2896 2943 2897 if ( !$posts_list)2898 return array();2944 if (!$posts_list) 2945 return array(); 2899 2946 2900 2947 foreach ($posts_list as $entry) { 2901 if ( !current_user_can( 'edit_post', $entry['ID'] ))2948 if (!current_user_can('edit_post', $entry['ID'])) 2902 2949 continue; 2903 2950 2904 2951 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false); 2905 2952 $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false); 2906 2953 2907 2954 // For drafts use the GMT version of the date 2908 if ( $entry['post_status'] == 'draft')2909 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s');2955 if ($entry['post_status'] == 'draft') 2956 $post_date_gmt = get_gmt_from_date(mysql2date('Y-m-d H:i:s', $entry['post_date']), 'Ymd\TH:i:s'); 2910 2957 2911 2958 $categories = array(); 2912 2959 $catids = wp_get_post_categories($entry['ID']); 2913 foreach( $catids as $catid)2960 foreach ($catids as $catid) 2914 2961 $categories[] = get_cat_name($catid); 2915 2962 2916 2963 $tagnames = array(); 2917 $tags = wp_get_post_tags( $entry['ID']);2918 if ( !empty( $tags )) {2919 foreach ( $tags as $tag) {2964 $tags = wp_get_post_tags($entry['ID']); 2965 if (!empty($tags)) { 2966 foreach ($tags as $tag) { 2920 2967 $tagnames[] = $tag->name; 2921 2968 } 2922 $tagnames = implode( ', ', $tagnames);2969 $tagnames = implode(', ', $tagnames); 2923 2970 } else { 2924 2971 $tagnames = ''; 2925 2972 } … … 2934 2981 $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0; 2935 2982 2936 2983 // Consider future posts as published 2937 if ( $entry['post_status'] === 'future')2984 if ($entry['post_status'] === 'future') 2938 2985 $entry['post_status'] = 'publish'; 2939 2986 2940 2987 // Get post format 2941 $post_format = get_post_format( $entry['ID']);2942 if ( empty( $post_format ))2988 $post_format = get_post_format($entry['ID']); 2989 if (empty($post_format)) 2943 2990 $post_format = 'standard'; 2944 2991 2945 2992 $struct[] = array( … … 2967 3014 'custom_fields' => $this->get_custom_fields($entry['ID']), 2968 3015 'wp_post_format' => $post_format 2969 3016 ); 2970 2971 3017 } 2972 3018 2973 3019 $recent_posts = array(); 2974 for ( $j=0; $j<count($struct); $j++) {3020 for ($j = 0; $j < count($struct); $j++) { 2975 3021 array_push($recent_posts, $struct[$j]); 2976 3022 } 2977 3023 … … 2990 3036 2991 3037 $this->escape($args); 2992 3038 2993 $blog_ID= (int) $args[0];2994 $username= $args[1];2995 $password= $args[2];3039 $blog_ID = (int) $args[0]; 3040 $username = $args[1]; 3041 $password = $args[2]; 2996 3042 2997 if ( !$user = $this->login($username, $password))3043 if (!$user = $this->login($username, $password)) 2998 3044 return $this->error; 2999 3045 3000 if ( !current_user_can( 'edit_posts' ))3001 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ));3046 if (!current_user_can('edit_posts')) 3047 return new IXR_Error(401, __('Sorry, you must be able to edit posts on this site in order to view categories.')); 3002 3048 3003 3049 do_action('xmlrpc_call', 'metaWeblog.getCategories'); 3004 3050 3005 3051 $categories_struct = array(); 3006 3052 3007 if ( $cats = get_categories(array('get' => 'all'))) {3008 foreach ( $cats as $cat) {3053 if ($cats = get_categories(array('get' => 'all'))) { 3054 foreach ($cats as $cat) { 3009 3055 $struct['categoryId'] = $cat->term_id; 3010 3056 $struct['parentId'] = $cat->parent; 3011 3057 $struct['description'] = $cat->name; … … 3036 3082 function mw_newMediaObject($args) { 3037 3083 global $wpdb; 3038 3084 3039 $blog_ID= (int) $args[0];3040 $username= $wpdb->escape($args[1]);3041 $password= $wpdb->escape($args[2]);3042 $data= $args[3];3085 $blog_ID = (int) $args[0]; 3086 $username = $wpdb->escape($args[1]); 3087 $password = $wpdb->escape($args[2]); 3088 $data = $args[3]; 3043 3089 3044 $name = sanitize_file_name( $data['name']);3090 $name = sanitize_file_name($data['name']); 3045 3091 $type = $data['type']; 3046 3092 $bits = $data['bits']; 3047 3093 3048 logIO('O', '(MW) Received '.strlen($bits).' bytes');3094 logIO('O', '(MW) Received ' . strlen($bits) . ' bytes'); 3049 3095 3050 if ( !$user = $this->login($username, $password))3096 if (!$user = $this->login($username, $password)) 3051 3097 return $this->error; 3052 3098 3053 3099 do_action('xmlrpc_call', 'metaWeblog.newMediaObject'); 3054 3100 3055 if ( !current_user_can('upload_files')) {3101 if (!current_user_can('upload_files')) { 3056 3102 logIO('O', '(MW) User does not have upload_files capability'); 3057 3103 $this->error = new IXR_Error(401, __('You are not allowed to upload files to this site.')); 3058 3104 return $this->error; 3059 3105 } 3060 3106 3061 if ( $upload_err = apply_filters( 'pre_upload_error', false ))3107 if ($upload_err = apply_filters('pre_upload_error', false)) 3062 3108 return new IXR_Error(500, $upload_err); 3063 3109 3064 if ( !empty($data['overwrite']) && ($data['overwrite'] == true)) {3110 if (!empty($data['overwrite']) && ($data['overwrite'] == true)) { 3065 3111 // Get postmeta info on the object. 3066 3112 $old_file = $wpdb->get_row(" 3067 3113 SELECT ID … … 3080 3126 } 3081 3127 3082 3128 $upload = wp_upload_bits($name, NULL, $bits); 3083 if ( ! empty($upload['error'])) {3129 if (!empty($upload['error'])) { 3084 3130 $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']); 3085 3131 logIO('O', '(MW) ' . $errorString); 3086 3132 return new IXR_Error(500, $errorString); … … 3094 3140 'post_type' => 'attachment', 3095 3141 'post_parent' => $post_id, 3096 3142 'post_mime_type' => $type, 3097 'guid' => $upload[ 'url']3143 'guid' => $upload['url'] 3098 3144 ); 3099 3145 3100 3146 // Save the data 3101 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id);3102 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ));3147 $id = wp_insert_attachment($attachment, $upload['file'], $post_id); 3148 wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $upload['file'])); 3103 3149 3104 return apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type ), 'upload');3150 return apply_filters('wp_handle_upload', array('file' => $name, 'url' => $upload['url'], 'type' => $type), 'upload'); 3105 3151 } 3106 3152 3107 3153 /* MovableType API functions … … 3120 3166 3121 3167 $this->escape($args); 3122 3168 3123 $blog_ID= (int) $args[0];3124 $username= $args[1];3125 $password= $args[2];3126 if ( isset( $args[3] ))3127 $query = array( 'numberposts' => absint( $args[3] ));3169 $blog_ID = (int) $args[0]; 3170 $username = $args[1]; 3171 $password = $args[2]; 3172 if (isset($args[3])) 3173 $query = array('numberposts' => absint($args[3])); 3128 3174 else 3129 3175 $query = array(); 3130 3176 3131 if ( !$user = $this->login($username, $password))3177 if (!$user = $this->login($username, $password)) 3132 3178 return $this->error; 3133 3179 3134 3180 do_action('xmlrpc_call', 'mt.getRecentPostTitles'); 3135 3181 3136 $posts_list = wp_get_recent_posts( $query);3182 $posts_list = wp_get_recent_posts($query); 3137 3183 3138 if ( !$posts_list) {3184 if (!$posts_list) { 3139 3185 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); 3140 3186 return $this->error; 3141 3187 } 3142 3188 3143 3189 foreach ($posts_list as $entry) { 3144 if ( !current_user_can( 'edit_post', $entry['ID'] ))3190 if (!current_user_can('edit_post', $entry['ID'])) 3145 3191 continue; 3146 3192 3147 3193 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false); 3148 3194 $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false); 3149 3195 3150 3196 // For drafts use the GMT version of the date 3151 if ( $entry['post_status'] == 'draft')3152 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s');3197 if ($entry['post_status'] == 'draft') 3198 $post_date_gmt = get_gmt_from_date(mysql2date('Y-m-d H:i:s', $entry['post_date']), 'Ymd\TH:i:s'); 3153 3199 3154 3200 $struct[] = array( 3155 3201 'dateCreated' => new IXR_Date($post_date), … … 3159 3205 'post_status' => $entry['post_status'], 3160 3206 'date_created_gmt' => new IXR_Date($post_date_gmt) 3161 3207 ); 3162 3163 3208 } 3164 3209 3165 3210 $recent_posts = array(); 3166 for ( $j=0; $j<count($struct); $j++) {3211 for ($j = 0; $j < count($struct); $j++) { 3167 3212 array_push($recent_posts, $struct[$j]); 3168 3213 } 3169 3214 … … 3182 3227 3183 3228 $this->escape($args); 3184 3229 3185 $blog_ID= (int) $args[0];3186 $username= $args[1];3187 $password= $args[2];3230 $blog_ID = (int) $args[0]; 3231 $username = $args[1]; 3232 $password = $args[2]; 3188 3233 3189 if ( !$user = $this->login($username, $password))3234 if (!$user = $this->login($username, $password)) 3190 3235 return $this->error; 3191 3236 3192 if ( !current_user_can( 'edit_posts' ))3193 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ));3237 if (!current_user_can('edit_posts')) 3238 return new IXR_Error(401, __('Sorry, you must be able to edit posts on this site in order to view categories.')); 3194 3239 3195 3240 do_action('xmlrpc_call', 'mt.getCategoryList'); 3196 3241 3197 3242 $categories_struct = array(); 3198 3243 3199 if ( $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => 0))) {3200 foreach ( $cats as $cat) {3244 if ($cats = get_categories(array('hide_empty' => 0, 'hierarchical' => 0))) { 3245 foreach ($cats as $cat) { 3201 3246 $struct['categoryId'] = $cat->term_id; 3202 3247 $struct['categoryName'] = $cat->name; 3203 3248 … … 3220 3265 3221 3266 $this->escape($args); 3222 3267 3223 $post_ID= (int) $args[0];3224 $username= $args[1];3225 $password= $args[2];3268 $post_ID = (int) $args[0]; 3269 $username = $args[1]; 3270 $password = $args[2]; 3226 3271 3227 if ( !$user = $this->login($username, $password))3272 if (!$user = $this->login($username, $password)) 3228 3273 return $this->error; 3229 3274 3230 if ( !current_user_can( 'edit_post', $post_ID ))3231 return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ));3275 if (!current_user_can('edit_post', $post_ID)) 3276 return new IXR_Error(401, __('Sorry, you can not edit this post.')); 3232 3277 3233 3278 do_action('xmlrpc_call', 'mt.getPostCategories'); 3234 3279 … … 3236 3281 $catids = wp_get_post_categories(intval($post_ID)); 3237 3282 // first listed category will be the primary category 3238 3283 $isPrimary = true; 3239 foreach ( $catids as $catid) {3284 foreach ($catids as $catid) { 3240 3285 $categories[] = array( 3241 3286 'categoryName' => get_cat_name($catid), 3242 3287 'categoryId' => (string) $catid, … … 3260 3305 3261 3306 $this->escape($args); 3262 3307 3263 $post_ID= (int) $args[0];3264 $username= $args[1];3265 $password= $args[2];3266 $categories= $args[3];3308 $post_ID = (int) $args[0]; 3309 $username = $args[1]; 3310 $password = $args[2]; 3311 $categories = $args[3]; 3267 3312 3268 if ( !$user = $this->login($username, $password))3313 if (!$user = $this->login($username, $password)) 3269 3314 return $this->error; 3270 3315 3271 3316 do_action('xmlrpc_call', 'mt.setPostCategories'); 3272 3317 3273 if ( !current_user_can('edit_post', $post_ID))3318 if (!current_user_can('edit_post', $post_ID)) 3274 3319 return new IXR_Error(401, __('Sorry, you cannot edit this post.')); 3275 3320 3276 foreach ( $categories as $cat) {3321 foreach ($categories as $cat) { 3277 3322 $catids[] = $cat['categoryId']; 3278 3323 } 3279 3324 … … 3295 3340 do_action('xmlrpc_call', 'mt.supportedMethods'); 3296 3341 3297 3342 $supported_methods = array(); 3298 foreach ( $this->methods as $key => $value) {3343 foreach ($this->methods as $key => $value) { 3299 3344 $supported_methods[] = $key; 3300 3345 } 3301 3346 … … 3332 3377 3333 3378 $actual_post = wp_get_single_post($post_ID, ARRAY_A); 3334 3379 3335 if ( !$actual_post)3380 if (!$actual_post) 3336 3381 return new IXR_Error(404, __('Sorry, no such post.')); 3337 3382 3338 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID));3383 $comments = $wpdb->get_results($wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID)); 3339 3384 3340 if ( !$comments)3385 if (!$comments) 3341 3386 return array(); 3342 3387 3343 3388 $trackback_pings = array(); 3344 foreach ( $comments as $comment) {3345 if ( 'trackback' == $comment->comment_type) {3389 foreach ($comments as $comment) { 3390 if ('trackback' == $comment->comment_type) { 3346 3391 $content = $comment->comment_content; 3347 3392 $title = substr($content, 8, (strpos($content, '</strong>') - 8)); 3348 3393 $trackback_pings[] = array( 3349 3394 'pingTitle' => $title, 3350 'pingURL'=> $comment->comment_author_url,3351 'pingIP'=> $comment->comment_author_IP3395 'pingURL' => $comment->comment_author_url, 3396 'pingIP' => $comment->comment_author_IP 3352 3397 ); 3353 3398 } 3354 3399 } … … 3368 3413 3369 3414 $this->escape($args); 3370 3415 3371 $post_ID= (int) $args[0];3372 $username= $args[1];3373 $password= $args[2];3416 $post_ID = (int) $args[0]; 3417 $username = $args[1]; 3418 $password = $args[2]; 3374 3419 3375 if ( !$user = $this->login($username, $password))3420 if (!$user = $this->login($username, $password)) 3376 3421 return $this->error; 3377 3422 3378 3423 do_action('xmlrpc_call', 'mt.publishPost'); 3379 3424 3380 if ( !current_user_can('publish_posts') || !current_user_can('edit_post', $post_ID))3425 if (!current_user_can('publish_posts') || !current_user_can('edit_post', $post_ID)) 3381 3426 return new IXR_Error(401, __('Sorry, you cannot publish this post.')); 3382 3427 3383 $postdata = wp_get_single_post($post_ID,ARRAY_A);3428 $postdata = wp_get_single_post($post_ID, ARRAY_A); 3384 3429 3385 3430 $postdata['post_status'] = 'publish'; 3386 3431 … … 3414 3459 $this->escape($args); 3415 3460 3416 3461 $pagelinkedfrom = $args[0]; 3417 $pagelinkedto= $args[1];3462 $pagelinkedto = $args[1]; 3418 3463 3419 3464 $title = ''; 3420 3465 … … 3423 3468 $pagelinkedto = str_replace('&', '&', $pagelinkedto); 3424 3469 3425 3470 // Check if the page linked to is in our site 3426 $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_option('home')));3427 if ( !$pos1)3471 $pos1 = strpos($pagelinkedto, str_replace(array('http://www.', 'http://', 'https://www.', 'https://'), '', get_option('home'))); 3472 if (!$pos1) 3428 3473 return new IXR_Error(0, __('Is there no link to us?')); 3429 3474 3430 3475 // let's find which post is linked to 3431 3476 // FIXME: does url_to_postid() cover all these cases already? 3432 3477 // if so, then let's use it and drop the old code. 3433 3478 $urltest = parse_url($pagelinkedto); 3434 if ( $post_ID = url_to_postid($pagelinkedto)) {3479 if ($post_ID = url_to_postid($pagelinkedto)) { 3435 3480 $way = 'url_to_postid()'; 3436 } elseif ( preg_match('#p/[0-9]{1,}#', $urltest['path'], $match)) {3481 } elseif (preg_match('#p/[0-9]{1,}#', $urltest['path'], $match)) { 3437 3482 // the path defines the post_ID (archives/p/XXXX) 3438 3483 $blah = explode('/', $match[0]); 3439 3484 $post_ID = (int) $blah[1]; 3440 3485 $way = 'from the path'; 3441 } elseif ( preg_match('#p=[0-9]{1,}#', $urltest['query'], $match)) {3486 } elseif (preg_match('#p=[0-9]{1,}#', $urltest['query'], $match)) { 3442 3487 // the querystring defines the post_ID (?p=XXXX) 3443 3488 $blah = explode('=', $match[0]); 3444 3489 $post_ID = (int) $blah[1]; 3445 3490 $way = 'from the querystring'; 3446 } elseif ( isset($urltest['fragment'])) {3491 } elseif (isset($urltest['fragment'])) { 3447 3492 // an #anchor is there, it's either... 3448 if ( intval($urltest['fragment'])) {3493 if (intval($urltest['fragment'])) { 3449 3494 // ...an integer #XXXX (simplest case) 3450 3495 $post_ID = (int) $urltest['fragment']; 3451 3496 $way = 'from the fragment (numeric)'; 3452 } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment'])) {3497 } elseif (preg_match('/post-[0-9]+/', $urltest['fragment'])) { 3453 3498 // ...a post id in the form 'post-###' 3454 3499 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']); 3455 3500 $way = 'from the fragment (post-###)'; 3456 } elseif ( is_string($urltest['fragment'])) {3501 } elseif (is_string($urltest['fragment'])) { 3457 3502 // ...or a string #title, a little more complicated 3458 3503 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); 3459 $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", like_escape( $title ));3460 if (! ($post_ID = $wpdb->get_var($sql))) {3504 $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", like_escape($title)); 3505 if (!($post_ID = $wpdb->get_var($sql))) { 3461 3506 // returning unknown error '0' is better than die()ing 3462 3507 return new IXR_Error(0, ''); 3463 3508 } … … 3470 3515 $post_ID = (int) $post_ID; 3471 3516 3472 3517 3473 logIO("O","(PB) URL='$pagelinkedto' ID='$post_ID' Found='$way'");3518 logIO("O", "(PB) URL='$pagelinkedto' ID='$post_ID' Found='$way'"); 3474 3519 3475 3520 $post = get_post($post_ID); 3476 3521 3477 if ( !$post) // Post_ID not found3522 if (!$post) // Post_ID not found 3478 3523 return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.')); 3479 3524 3480 if ( $post_ID == url_to_postid($pagelinkedfrom))3525 if ($post_ID == url_to_postid($pagelinkedfrom)) 3481 3526 return new IXR_Error(0, __('The source URL and the target URL cannot both point to the same resource.')); 3482 3527 3483 3528 // Check if pings are on 3484 if ( !pings_open($post))3529 if (!pings_open($post)) 3485 3530 return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.')); 3486 3531 3487 3532 // Let's check that the remote site didn't already pingback this entry 3488 if ( $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ))3489 return new IXR_Error( 48, __( 'The pingback has already been registered.' ));3533 if ($wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom))) 3534 return new IXR_Error(48, __('The pingback has already been registered.')); 3490 3535 3491 3536 // very stupid, but gives time to the 'from' server to publish ! 3492 3537 sleep(1); 3493 3538 3494 3539 // Let's check the remote site 3495 $linea = wp_remote_fopen( $pagelinkedfrom);3496 if ( !$linea)3540 $linea = wp_remote_fopen($pagelinkedfrom); 3541 if (!$linea) 3497 3542 return new IXR_Error(16, __('The source URL does not exist.')); 3498 3543 3499 3544 $linea = apply_filters('pre_remote_source', $linea, $pagelinkedto); 3500 3545 3501 3546 // Work around bug in strip_tags(): 3502 3547 $linea = str_replace('<!DOC', '<DOC', $linea); 3503 $linea = preg_replace( '/[\s\r\n\t]+/', ' ', $linea); // normalize spaces3504 $linea = preg_replace( "/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea);3548 $linea = preg_replace('/[\s\r\n\t]+/', ' ', $linea); // normalize spaces 3549 $linea = preg_replace("/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea); 3505 3550 3506 3551 preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle); 3507 3552 $title = $matchtitle[1]; 3508 if ( empty( $title ))3553 if (empty($title)) 3509 3554 return new IXR_Error(32, __('We cannot find a title on that page.')); 3510 3555 3511 $linea = strip_tags( $linea, '<a>'); // just keep the tag we need3556 $linea = strip_tags($linea, '<a>'); // just keep the tag we need 3512 3557 3513 $p = explode( "\n\n", $linea);3558 $p = explode("\n\n", $linea); 3514 3559 3515 3560 $preg_target = preg_quote($pagelinkedto, '|'); 3516 3561 3517 foreach ( $p as $para) {3518 if ( strpos($para, $pagelinkedto) !== false) { // it exists, but is it a link?3519 preg_match("|<a[^>]+?".$preg_target."[^>]*>([^>]+?)</a>|", $para, $context);3562 foreach ($p as $para) { 3563 if (strpos($para, $pagelinkedto) !== false) { // it exists, but is it a link? 3564 preg_match("|<a[^>]+?" . $preg_target . "[^>]*>([^>]+?)</a>|", $para, $context); 3520 3565 3521 3566 // If the URL isn't in a link context, keep looking 3522 if ( empty($context))3567 if (empty($context)) 3523 3568 continue; 3524 3569 3525 3570 // We're going to use this fake tag to mark the context in a bit … … 3527 3572 $excerpt = preg_replace('|\</?wpcontext\>|', '', $para); 3528 3573 3529 3574 // prevent really long link text 3530 if ( strlen($context[1]) > 100)3575 if (strlen($context[1]) > 100) 3531 3576 $context[1] = substr($context[1], 0, 100) . '...'; 3532 3577 3533 $marker = '<wpcontext>'.$context[1].'</wpcontext>'; // set up our marker3534 $excerpt= str_replace($context[0], $marker, $excerpt); // swap out the link for our marker3578 $marker = '<wpcontext>' . $context[1] . '</wpcontext>'; // set up our marker 3579 $excerpt = str_replace($context[0], $marker, $excerpt); // swap out the link for our marker 3535 3580 $excerpt = strip_tags($excerpt, '<wpcontext>'); // strip all tags but our context marker 3536 3581 $excerpt = trim($excerpt); 3537 3582 $preg_marker = preg_quote($marker, '|'); … … 3541 3586 } 3542 3587 } 3543 3588 3544 if ( empty($context)) // Link to target not found3589 if (empty($context)) // Link to target not found 3545 3590 return new IXR_Error(17, __('The source URL does not contain a link to the target URL, and so cannot be used as a source.')); 3546 3591 3547 3592 $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom); 3548 3593 3549 $context = '[...] ' . esc_html( $excerpt) . ' [...]';3550 $pagelinkedfrom = $wpdb->escape( $pagelinkedfrom);3594 $context = '[...] ' . esc_html($excerpt) . ' [...]'; 3595 $pagelinkedfrom = $wpdb->escape($pagelinkedfrom); 3551 3596 3552 3597 $comment_post_ID = (int) $post_ID; 3553 3598 $comment_author = $title; … … 3587 3632 $url = $args; 3588 3633 3589 3634 $post_ID = url_to_postid($url); 3590 if ( !$post_ID) {3635 if (!$post_ID) { 3591 3636 // We aren't sure that the resource is available and/or pingback enabled 3592 3637 return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.')); 3593 3638 } 3594 3639 3595 3640 $actual_post = wp_get_single_post($post_ID, ARRAY_A); 3596 3641 3597 if ( !$actual_post) {3642 if (!$actual_post) { 3598 3643 // No such post = resource not found 3599 3644 return new IXR_Error(32, __('The specified target URL does not exist.')); 3600 3645 } 3601 3646 3602 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID));3647 $comments = $wpdb->get_results($wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID)); 3603 3648 3604 if ( !$comments)3649 if (!$comments) 3605 3650 return array(); 3606 3651 3607 3652 $pingbacks = array(); 3608 foreach ( $comments as $comment) {3609 if ( 'pingback' == $comment->comment_type)3653 foreach ($comments as $comment) { 3654 if ('pingback' == $comment->comment_type) 3610 3655 $pingbacks[] = $comment->comment_author_url; 3611 3656 } 3612 3657 3613 3658 return $pingbacks; 3614 3659 } 3660 3615 3661 } 3662 3616 3663 ?>