mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * XML-RPC protocol support for WordPress
mp-wp_genesis 4 *
mp-wp_genesis 5 * @license GPL v2 <./license.txt>
mp-wp_genesis 6 * @package WordPress
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Whether this is a XMLRPC Request
mp-wp_genesis 11 *
mp-wp_genesis 12 * @var bool
mp-wp_genesis 13 */
mp-wp_genesis 14 define('XMLRPC_REQUEST', true);
mp-wp_genesis 15
mp-wp_genesis 16 // Some browser-embedded clients send cookies. We don't want them.
mp-wp_genesis 17 $_COOKIE = array();
mp-wp_genesis 18
mp-wp_genesis 19 // A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default,
mp-wp_genesis 20 // but we can do it ourself.
mp-wp_genesis 21 if ( !isset( $HTTP_RAW_POST_DATA ) ) {
mp-wp_genesis 22 $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
mp-wp_genesis 23 }
mp-wp_genesis 24
mp-wp_genesis 25 // fix for mozBlog and other cases where '<?xml' isn't on the very first line
mp-wp_genesis 26 if ( isset($HTTP_RAW_POST_DATA) )
mp-wp_genesis 27 $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
mp-wp_genesis 28
mp-wp_genesis 29 /** Include the bootstrap for setting up WordPress environment */
mp-wp_genesis 30 include('./wp-load.php');
mp-wp_genesis 31
mp-wp_genesis 32 if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd
mp-wp_genesis 33 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
mp-wp_genesis 34 ?>
mp-wp_genesis 35 <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
mp-wp_genesis 36 <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
mp-wp_genesis 37 <service>
mp-wp_genesis 38 <engineName>WordPress</engineName>
mp-wp_genesis 39 <engineLink>http://wordpress.org/</engineLink>
mp-wp_genesis 40 <homePageLink><?php bloginfo_rss('url') ?></homePageLink>
mp-wp_genesis 41 <apis>
mp-wp_genesis 42 <api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url('xmlrpc.php') ?>" />
mp-wp_genesis 43 <api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php') ?>" />
mp-wp_genesis 44 <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php') ?>" />
mp-wp_genesis 45 <api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php') ?>" />
mp-wp_genesis 46 <api name="Atom" blogID="" preferred="false" apiLink="<?php echo apply_filters('atom_service_url', site_url('wp-app.php/service') ) ?>" />
mp-wp_genesis 47 </apis>
mp-wp_genesis 48 </service>
mp-wp_genesis 49 </rsd>
mp-wp_genesis 50 <?php
mp-wp_genesis 51 exit;
mp-wp_genesis 52 }
mp-wp_genesis 53
mp-wp_genesis 54 include_once(ABSPATH . 'wp-admin/includes/admin.php');
mp-wp_genesis 55 include_once(ABSPATH . WPINC . '/class-IXR.php');
mp-wp_genesis 56
mp-wp_genesis 57 // Turn off all warnings and errors.
mp-wp_genesis 58 // error_reporting(0);
mp-wp_genesis 59
mp-wp_genesis 60 /**
mp-wp_genesis 61 * Posts submitted via the xmlrpc interface get that title
mp-wp_genesis 62 * @name post_default_title
mp-wp_genesis 63 * @var string
mp-wp_genesis 64 */
mp-wp_genesis 65 $post_default_title = "";
mp-wp_genesis 66
mp-wp_genesis 67 /**
mp-wp_genesis 68 * Whether to enable XMLRPC Logging.
mp-wp_genesis 69 *
mp-wp_genesis 70 * @name xmlrpc_logging
mp-wp_genesis 71 * @var int|bool
mp-wp_genesis 72 */
mp-wp_genesis 73 $xmlrpc_logging = 0;
mp-wp_genesis 74
mp-wp_genesis 75 /**
mp-wp_genesis 76 * logIO() - Writes logging info to a file.
mp-wp_genesis 77 *
mp-wp_genesis 78 * @uses $xmlrpc_logging
mp-wp_genesis 79 * @package WordPress
mp-wp_genesis 80 * @subpackage Logging
mp-wp_genesis 81 *
mp-wp_genesis 82 * @param string $io Whether input or output
mp-wp_genesis 83 * @param string $msg Information describing logging reason.
mp-wp_genesis 84 * @return bool Always return true
mp-wp_genesis 85 */
mp-wp_genesis 86 function logIO($io,$msg) {
mp-wp_genesis 87 global $xmlrpc_logging;
mp-wp_genesis 88 if ($xmlrpc_logging) {
mp-wp_genesis 89 $fp = fopen("../xmlrpc.log","a+");
mp-wp_genesis 90 $date = gmdate("Y-m-d H:i:s ");
mp-wp_genesis 91 $iot = ($io == "I") ? " Input: " : " Output: ";
mp-wp_genesis 92 fwrite($fp, "\n\n".$date.$iot.$msg);
mp-wp_genesis 93 fclose($fp);
mp-wp_genesis 94 }
mp-wp_genesis 95 return true;
mp-wp_genesis 96 }
mp-wp_genesis 97
mp-wp_genesis 98 if ( isset($HTTP_RAW_POST_DATA) )
mp-wp_genesis 99 logIO("I", $HTTP_RAW_POST_DATA);
mp-wp_genesis 100
mp-wp_genesis 101 /**
mp-wp_genesis 102 * WordPress XMLRPC server implementation.
mp-wp_genesis 103 *
mp-wp_genesis 104 * Implements compatability for Blogger API, MetaWeblog API, MovableType, and
mp-wp_genesis 105 * pingback. Additional WordPress API for managing comments, pages, posts,
mp-wp_genesis 106 * options, etc.
mp-wp_genesis 107 *
mp-wp_genesis 108 * Since WordPress 2.6.0, WordPress XMLRPC server can be disabled in the
mp-wp_genesis 109 * administration panels.
mp-wp_genesis 110 *
mp-wp_genesis 111 * @package WordPress
mp-wp_genesis 112 * @subpackage Publishing
mp-wp_genesis 113 * @since 1.5.0
mp-wp_genesis 114 */
mp-wp_genesis 115 class wp_xmlrpc_server extends IXR_Server {
mp-wp_genesis 116
mp-wp_genesis 117 /**
mp-wp_genesis 118 * Register all of the XMLRPC methods that XMLRPC server understands.
mp-wp_genesis 119 *
mp-wp_genesis 120 * PHP4 constructor and sets up server and method property. Passes XMLRPC
mp-wp_genesis 121 * methods through the 'xmlrpc_methods' filter to allow plugins to extend
mp-wp_genesis 122 * or replace XMLRPC methods.
mp-wp_genesis 123 *
mp-wp_genesis 124 * @since 1.5.0
mp-wp_genesis 125 *
mp-wp_genesis 126 * @return wp_xmlrpc_server
mp-wp_genesis 127 */
mp-wp_genesis 128 function wp_xmlrpc_server() {
mp-wp_genesis 129 $this->methods = array(
mp-wp_genesis 130 // Close all but pingback!
mp-wp_genesis 131 /*
mp-wp_genesis 132 // WordPress API
mp-wp_genesis 133 'wp.getUsersBlogs' => 'this:wp_getUsersBlogs',
mp-wp_genesis 134 'wp.getPage' => 'this:wp_getPage',
mp-wp_genesis 135 'wp.getPages' => 'this:wp_getPages',
mp-wp_genesis 136 'wp.newPage' => 'this:wp_newPage',
mp-wp_genesis 137 'wp.deletePage' => 'this:wp_deletePage',
mp-wp_genesis 138 'wp.editPage' => 'this:wp_editPage',
mp-wp_genesis 139 'wp.getPageList' => 'this:wp_getPageList',
mp-wp_genesis 140 'wp.getAuthors' => 'this:wp_getAuthors',
mp-wp_genesis 141 'wp.getCategories' => 'this:mw_getCategories', // Alias
mp-wp_genesis 142 'wp.getTags' => 'this:wp_getTags',
mp-wp_genesis 143 'wp.newCategory' => 'this:wp_newCategory',
mp-wp_genesis 144 'wp.deleteCategory' => 'this:wp_deleteCategory',
mp-wp_genesis 145 'wp.suggestCategories' => 'this:wp_suggestCategories',
mp-wp_genesis 146 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias
mp-wp_genesis 147 'wp.getCommentCount' => 'this:wp_getCommentCount',
mp-wp_genesis 148 'wp.getPostStatusList' => 'this:wp_getPostStatusList',
mp-wp_genesis 149 'wp.getPageStatusList' => 'this:wp_getPageStatusList',
mp-wp_genesis 150 'wp.getPageTemplates' => 'this:wp_getPageTemplates',
mp-wp_genesis 151 'wp.getOptions' => 'this:wp_getOptions',
mp-wp_genesis 152 'wp.setOptions' => 'this:wp_setOptions',
mp-wp_genesis 153 'wp.getComment' => 'this:wp_getComment',
mp-wp_genesis 154 'wp.getComments' => 'this:wp_getComments',
mp-wp_genesis 155 'wp.deleteComment' => 'this:wp_deleteComment',
mp-wp_genesis 156 'wp.editComment' => 'this:wp_editComment',
mp-wp_genesis 157 'wp.newComment' => 'this:wp_newComment',
mp-wp_genesis 158 'wp.getCommentStatusList' => 'this:wp_getCommentStatusList',
mp-wp_genesis 159
mp-wp_genesis 160 // Blogger API
mp-wp_genesis 161 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
mp-wp_genesis 162 'blogger.getUserInfo' => 'this:blogger_getUserInfo',
mp-wp_genesis 163 'blogger.getPost' => 'this:blogger_getPost',
mp-wp_genesis 164 'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
mp-wp_genesis 165 'blogger.getTemplate' => 'this:blogger_getTemplate',
mp-wp_genesis 166 'blogger.setTemplate' => 'this:blogger_setTemplate',
mp-wp_genesis 167 'blogger.newPost' => 'this:blogger_newPost',
mp-wp_genesis 168 'blogger.editPost' => 'this:blogger_editPost',
mp-wp_genesis 169 'blogger.deletePost' => 'this:blogger_deletePost',
mp-wp_genesis 170
mp-wp_genesis 171 // MetaWeblog API (with MT extensions to structs)
mp-wp_genesis 172 'metaWeblog.newPost' => 'this:mw_newPost',
mp-wp_genesis 173 'metaWeblog.editPost' => 'this:mw_editPost',
mp-wp_genesis 174 'metaWeblog.getPost' => 'this:mw_getPost',
mp-wp_genesis 175 'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
mp-wp_genesis 176 'metaWeblog.getCategories' => 'this:mw_getCategories',
mp-wp_genesis 177 'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
mp-wp_genesis 178
mp-wp_genesis 179 // MetaWeblog API aliases for Blogger API
mp-wp_genesis 180 // see http://www.xmlrpc.com/stories/storyReader$2460
mp-wp_genesis 181 'metaWeblog.deletePost' => 'this:blogger_deletePost',
mp-wp_genesis 182 'metaWeblog.getTemplate' => 'this:blogger_getTemplate',
mp-wp_genesis 183 'metaWeblog.setTemplate' => 'this:blogger_setTemplate',
mp-wp_genesis 184 'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
mp-wp_genesis 185
mp-wp_genesis 186 // MovableType API
mp-wp_genesis 187 'mt.getCategoryList' => 'this:mt_getCategoryList',
mp-wp_genesis 188 'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
mp-wp_genesis 189 'mt.getPostCategories' => 'this:mt_getPostCategories',
mp-wp_genesis 190 'mt.setPostCategories' => 'this:mt_setPostCategories',
mp-wp_genesis 191 'mt.supportedMethods' => 'this:mt_supportedMethods',
mp-wp_genesis 192 'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
mp-wp_genesis 193 'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
mp-wp_genesis 194 'mt.publishPost' => 'this:mt_publishPost',
mp-wp_genesis 195
mp-wp_genesis 196
mp-wp_genesis 197 'demo.sayHello' => 'this:sayHello',
mp-wp_genesis 198 'demo.addTwoNumbers' => 'this:addTwoNumbers'
mp-wp_genesis 199 */
mp-wp_genesis 200
mp-wp_genesis 201 // PingBack
mp-wp_genesis 202 'pingback.ping' => 'this:pingback_ping',
mp-wp_genesis 203 'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
mp-wp_genesis 204
mp-wp_genesis 205 );
mp-wp_genesis 206
mp-wp_genesis 207 $this->initialise_blog_option_info( );
mp-wp_genesis 208 $this->methods = apply_filters('xmlrpc_methods', $this->methods);
mp-wp_genesis 209 $this->IXR_Server($this->methods);
mp-wp_genesis 210 }
mp-wp_genesis 211
mp-wp_genesis 212 /**
mp-wp_genesis 213 * Test XMLRPC API by saying, "Hello!" to client.
mp-wp_genesis 214 *
mp-wp_genesis 215 * @since 1.5.0
mp-wp_genesis 216 *
mp-wp_genesis 217 * @param array $args Method Parameters.
mp-wp_genesis 218 * @return string
mp-wp_genesis 219 */
mp-wp_genesis 220 function sayHello($args) {
mp-wp_genesis 221 return 'Hello!';
mp-wp_genesis 222 }
mp-wp_genesis 223
mp-wp_genesis 224 /**
mp-wp_genesis 225 * Test XMLRPC API by adding two numbers for client.
mp-wp_genesis 226 *
mp-wp_genesis 227 * @since 1.5.0
mp-wp_genesis 228 *
mp-wp_genesis 229 * @param array $args Method Parameters.
mp-wp_genesis 230 * @return int
mp-wp_genesis 231 */
mp-wp_genesis 232 function addTwoNumbers($args) {
mp-wp_genesis 233 $number1 = $args[0];
mp-wp_genesis 234 $number2 = $args[1];
mp-wp_genesis 235 return $number1 + $number2;
mp-wp_genesis 236 }
mp-wp_genesis 237
mp-wp_genesis 238 /**
mp-wp_genesis 239 * Check user's credentials.
mp-wp_genesis 240 *
mp-wp_genesis 241 * @since 1.5.0
mp-wp_genesis 242 *
mp-wp_genesis 243 * @param string $user_login User's username.
mp-wp_genesis 244 * @param string $user_pass User's password.
mp-wp_genesis 245 * @return bool Whether authentication passed.
mp-wp_genesis 246 */
mp-wp_genesis 247 function login_pass_ok($user_login, $user_pass) {
mp-wp_genesis 248 if ( !get_option( 'enable_xmlrpc' ) ) {
mp-wp_genesis 249 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this blog. An admin user can enable them at %s'), admin_url('options-writing.php') ) );
mp-wp_genesis 250 return false;
mp-wp_genesis 251 }
mp-wp_genesis 252
mp-wp_genesis 253 if (!user_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 254 $this->error = new IXR_Error(403, __('Bad login/pass combination.'));
mp-wp_genesis 255 return false;
mp-wp_genesis 256 }
mp-wp_genesis 257 return true;
mp-wp_genesis 258 }
mp-wp_genesis 259
mp-wp_genesis 260 /**
mp-wp_genesis 261 * Sanitize string or array of strings for database.
mp-wp_genesis 262 *
mp-wp_genesis 263 * @since 1.5.2
mp-wp_genesis 264 *
mp-wp_genesis 265 * @param string|array $array Sanitize single string or array of strings.
mp-wp_genesis 266 * @return string|array Type matches $array and sanitized for the database.
mp-wp_genesis 267 */
mp-wp_genesis 268 function escape(&$array) {
mp-wp_genesis 269 global $wpdb;
mp-wp_genesis 270
mp-wp_genesis 271 if(!is_array($array)) {
mp-wp_genesis 272 return($wpdb->escape($array));
mp-wp_genesis 273 }
mp-wp_genesis 274 else {
mp-wp_genesis 275 foreach ( (array) $array as $k => $v ) {
mp-wp_genesis 276 if (is_array($v)) {
mp-wp_genesis 277 $this->escape($array[$k]);
mp-wp_genesis 278 } else if (is_object($v)) {
mp-wp_genesis 279 //skip
mp-wp_genesis 280 } else {
mp-wp_genesis 281 $array[$k] = $wpdb->escape($v);
mp-wp_genesis 282 }
mp-wp_genesis 283 }
mp-wp_genesis 284 }
mp-wp_genesis 285 }
mp-wp_genesis 286
mp-wp_genesis 287 /**
mp-wp_genesis 288 * Retrieve custom fields for post.
mp-wp_genesis 289 *
mp-wp_genesis 290 * @since 2.5.0
mp-wp_genesis 291 *
mp-wp_genesis 292 * @param int $post_id Post ID.
mp-wp_genesis 293 * @return array Custom fields, if exist.
mp-wp_genesis 294 */
mp-wp_genesis 295 function get_custom_fields($post_id) {
mp-wp_genesis 296 $post_id = (int) $post_id;
mp-wp_genesis 297
mp-wp_genesis 298 $custom_fields = array();
mp-wp_genesis 299
mp-wp_genesis 300 foreach ( (array) has_meta($post_id) as $meta ) {
mp-wp_genesis 301 // Don't expose protected fields.
mp-wp_genesis 302 if ( strpos($meta['meta_key'], '_wp_') === 0 ) {
mp-wp_genesis 303 continue;
mp-wp_genesis 304 }
mp-wp_genesis 305
mp-wp_genesis 306 $custom_fields[] = array(
mp-wp_genesis 307 "id" => $meta['meta_id'],
mp-wp_genesis 308 "key" => $meta['meta_key'],
mp-wp_genesis 309 "value" => $meta['meta_value']
mp-wp_genesis 310 );
mp-wp_genesis 311 }
mp-wp_genesis 312
mp-wp_genesis 313 return $custom_fields;
mp-wp_genesis 314 }
mp-wp_genesis 315
mp-wp_genesis 316 /**
mp-wp_genesis 317 * Set custom fields for post.
mp-wp_genesis 318 *
mp-wp_genesis 319 * @since 2.5.0
mp-wp_genesis 320 *
mp-wp_genesis 321 * @param int $post_id Post ID.
mp-wp_genesis 322 * @param array $fields Custom fields.
mp-wp_genesis 323 */
mp-wp_genesis 324 function set_custom_fields($post_id, $fields) {
mp-wp_genesis 325 $post_id = (int) $post_id;
mp-wp_genesis 326
mp-wp_genesis 327 foreach ( (array) $fields as $meta ) {
mp-wp_genesis 328 if ( isset($meta['id']) ) {
mp-wp_genesis 329 $meta['id'] = (int) $meta['id'];
mp-wp_genesis 330
mp-wp_genesis 331 if ( isset($meta['key']) ) {
mp-wp_genesis 332 update_meta($meta['id'], $meta['key'], $meta['value']);
mp-wp_genesis 333 }
mp-wp_genesis 334 else {
mp-wp_genesis 335 delete_meta($meta['id']);
mp-wp_genesis 336 }
mp-wp_genesis 337 }
mp-wp_genesis 338 else {
mp-wp_genesis 339 $_POST['metakeyinput'] = $meta['key'];
mp-wp_genesis 340 $_POST['metavalue'] = $meta['value'];
mp-wp_genesis 341 add_meta($post_id);
mp-wp_genesis 342 }
mp-wp_genesis 343 }
mp-wp_genesis 344 }
mp-wp_genesis 345
mp-wp_genesis 346 /**
mp-wp_genesis 347 * Setup blog options property.
mp-wp_genesis 348 *
mp-wp_genesis 349 * Passes property through 'xmlrpc_blog_options' filter.
mp-wp_genesis 350 *
mp-wp_genesis 351 * @since 2.6.0
mp-wp_genesis 352 */
mp-wp_genesis 353 function initialise_blog_option_info( ) {
mp-wp_genesis 354 global $wp_version;
mp-wp_genesis 355
mp-wp_genesis 356 $this->blog_options = array(
mp-wp_genesis 357 // Read only options
mp-wp_genesis 358 'software_name' => array(
mp-wp_genesis 359 'desc' => __( 'Software Name' ),
mp-wp_genesis 360 'readonly' => true,
mp-wp_genesis 361 'value' => 'WordPress'
mp-wp_genesis 362 ),
mp-wp_genesis 363 'software_version' => array(
mp-wp_genesis 364 'desc' => __( 'Software Version' ),
mp-wp_genesis 365 'readonly' => true,
mp-wp_genesis 366 'value' => $wp_version
mp-wp_genesis 367 ),
mp-wp_genesis 368 'blog_url' => array(
mp-wp_genesis 369 'desc' => __( 'Blog URL' ),
mp-wp_genesis 370 'readonly' => true,
mp-wp_genesis 371 'option' => 'siteurl'
mp-wp_genesis 372 ),
mp-wp_genesis 373
mp-wp_genesis 374 // Updatable options
mp-wp_genesis 375 'time_zone' => array(
mp-wp_genesis 376 'desc' => __( 'Time Zone' ),
mp-wp_genesis 377 'readonly' => false,
mp-wp_genesis 378 'option' => 'gmt_offset'
mp-wp_genesis 379 ),
mp-wp_genesis 380 'blog_title' => array(
mp-wp_genesis 381 'desc' => __( 'Blog Title' ),
mp-wp_genesis 382 'readonly' => false,
mp-wp_genesis 383 'option' => 'blogname'
mp-wp_genesis 384 ),
mp-wp_genesis 385 'blog_tagline' => array(
mp-wp_genesis 386 'desc' => __( 'Blog Tagline' ),
mp-wp_genesis 387 'readonly' => false,
mp-wp_genesis 388 'option' => 'blogdescription'
mp-wp_genesis 389 ),
mp-wp_genesis 390 'date_format' => array(
mp-wp_genesis 391 'desc' => __( 'Date Format' ),
mp-wp_genesis 392 'readonly' => false,
mp-wp_genesis 393 'option' => 'date_format'
mp-wp_genesis 394 ),
mp-wp_genesis 395 'time_format' => array(
mp-wp_genesis 396 'desc' => __( 'Time Format' ),
mp-wp_genesis 397 'readonly' => false,
mp-wp_genesis 398 'option' => 'time_format'
mp-wp_genesis 399 )
mp-wp_genesis 400 );
mp-wp_genesis 401
mp-wp_genesis 402 $this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options );
mp-wp_genesis 403 }
mp-wp_genesis 404
mp-wp_genesis 405 /**
mp-wp_genesis 406 * Retrieve the blogs of the user.
mp-wp_genesis 407 *
mp-wp_genesis 408 * @since 2.6.0
mp-wp_genesis 409 *
mp-wp_genesis 410 * @param array $args Method parameters.
mp-wp_genesis 411 * @return array
mp-wp_genesis 412 */
mp-wp_genesis 413 function wp_getUsersBlogs( $args ) {
mp-wp_genesis 414 // If this isn't on WPMU then just use blogger_getUsersBlogs
mp-wp_genesis 415 if( !function_exists( 'is_site_admin' ) ) {
mp-wp_genesis 416 array_unshift( $args, 1 );
mp-wp_genesis 417 return $this->blogger_getUsersBlogs( $args );
mp-wp_genesis 418 }
mp-wp_genesis 419
mp-wp_genesis 420 $this->escape( $args );
mp-wp_genesis 421
mp-wp_genesis 422 $username = $args[0];
mp-wp_genesis 423 $password = $args[1];
mp-wp_genesis 424
mp-wp_genesis 425 if( !$this->login_pass_ok( $username, $password ) )
mp-wp_genesis 426 return $this->error;
mp-wp_genesis 427
mp-wp_genesis 428 do_action( 'xmlrpc_call', 'wp.getUsersBlogs' );
mp-wp_genesis 429
mp-wp_genesis 430 $user = set_current_user( 0, $username );
mp-wp_genesis 431
mp-wp_genesis 432 $blogs = (array) get_blogs_of_user( $user->ID );
mp-wp_genesis 433 $struct = array( );
mp-wp_genesis 434
mp-wp_genesis 435 foreach( $blogs as $blog ) {
mp-wp_genesis 436 // Don't include blogs that aren't hosted at this site
mp-wp_genesis 437 if( $blog->site_id != $current_site->id )
mp-wp_genesis 438 continue;
mp-wp_genesis 439
mp-wp_genesis 440 $blog_id = $blog->userblog_id;
mp-wp_genesis 441 switch_to_blog($blog_id);
mp-wp_genesis 442 $is_admin = current_user_can('level_8');
mp-wp_genesis 443
mp-wp_genesis 444 $struct[] = array(
mp-wp_genesis 445 'isAdmin' => $is_admin,
mp-wp_genesis 446 'url' => get_option( 'home' ) . '/',
mp-wp_genesis 447 'blogid' => $blog_id,
mp-wp_genesis 448 'blogName' => get_option( 'blogname' ),
mp-wp_genesis 449 'xmlrpc' => get_option( 'home' ) . '/xmlrpc.php'
mp-wp_genesis 450 );
mp-wp_genesis 451
mp-wp_genesis 452 restore_current_blog( );
mp-wp_genesis 453 }
mp-wp_genesis 454
mp-wp_genesis 455 return $struct;
mp-wp_genesis 456 }
mp-wp_genesis 457
mp-wp_genesis 458 /**
mp-wp_genesis 459 * Retrieve page.
mp-wp_genesis 460 *
mp-wp_genesis 461 * @since 2.2.0
mp-wp_genesis 462 *
mp-wp_genesis 463 * @param array $args Method parameters.
mp-wp_genesis 464 * @return array
mp-wp_genesis 465 */
mp-wp_genesis 466 function wp_getPage($args) {
mp-wp_genesis 467 $this->escape($args);
mp-wp_genesis 468
mp-wp_genesis 469 $blog_id = (int) $args[0];
mp-wp_genesis 470 $page_id = (int) $args[1];
mp-wp_genesis 471 $username = $args[2];
mp-wp_genesis 472 $password = $args[3];
mp-wp_genesis 473
mp-wp_genesis 474 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 475 return($this->error);
mp-wp_genesis 476 }
mp-wp_genesis 477
mp-wp_genesis 478 set_current_user( 0, $username );
mp-wp_genesis 479 if( !current_user_can( 'edit_page', $page_id ) )
mp-wp_genesis 480 return new IXR_Error( 401, __( 'Sorry, you can not edit this page.' ) );
mp-wp_genesis 481
mp-wp_genesis 482 do_action('xmlrpc_call', 'wp.getPage');
mp-wp_genesis 483
mp-wp_genesis 484 // Lookup page info.
mp-wp_genesis 485 $page = get_page($page_id);
mp-wp_genesis 486
mp-wp_genesis 487 // If we found the page then format the data.
mp-wp_genesis 488 if($page->ID && ($page->post_type == "page")) {
mp-wp_genesis 489 // Get all of the page content and link.
mp-wp_genesis 490 $full_page = get_extended($page->post_content);
mp-wp_genesis 491 $link = post_permalink($page->ID);
mp-wp_genesis 492
mp-wp_genesis 493 // Get info the page parent if there is one.
mp-wp_genesis 494 $parent_title = "";
mp-wp_genesis 495 if(!empty($page->post_parent)) {
mp-wp_genesis 496 $parent = get_page($page->post_parent);
mp-wp_genesis 497 $parent_title = $parent->post_title;
mp-wp_genesis 498 }
mp-wp_genesis 499
mp-wp_genesis 500 // Determine comment and ping settings.
mp-wp_genesis 501 $allow_comments = ("open" == $page->comment_status) ? 1 : 0;
mp-wp_genesis 502 $allow_pings = ("open" == $page->ping_status) ? 1 : 0;
mp-wp_genesis 503
mp-wp_genesis 504 // Format page date.
mp-wp_genesis 505 $page_date = mysql2date("Ymd\TH:i:s", $page->post_date);
mp-wp_genesis 506 $page_date_gmt = mysql2date("Ymd\TH:i:s", $page->post_date_gmt);
mp-wp_genesis 507
mp-wp_genesis 508 // Pull the categories info together.
mp-wp_genesis 509 $categories = array();
mp-wp_genesis 510 foreach(wp_get_post_categories($page->ID) as $cat_id) {
mp-wp_genesis 511 $categories[] = get_cat_name($cat_id);
mp-wp_genesis 512 }
mp-wp_genesis 513
mp-wp_genesis 514 // Get the author info.
mp-wp_genesis 515 $author = get_userdata($page->post_author);
mp-wp_genesis 516
mp-wp_genesis 517 $page_template = get_post_meta( $page->ID, '_wp_page_template', true );
mp-wp_genesis 518 if( empty( $page_template ) )
mp-wp_genesis 519 $page_template = 'default';
mp-wp_genesis 520
mp-wp_genesis 521 $page_struct = array(
mp-wp_genesis 522 "dateCreated" => new IXR_Date($page_date),
mp-wp_genesis 523 "userid" => $page->post_author,
mp-wp_genesis 524 "page_id" => $page->ID,
mp-wp_genesis 525 "page_status" => $page->post_status,
mp-wp_genesis 526 "description" => $full_page["main"],
mp-wp_genesis 527 "title" => $page->post_title,
mp-wp_genesis 528 "link" => $link,
mp-wp_genesis 529 "permaLink" => $link,
mp-wp_genesis 530 "categories" => $categories,
mp-wp_genesis 531 "excerpt" => $page->post_excerpt,
mp-wp_genesis 532 "text_more" => $full_page["extended"],
mp-wp_genesis 533 "mt_allow_comments" => $allow_comments,
mp-wp_genesis 534 "mt_allow_pings" => $allow_pings,
mp-wp_genesis 535 "wp_slug" => $page->post_name,
mp-wp_genesis 536 "wp_password" => $page->post_password,
mp-wp_genesis 537 "wp_author" => $author->display_name,
mp-wp_genesis 538 "wp_page_parent_id" => $page->post_parent,
mp-wp_genesis 539 "wp_page_parent_title" => $parent_title,
mp-wp_genesis 540 "wp_page_order" => $page->menu_order,
mp-wp_genesis 541 "wp_author_id" => $author->ID,
mp-wp_genesis 542 "wp_author_display_name" => $author->display_name,
mp-wp_genesis 543 "date_created_gmt" => new IXR_Date($page_date_gmt),
mp-wp_genesis 544 "custom_fields" => $this->get_custom_fields($page_id),
mp-wp_genesis 545 "wp_page_template" => $page_template
mp-wp_genesis 546 );
mp-wp_genesis 547
mp-wp_genesis 548 return($page_struct);
mp-wp_genesis 549 }
mp-wp_genesis 550 // If the page doesn't exist indicate that.
mp-wp_genesis 551 else {
mp-wp_genesis 552 return(new IXR_Error(404, __("Sorry, no such page.")));
mp-wp_genesis 553 }
mp-wp_genesis 554 }
mp-wp_genesis 555
mp-wp_genesis 556 /**
mp-wp_genesis 557 * Retrieve Pages.
mp-wp_genesis 558 *
mp-wp_genesis 559 * @since 2.2.0
mp-wp_genesis 560 *
mp-wp_genesis 561 * @param array $args Method parameters.
mp-wp_genesis 562 * @return array
mp-wp_genesis 563 */
mp-wp_genesis 564 function wp_getPages($args) {
mp-wp_genesis 565 $this->escape($args);
mp-wp_genesis 566
mp-wp_genesis 567 $blog_id = (int) $args[0];
mp-wp_genesis 568 $username = $args[1];
mp-wp_genesis 569 $password = $args[2];
mp-wp_genesis 570 $num_pages = (int) $args[3];
mp-wp_genesis 571
mp-wp_genesis 572 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 573 return($this->error);
mp-wp_genesis 574 }
mp-wp_genesis 575
mp-wp_genesis 576 set_current_user( 0, $username );
mp-wp_genesis 577 if( !current_user_can( 'edit_pages' ) )
mp-wp_genesis 578 return new IXR_Error( 401, __( 'Sorry, you can not edit pages.' ) );
mp-wp_genesis 579
mp-wp_genesis 580 do_action('xmlrpc_call', 'wp.getPages');
mp-wp_genesis 581
mp-wp_genesis 582 $page_limit = 10;
mp-wp_genesis 583 if( isset( $num_pages ) ) {
mp-wp_genesis 584 $page_limit = $num_pages;
mp-wp_genesis 585 }
mp-wp_genesis 586
mp-wp_genesis 587 $pages = get_posts( "post_type=page&post_status=all&numberposts={$page_limit}" );
mp-wp_genesis 588 $num_pages = count($pages);
mp-wp_genesis 589
mp-wp_genesis 590 // If we have pages, put together their info.
mp-wp_genesis 591 if($num_pages >= 1) {
mp-wp_genesis 592 $pages_struct = array();
mp-wp_genesis 593
mp-wp_genesis 594 for($i = 0; $i < $num_pages; $i++) {
mp-wp_genesis 595 $page = wp_xmlrpc_server::wp_getPage(array(
mp-wp_genesis 596 $blog_id, $pages[$i]->ID, $username, $password
mp-wp_genesis 597 ));
mp-wp_genesis 598 $pages_struct[] = $page;
mp-wp_genesis 599 }
mp-wp_genesis 600
mp-wp_genesis 601 return($pages_struct);
mp-wp_genesis 602 }
mp-wp_genesis 603 // If no pages were found return an error.
mp-wp_genesis 604 else {
mp-wp_genesis 605 return(array());
mp-wp_genesis 606 }
mp-wp_genesis 607 }
mp-wp_genesis 608
mp-wp_genesis 609 /**
mp-wp_genesis 610 * Create new page.
mp-wp_genesis 611 *
mp-wp_genesis 612 * @since 2.2.0
mp-wp_genesis 613 *
mp-wp_genesis 614 * @param array $args Method parameters.
mp-wp_genesis 615 * @return unknown
mp-wp_genesis 616 */
mp-wp_genesis 617 function wp_newPage($args) {
mp-wp_genesis 618 // Items not escaped here will be escaped in newPost.
mp-wp_genesis 619 $username = $this->escape($args[1]);
mp-wp_genesis 620 $password = $this->escape($args[2]);
mp-wp_genesis 621 $page = $args[3];
mp-wp_genesis 622 $publish = $args[4];
mp-wp_genesis 623
mp-wp_genesis 624 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 625 return($this->error);
mp-wp_genesis 626 }
mp-wp_genesis 627
mp-wp_genesis 628 do_action('xmlrpc_call', 'wp.newPage');
mp-wp_genesis 629
mp-wp_genesis 630 // Set the user context and check if they are allowed
mp-wp_genesis 631 // to add new pages.
mp-wp_genesis 632 $user = set_current_user(0, $username);
mp-wp_genesis 633 if(!current_user_can("publish_pages")) {
mp-wp_genesis 634 return(new IXR_Error(401, __("Sorry, you can not add new pages.")));
mp-wp_genesis 635 }
mp-wp_genesis 636
mp-wp_genesis 637 // Mark this as content for a page.
mp-wp_genesis 638 $args[3]["post_type"] = "page";
mp-wp_genesis 639
mp-wp_genesis 640 // Let mw_newPost do all of the heavy lifting.
mp-wp_genesis 641 return($this->mw_newPost($args));
mp-wp_genesis 642 }
mp-wp_genesis 643
mp-wp_genesis 644 /**
mp-wp_genesis 645 * Delete page.
mp-wp_genesis 646 *
mp-wp_genesis 647 * @since 2.2.0
mp-wp_genesis 648 *
mp-wp_genesis 649 * @param array $args Method parameters.
mp-wp_genesis 650 * @return bool True, if success.
mp-wp_genesis 651 */
mp-wp_genesis 652 function wp_deletePage($args) {
mp-wp_genesis 653 $this->escape($args);
mp-wp_genesis 654
mp-wp_genesis 655 $blog_id = (int) $args[0];
mp-wp_genesis 656 $username = $args[1];
mp-wp_genesis 657 $password = $args[2];
mp-wp_genesis 658 $page_id = (int) $args[3];
mp-wp_genesis 659
mp-wp_genesis 660 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 661 return($this->error);
mp-wp_genesis 662 }
mp-wp_genesis 663
mp-wp_genesis 664 do_action('xmlrpc_call', 'wp.deletePage');
mp-wp_genesis 665
mp-wp_genesis 666 // Get the current page based on the page_id and
mp-wp_genesis 667 // make sure it is a page and not a post.
mp-wp_genesis 668 $actual_page = wp_get_single_post($page_id, ARRAY_A);
mp-wp_genesis 669 if(
mp-wp_genesis 670 !$actual_page
mp-wp_genesis 671 || ($actual_page["post_type"] != "page")
mp-wp_genesis 672 ) {
mp-wp_genesis 673 return(new IXR_Error(404, __("Sorry, no such page.")));
mp-wp_genesis 674 }
mp-wp_genesis 675
mp-wp_genesis 676 // Set the user context and make sure they can delete pages.
mp-wp_genesis 677 set_current_user(0, $username);
mp-wp_genesis 678 if(!current_user_can("delete_page", $page_id)) {
mp-wp_genesis 679 return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page.")));
mp-wp_genesis 680 }
mp-wp_genesis 681
mp-wp_genesis 682 // Attempt to delete the page.
mp-wp_genesis 683 $result = wp_delete_post($page_id);
mp-wp_genesis 684 if(!$result) {
mp-wp_genesis 685 return(new IXR_Error(500, __("Failed to delete the page.")));
mp-wp_genesis 686 }
mp-wp_genesis 687
mp-wp_genesis 688 return(true);
mp-wp_genesis 689 }
mp-wp_genesis 690
mp-wp_genesis 691 /**
mp-wp_genesis 692 * Edit page.
mp-wp_genesis 693 *
mp-wp_genesis 694 * @since 2.2.0
mp-wp_genesis 695 *
mp-wp_genesis 696 * @param array $args Method parameters.
mp-wp_genesis 697 * @return unknown
mp-wp_genesis 698 */
mp-wp_genesis 699 function wp_editPage($args) {
mp-wp_genesis 700 // Items not escaped here will be escaped in editPost.
mp-wp_genesis 701 $blog_id = (int) $args[0];
mp-wp_genesis 702 $page_id = (int) $this->escape($args[1]);
mp-wp_genesis 703 $username = $this->escape($args[2]);
mp-wp_genesis 704 $password = $this->escape($args[3]);
mp-wp_genesis 705 $content = $args[4];
mp-wp_genesis 706 $publish = $args[5];
mp-wp_genesis 707
mp-wp_genesis 708 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 709 return($this->error);
mp-wp_genesis 710 }
mp-wp_genesis 711
mp-wp_genesis 712 do_action('xmlrpc_call', 'wp.editPage');
mp-wp_genesis 713
mp-wp_genesis 714 // Get the page data and make sure it is a page.
mp-wp_genesis 715 $actual_page = wp_get_single_post($page_id, ARRAY_A);
mp-wp_genesis 716 if(
mp-wp_genesis 717 !$actual_page
mp-wp_genesis 718 || ($actual_page["post_type"] != "page")
mp-wp_genesis 719 ) {
mp-wp_genesis 720 return(new IXR_Error(404, __("Sorry, no such page.")));
mp-wp_genesis 721 }
mp-wp_genesis 722
mp-wp_genesis 723 // Set the user context and make sure they are allowed to edit pages.
mp-wp_genesis 724 set_current_user(0, $username);
mp-wp_genesis 725 if(!current_user_can("edit_page", $page_id)) {
mp-wp_genesis 726 return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page.")));
mp-wp_genesis 727 }
mp-wp_genesis 728
mp-wp_genesis 729 // Mark this as content for a page.
mp-wp_genesis 730 $content["post_type"] = "page";
mp-wp_genesis 731
mp-wp_genesis 732 // Arrange args in the way mw_editPost understands.
mp-wp_genesis 733 $args = array(
mp-wp_genesis 734 $page_id,
mp-wp_genesis 735 $username,
mp-wp_genesis 736 $password,
mp-wp_genesis 737 $content,
mp-wp_genesis 738 $publish
mp-wp_genesis 739 );
mp-wp_genesis 740
mp-wp_genesis 741 // Let mw_editPost do all of the heavy lifting.
mp-wp_genesis 742 return($this->mw_editPost($args));
mp-wp_genesis 743 }
mp-wp_genesis 744
mp-wp_genesis 745 /**
mp-wp_genesis 746 * Retrieve page list.
mp-wp_genesis 747 *
mp-wp_genesis 748 * @since 2.2.0
mp-wp_genesis 749 *
mp-wp_genesis 750 * @param array $args Method parameters.
mp-wp_genesis 751 * @return unknown
mp-wp_genesis 752 */
mp-wp_genesis 753 function wp_getPageList($args) {
mp-wp_genesis 754 global $wpdb;
mp-wp_genesis 755
mp-wp_genesis 756 $this->escape($args);
mp-wp_genesis 757
mp-wp_genesis 758 $blog_id = (int) $args[0];
mp-wp_genesis 759 $username = $args[1];
mp-wp_genesis 760 $password = $args[2];
mp-wp_genesis 761
mp-wp_genesis 762 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 763 return($this->error);
mp-wp_genesis 764 }
mp-wp_genesis 765
mp-wp_genesis 766 set_current_user( 0, $username );
mp-wp_genesis 767 if( !current_user_can( 'edit_pages' ) )
mp-wp_genesis 768 return new IXR_Error( 401, __( 'Sorry, you can not edit pages.' ) );
mp-wp_genesis 769
mp-wp_genesis 770 do_action('xmlrpc_call', 'wp.getPageList');
mp-wp_genesis 771
mp-wp_genesis 772 // Get list of pages ids and titles
mp-wp_genesis 773 $page_list = $wpdb->get_results("
mp-wp_genesis 774 SELECT ID page_id,
mp-wp_genesis 775 post_title page_title,
mp-wp_genesis 776 post_parent page_parent_id,
mp-wp_genesis 777 post_date_gmt,
mp-wp_genesis 778 post_date
mp-wp_genesis 779 FROM {$wpdb->posts}
mp-wp_genesis 780 WHERE post_type = 'page'
mp-wp_genesis 781 ORDER BY ID
mp-wp_genesis 782 ");
mp-wp_genesis 783
mp-wp_genesis 784 // The date needs to be formated properly.
mp-wp_genesis 785 $num_pages = count($page_list);
mp-wp_genesis 786 for($i = 0; $i < $num_pages; $i++) {
mp-wp_genesis 787 $post_date = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date);
mp-wp_genesis 788 $post_date_gmt = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date_gmt);
mp-wp_genesis 789
mp-wp_genesis 790 $page_list[$i]->dateCreated = new IXR_Date($post_date);
mp-wp_genesis 791 $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
mp-wp_genesis 792
mp-wp_genesis 793 unset($page_list[$i]->post_date_gmt);
mp-wp_genesis 794 unset($page_list[$i]->post_date);
mp-wp_genesis 795 }
mp-wp_genesis 796
mp-wp_genesis 797 return($page_list);
mp-wp_genesis 798 }
mp-wp_genesis 799
mp-wp_genesis 800 /**
mp-wp_genesis 801 * Retrieve authors list.
mp-wp_genesis 802 *
mp-wp_genesis 803 * @since 2.2.0
mp-wp_genesis 804 *
mp-wp_genesis 805 * @param array $args Method parameters.
mp-wp_genesis 806 * @return array
mp-wp_genesis 807 */
mp-wp_genesis 808 function wp_getAuthors($args) {
mp-wp_genesis 809
mp-wp_genesis 810 $this->escape($args);
mp-wp_genesis 811
mp-wp_genesis 812 $blog_id = (int) $args[0];
mp-wp_genesis 813 $username = $args[1];
mp-wp_genesis 814 $password = $args[2];
mp-wp_genesis 815
mp-wp_genesis 816 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 817 return($this->error);
mp-wp_genesis 818 }
mp-wp_genesis 819
mp-wp_genesis 820 set_current_user(0, $username);
mp-wp_genesis 821 if(!current_user_can("edit_posts")) {
mp-wp_genesis 822 return(new IXR_Error(401, __("Sorry, you can not edit posts on this blog.")));
mp-wp_genesis 823 }
mp-wp_genesis 824
mp-wp_genesis 825 do_action('xmlrpc_call', 'wp.getAuthors');
mp-wp_genesis 826
mp-wp_genesis 827 $authors = array();
mp-wp_genesis 828 foreach( (array) get_users_of_blog() as $row ) {
mp-wp_genesis 829 $authors[] = array(
mp-wp_genesis 830 "user_id" => $row->user_id,
mp-wp_genesis 831 "user_login" => $row->user_login,
mp-wp_genesis 832 "display_name" => $row->display_name
mp-wp_genesis 833 );
mp-wp_genesis 834 }
mp-wp_genesis 835
mp-wp_genesis 836 return($authors);
mp-wp_genesis 837 }
mp-wp_genesis 838
mp-wp_genesis 839 /**
mp-wp_genesis 840 * Get list of all tags
mp-wp_genesis 841 *
mp-wp_genesis 842 * @since 2.7
mp-wp_genesis 843 *
mp-wp_genesis 844 * @param array $args Method parameters.
mp-wp_genesis 845 * @return array
mp-wp_genesis 846 */
mp-wp_genesis 847 function wp_getTags( $args ) {
mp-wp_genesis 848 $this->escape( $args );
mp-wp_genesis 849
mp-wp_genesis 850 $blog_id = (int) $args[0];
mp-wp_genesis 851 $username = $args[1];
mp-wp_genesis 852 $password = $args[2];
mp-wp_genesis 853
mp-wp_genesis 854 if( !$this->login_pass_ok( $username, $password ) ) {
mp-wp_genesis 855 return $this->error;
mp-wp_genesis 856 }
mp-wp_genesis 857
mp-wp_genesis 858 set_current_user( 0, $username );
mp-wp_genesis 859 if( !current_user_can( 'edit_posts' ) ) {
mp-wp_genesis 860 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view tags.' ) );
mp-wp_genesis 861 }
mp-wp_genesis 862
mp-wp_genesis 863 do_action( 'xmlrpc_call', 'wp.getKeywords' );
mp-wp_genesis 864
mp-wp_genesis 865 $tags = array( );
mp-wp_genesis 866
mp-wp_genesis 867 if( $all_tags = get_tags( ) ) {
mp-wp_genesis 868 foreach( (array) $all_tags as $tag ) {
mp-wp_genesis 869 $struct['tag_id'] = $tag->term_id;
mp-wp_genesis 870 $struct['name'] = $tag->name;
mp-wp_genesis 871 $struct['count'] = $tag->count;
mp-wp_genesis 872 $struct['slug'] = $tag->slug;
mp-wp_genesis 873 $struct['html_url'] = wp_specialchars( get_tag_link( $tag->term_id ) );
mp-wp_genesis 874 $struct['rss_url'] = wp_specialchars( get_tag_feed_link( $tag->term_id ) );
mp-wp_genesis 875
mp-wp_genesis 876 $tags[] = $struct;
mp-wp_genesis 877 }
mp-wp_genesis 878 }
mp-wp_genesis 879
mp-wp_genesis 880 return $tags;
mp-wp_genesis 881 }
mp-wp_genesis 882
mp-wp_genesis 883 /**
mp-wp_genesis 884 * Create new category.
mp-wp_genesis 885 *
mp-wp_genesis 886 * @since 2.2.0
mp-wp_genesis 887 *
mp-wp_genesis 888 * @param array $args Method parameters.
mp-wp_genesis 889 * @return int Category ID.
mp-wp_genesis 890 */
mp-wp_genesis 891 function wp_newCategory($args) {
mp-wp_genesis 892 $this->escape($args);
mp-wp_genesis 893
mp-wp_genesis 894 $blog_id = (int) $args[0];
mp-wp_genesis 895 $username = $args[1];
mp-wp_genesis 896 $password = $args[2];
mp-wp_genesis 897 $category = $args[3];
mp-wp_genesis 898
mp-wp_genesis 899 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 900 return($this->error);
mp-wp_genesis 901 }
mp-wp_genesis 902
mp-wp_genesis 903 do_action('xmlrpc_call', 'wp.newCategory');
mp-wp_genesis 904
mp-wp_genesis 905 // Set the user context and make sure they are
mp-wp_genesis 906 // allowed to add a category.
mp-wp_genesis 907 set_current_user(0, $username);
mp-wp_genesis 908 if(!current_user_can("manage_categories")) {
mp-wp_genesis 909 return(new IXR_Error(401, __("Sorry, you do not have the right to add a category.")));
mp-wp_genesis 910 }
mp-wp_genesis 911
mp-wp_genesis 912 // If no slug was provided make it empty so that
mp-wp_genesis 913 // WordPress will generate one.
mp-wp_genesis 914 if(empty($category["slug"])) {
mp-wp_genesis 915 $category["slug"] = "";
mp-wp_genesis 916 }
mp-wp_genesis 917
mp-wp_genesis 918 // If no parent_id was provided make it empty
mp-wp_genesis 919 // so that it will be a top level page (no parent).
mp-wp_genesis 920 if ( !isset($category["parent_id"]) )
mp-wp_genesis 921 $category["parent_id"] = "";
mp-wp_genesis 922
mp-wp_genesis 923 // If no description was provided make it empty.
mp-wp_genesis 924 if(empty($category["description"])) {
mp-wp_genesis 925 $category["description"] = "";
mp-wp_genesis 926 }
mp-wp_genesis 927
mp-wp_genesis 928 $new_category = array(
mp-wp_genesis 929 "cat_name" => $category["name"],
mp-wp_genesis 930 "category_nicename" => $category["slug"],
mp-wp_genesis 931 "category_parent" => $category["parent_id"],
mp-wp_genesis 932 "category_description" => $category["description"]
mp-wp_genesis 933 );
mp-wp_genesis 934
mp-wp_genesis 935 $cat_id = wp_insert_category($new_category);
mp-wp_genesis 936 if(!$cat_id) {
mp-wp_genesis 937 return(new IXR_Error(500, __("Sorry, the new category failed.")));
mp-wp_genesis 938 }
mp-wp_genesis 939
mp-wp_genesis 940 return($cat_id);
mp-wp_genesis 941 }
mp-wp_genesis 942
mp-wp_genesis 943 /**
mp-wp_genesis 944 * Remove category.
mp-wp_genesis 945 *
mp-wp_genesis 946 * @since 2.5.0
mp-wp_genesis 947 *
mp-wp_genesis 948 * @param array $args Method parameters.
mp-wp_genesis 949 * @return mixed See {@link wp_delete_category()} for return info.
mp-wp_genesis 950 */
mp-wp_genesis 951 function wp_deleteCategory($args) {
mp-wp_genesis 952 $this->escape($args);
mp-wp_genesis 953
mp-wp_genesis 954 $blog_id = (int) $args[0];
mp-wp_genesis 955 $username = $args[1];
mp-wp_genesis 956 $password = $args[2];
mp-wp_genesis 957 $category_id = (int) $args[3];
mp-wp_genesis 958
mp-wp_genesis 959 if( !$this->login_pass_ok( $username, $password ) ) {
mp-wp_genesis 960 return $this->error;
mp-wp_genesis 961 }
mp-wp_genesis 962
mp-wp_genesis 963 do_action('xmlrpc_call', 'wp.deleteCategory');
mp-wp_genesis 964
mp-wp_genesis 965 set_current_user(0, $username);
mp-wp_genesis 966 if( !current_user_can("manage_categories") ) {
mp-wp_genesis 967 return new IXR_Error( 401, __( "Sorry, you do not have the right to delete a category." ) );
mp-wp_genesis 968 }
mp-wp_genesis 969
mp-wp_genesis 970 return wp_delete_category( $category_id );
mp-wp_genesis 971 }
mp-wp_genesis 972
mp-wp_genesis 973 /**
mp-wp_genesis 974 * Retrieve category list.
mp-wp_genesis 975 *
mp-wp_genesis 976 * @since 2.2.0
mp-wp_genesis 977 *
mp-wp_genesis 978 * @param array $args Method parameters.
mp-wp_genesis 979 * @return array
mp-wp_genesis 980 */
mp-wp_genesis 981 function wp_suggestCategories($args) {
mp-wp_genesis 982 $this->escape($args);
mp-wp_genesis 983
mp-wp_genesis 984 $blog_id = (int) $args[0];
mp-wp_genesis 985 $username = $args[1];
mp-wp_genesis 986 $password = $args[2];
mp-wp_genesis 987 $category = $args[3];
mp-wp_genesis 988 $max_results = (int) $args[4];
mp-wp_genesis 989
mp-wp_genesis 990 if(!$this->login_pass_ok($username, $password)) {
mp-wp_genesis 991 return($this->error);
mp-wp_genesis 992 }
mp-wp_genesis 993
mp-wp_genesis 994 set_current_user(0, $username);
mp-wp_genesis 995 if( !current_user_can( 'edit_posts' ) )
mp-wp_genesis 996 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this blog in order to view categories.' ) );
mp-wp_genesis 997
mp-wp_genesis 998 do_action('xmlrpc_call', 'wp.suggestCategories');
mp-wp_genesis 999
mp-wp_genesis 1000 $category_suggestions = array();
mp-wp_genesis 1001 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category);
mp-wp_genesis 1002 foreach ( (array) get_categories($args) as $cat ) {
mp-wp_genesis 1003 $category_suggestions[] = array(
mp-wp_genesis 1004 "category_id" => $cat->cat_ID,
mp-wp_genesis 1005 "category_name" => $cat->cat_name
mp-wp_genesis 1006 );
mp-wp_genesis 1007 }
mp-wp_genesis 1008
mp-wp_genesis 1009 return($category_suggestions);
mp-wp_genesis 1010 }
mp-wp_genesis 1011
mp-wp_genesis 1012 /**
mp-wp_genesis 1013 * Retrieve comment.
mp-wp_genesis 1014 *
mp-wp_genesis 1015 * @since 2.7.0
mp-wp_genesis 1016 *
mp-wp_genesis 1017 * @param array $args Method parameters.
mp-wp_genesis 1018 * @return array
mp-wp_genesis 1019 */
mp-wp_genesis 1020 function wp_getComment($args) {
mp-wp_genesis 1021 $this->escape($args);
mp-wp_genesis 1022
mp-wp_genesis 1023 $blog_id = (int) $args[0];
mp-wp_genesis 1024 $username = $args[1];
mp-wp_genesis 1025 $password = $args[2];
mp-wp_genesis 1026 $comment_id = (int) $args[3];
mp-wp_genesis 1027
mp-wp_genesis 1028 if ( !$this->login_pass_ok( $username, $password ) )
mp-wp_genesis 1029 return $this->error;
mp-wp_genesis 1030
mp-wp_genesis 1031 set_current_user( 0, $username );
mp-wp_genesis 1032 if ( !current_user_can( 'moderate_comments' ) )
mp-wp_genesis 1033 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
mp-wp_genesis 1034
mp-wp_genesis 1035 do_action('xmlrpc_call', 'wp.getComment');
mp-wp_genesis 1036
mp-wp_genesis 1037 if ( ! $comment = get_comment($comment_id) )
mp-wp_genesis 1038 return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
mp-wp_genesis 1039
mp-wp_genesis 1040 // Format page date.
mp-wp_genesis 1041 $comment_date = mysql2date("Ymd\TH:i:s", $comment->comment_date);
mp-wp_genesis 1042 $comment_date_gmt = mysql2date("Ymd\TH:i:s", $comment->comment_date_gmt);
mp-wp_genesis 1043
mp-wp_genesis 1044 if ( 0 == $comment->comment_approved )
mp-wp_genesis 1045 $comment_status = 'hold';
mp-wp_genesis 1046 else if ( 'spam' == $comment->comment_approved )
mp-wp_genesis 1047 $comment_status = 'spam';
mp-wp_genesis 1048 else if ( 1 == $comment->comment_approved )
mp-wp_genesis 1049 $comment_status = 'approve';
mp-wp_genesis 1050 else
mp-wp_genesis 1051 $comment_status = $comment->comment_approved;
mp-wp_genesis 1052
mp-wp_genesis 1053 $link = get_comment_link($comment);
mp-wp_genesis 1054
mp-wp_genesis 1055 $comment_struct = array(
mp-wp_genesis 1056 "date_created_gmt" => new IXR_Date($comment_date_gmt),
mp-wp_genesis 1057 "user_id" => $comment->user_id,
mp-wp_genesis 1058 "comment_id" => $comment->comment_ID,
mp-wp_genesis 1059 "parent" => $comment->comment_parent,
mp-wp_genesis 1060 "status" => $comment_status,
mp-wp_genesis 1061 "content" => $comment->comment_content,
mp-wp_genesis 1062 "link" => $link,
mp-wp_genesis 1063 "post_id" => $comment->comment_post_ID,
mp-wp_genesis 1064 "post_title" => get_the_title($comment->comment_post_ID),
mp-wp_genesis 1065 "author" => $comment->comment_author,
mp-wp_genesis 1066 "author_url" => $comment->comment_author_url,
mp-wp_genesis 1067 "author_email" => $comment->comment_author_email,
mp-wp_genesis 1068 "author_ip" => $comment->comment_author_IP,
mp-wp_genesis 1069 "type" => $comment->comment_type,
mp-wp_genesis 1070 );
mp-wp_genesis 1071
mp-wp_genesis 1072 return $comment_struct;
mp-wp_genesis 1073 }
mp-wp_genesis 1074
mp-wp_genesis 1075 /**
mp-wp_genesis 1076 * Retrieve comments.
mp-wp_genesis 1077 *
mp-wp_genesis 1078 * @since 2.7.0
mp-wp_genesis 1079 *
mp-wp_genesis 1080 * @param array $args Method parameters.
mp-wp_genesis 1081 * @return array
mp-wp_genesis 1082 */
mp-wp_genesis 1083 function wp_getComments($args) {
mp-wp_genesis 1084 $this->escape($args);
mp-wp_genesis 1085
mp-wp_genesis 1086 $blog_id = (int) $args[0];
mp-wp_genesis 1087 $username = $args[1];
mp-wp_genesis 1088 $password = $args[2];
mp-wp_genesis 1089 $struct = $args[3];
mp-wp_genesis 1090
mp-wp_genesis 1091 if ( !$this->login_pass_ok($username, $password) )
mp-wp_genesis 1092 return($this->error);
mp-wp_genesis 1093
mp-wp_genesis 1094 set_current_user( 0, $username );
mp-wp_genesis 1095 if ( !current_user_can( 'moderate_comments' ) )
mp-wp_genesis 1096 return new IXR_Error( 401, __( 'Sorry, you can not edit comments.' ) );
mp-wp_genesis 1097
mp-wp_genesis 1098 do_action('xmlrpc_call', 'wp.getComments');
mp-wp_genesis 1099
mp-wp_genesis 1100 if ( isset($struct['status']) )
mp-wp_genesis 1101 $status = $struct['status'];
mp-wp_genesis 1102 else
mp-wp_genesis 1103 $status = '';
mp-wp_genesis 1104
mp-wp_genesis 1105 $post_id = '';
mp-wp_genesis 1106 if ( isset($struct['post_id']) )
mp-wp_genesis 1107 $post_id = absint($struct['post_id']);
mp-wp_genesis 1108
mp-wp_genesis 1109 $offset = 0;
mp-wp_genesis 1110 if ( isset($struct['offset']) )
mp-wp_genesis 1111 $offset = absint($struct['offset']);
mp-wp_genesis 1112
mp-wp_genesis 1113 $number = 10;
mp-wp_genesis 1114 if ( isset($struct['number']) )
mp-wp_genesis 1115 $number = absint($struct['number']);
mp-wp_genesis 1116
mp-wp_genesis 1117 $comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) );
mp-wp_genesis 1118 $num_comments = count($comments);
mp-wp_genesis 1119
mp-wp_genesis 1120 if ( ! $num_comments )
mp-wp_genesis 1121 return array();
mp-wp_genesis 1122
mp-wp_genesis 1123 $comments_struct = array();
mp-wp_genesis 1124
mp-wp_genesis 1125 for ( $i = 0; $i < $num_comments; $i++ ) {
mp-wp_genesis 1126 $comment = wp_xmlrpc_server::wp_getComment(array(
mp-wp_genesis 1127 $blog_id, $username, $password, $comments[$i]->comment_ID,
mp-wp_genesis 1128 ));
mp-wp_genesis 1129 $comments_struct[] = $comment;
mp-wp_genesis 1130 }
mp-wp_genesis 1131
mp-wp_genesis 1132 return $comments_struct;
mp-wp_genesis 1133 }
mp-wp_genesis 1134
mp-wp_genesis 1135 /**
mp-wp_genesis 1136 * Remove comment.
mp-wp_genesis 1137 *
mp-wp_genesis 1138 * @since 2.7.0
mp-wp_genesis 1139 *
mp-wp_genesis 1140 * @param array $args Method parameters.
mp-wp_genesis 1141 * @return mixed {@link wp_delete_comment()}
mp-wp_genesis 1142 */
mp-wp_genesis 1143 function wp_deleteComment($args) {
mp-wp_genesis 1144 $this->escape($args);
mp-wp_genesis 1145
mp-wp_genesis 1146 $blog_id = (int) $args[0];
mp-wp_genesis 1147 $username = $args[1];
mp-wp_genesis 1148 $password = $args[2];
mp-wp_genesis 1149 $comment_ID = (int) $args[3];
mp-wp_genesis 1150
mp-wp_genesis 1151 if ( !$this->login_pass_ok( $username, $password ) )
mp-wp_genesis 1152 return $this->error;
mp-wp_genesis 1153
mp-wp_genesis 1154 set_current_user( 0, $username );
mp-wp_genesis 1155 if ( !current_user_can( 'moderate_comments' ) )
mp-wp_genesis 1156 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
mp-wp_genesis 1157
mp-wp_genesis 1158 do_action('xmlrpc_call', 'wp.deleteComment');
mp-wp_genesis 1159
mp-wp_genesis 1160 if ( ! get_comment($comment_ID) )
mp-wp_genesis 1161 return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
mp-wp_genesis 1162
mp-wp_genesis 1163 return wp_delete_comment($comment_ID);
mp-wp_genesis 1164 }
mp-wp_genesis 1165
mp-wp_genesis 1166 /**
mp-wp_genesis 1167 * Edit comment.
mp-wp_genesis 1168 *
mp-wp_genesis 1169 * @since 2.7.0
mp-wp_genesis 1170 *
mp-wp_genesis 1171 * @param array $args Method parameters.
mp-wp_genesis 1172 * @return bool True, on success.
mp-wp_genesis 1173 */
mp-wp_genesis 1174 function wp_editComment($args) {
mp-wp_genesis 1175 $this->escape($args);
mp-wp_genesis 1176
mp-wp_genesis 1177 $blog_id = (int) $args[0];
mp-wp_genesis 1178 $username = $args[1];
mp-wp_genesis 1179 $password = $args[2];
mp-wp_genesis 1180 $comment_ID = (int) $args[3];
mp-wp_genesis 1181 $content_struct = $args[4];
mp-wp_genesis 1182
mp-wp_genesis 1183 if ( !$this->login_pass_ok( $username, $password ) )
mp-wp_genesis 1184 return $this->error;
mp-wp_genesis 1185
mp-wp_genesis 1186 set_current_user( 0, $username );
mp-wp_genesis 1187 if ( !current_user_can( 'moderate_comments' ) )
mp-wp_genesis 1188 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
mp-wp_genesis 1189
mp-wp_genesis 1190 do_action('xmlrpc_call', 'wp.editComment');
mp-wp_genesis 1191
mp-wp_genesis 1192 if ( ! get_comment($comment_ID) )
mp-wp_genesis 1193 return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
mp-wp_genesis 1194
mp-wp_genesis 1195 if ( isset($content_struct['status']) ) {
mp-wp_genesis 1196 $statuses = get_comment_statuses();
mp-wp_genesis 1197 $statuses = array_keys($statuses);
mp-wp_genesis 1198
mp-wp_genesis 1199 if ( ! in_array($content_struct['status'], $statuses) )
mp-wp_genesis 1200 return new IXR_Error( 401, __( 'Invalid comment status.' ) );
mp-wp_genesis 1201 $comment_approved = $content_struct['status'];
mp-wp_genesis 1202 }
mp-wp_genesis 1203
mp-wp_genesis 1204 // Do some timestamp voodoo
mp-wp_genesis 1205 if ( !empty( $content_struct['date_created_gmt'] ) ) {
mp-wp_genesis 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 force
mp-wp_genesis 1207 $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
mp-wp_genesis 1208 $comment_date_gmt = iso8601_to_datetime($dateCreated, GMT);
mp-wp_genesis 1209 }
mp-wp_genesis 1210
mp-wp_genesis 1211 if ( isset($content_struct['content']) )
mp-wp_genesis 1212 $comment_content = $content_struct['content'];
mp-wp_genesis 1213
mp-wp_genesis 1214 if ( isset($content_struct['author']) )
mp-wp_genesis 1215 $comment_author = $content_struct['author'];
mp-wp_genesis 1216
mp-wp_genesis 1217 if ( isset($content_struct['author_url']) )
mp-wp_genesis 1218 $comment_author_url = $content_struct['author_url'];
mp-wp_genesis 1219
mp-wp_genesis 1220 if ( isset($content_struct['author_email']) )
mp-wp_genesis 1221 $comment_author_email = $content_struct['author_email'];
mp-wp_genesis 1222
mp-wp_genesis 1223 // We've got all the data -- post it:
mp-wp_genesis 1224 $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url');
mp-wp_genesis 1225
mp-wp_genesis 1226 $result = wp_update_comment($comment);
mp-wp_genesis 1227 if ( is_wp_error( $result ) )
mp-wp_genesis 1228 return new IXR_Error(500, $result->get_error_message());
mp-wp_genesis 1229
mp-wp_genesis 1230 if ( !$result )
mp-wp_genesis 1231 return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.'));
mp-wp_genesis 1232
mp-wp_genesis 1233 return true;
mp-wp_genesis 1234 }
mp-wp_genesis 1235
mp-wp_genesis 1236 /**
mp-wp_genesis 1237 * Create new comment.
mp-wp_genesis 1238 *
mp-wp_genesis 1239 * @since 2.7.0
mp-wp_genesis 1240 *
mp-wp_genesis 1241 * @param array $args Method parameters.
mp-wp_genesis 1242 * @return mixed {@link wp_new_comment()}
mp-wp_genesis 1243 */
mp-wp_genesis 1244 function wp_newComment($args) {
mp-wp_genesis 1245 global $wpdb;
mp-wp_genesis 1246
mp-wp_genesis 1247 $this->escape($args);
mp-wp_genesis 1248
mp-wp_genesis 1249 $blog_id = (int) $args[0];
mp-wp_genesis 1250 $username = $args[1];
mp-wp_genesis 1251 $password = $args[2];
mp-wp_genesis 1252 $post = $args[3];
mp-wp_genesis 1253 $content_struct = $args[4];
mp-wp_genesis 1254
mp-wp_genesis 1255 $allow_anon = apply_filters('xmlrpc_allow_anonymous_comments', false);
mp-wp_genesis 1256
mp-wp_genesis 1257 if ( !$this->login_pass_ok( $username, $password ) ) {
mp-wp_genesis 1258 $logged_in = false;
mp-wp_genesis 1259 if ( $allow_anon && get_option('comment_registration') )
mp-wp_genesis 1260 return new IXR_Error( 403, __( 'You must be registered to comment' ) );
mp-wp_genesis 1261 else if ( !$allow_anon )
mp-wp_genesis 1262 return $this->error;
mp-wp_genesis 1263 } else {
mp-wp_genesis 1264 $logged_in = true;
mp-wp_genesis 1265 set_current_user( 0, $username );
mp-wp_genesis 1266 if ( !current_user_can( 'moderate_comments' ) )
mp-wp_genesis 1267 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
mp-wp_genesis 1268 }
mp-wp_genesis 1269
mp-wp_genesis 1270 if ( is_numeric($post) )
mp-wp_genesis 1271 $post_id = absint($post);
mp-wp_genesis 1272 else
mp-wp_genesis 1273 $post_id = url_to_postid($post);
mp-wp_genesis 1274
mp-wp_genesis 1275 if ( ! $post_id )
mp-wp_genesis 1276 return new IXR_Error( 404, __( 'Invalid post ID.' ) );
mp-wp_genesis 1277
mp-wp_genesis 1278 if ( ! get_post($post_id) )
mp-wp_genesis 1279 return new IXR_Error( 404, __( 'Invalid post ID.' ) );
mp-wp_genesis 1280
mp-wp_genesis 1281 $comment['comment_post_ID'] = $post_id;
mp-wp_genesis 1282
mp-wp_genesis 1283 if ( $logged_in ) {
mp-wp_genesis 1284 $user = wp_get_current_user();
mp-wp_genesis 1285 $comment['comment_author'] = $wpdb->escape( $user->display_name );
mp-wp_genesis 1286 $comment['comment_author_email'] = $wpdb->escape( $user->user_email );
mp-wp_genesis 1287 $comment['comment_author_url'] = $wpdb->escape( $user->user_url );
mp-wp_genesis 1288 $comment['user_ID'] = $user->ID;
mp-wp_genesis 1289 } else {
mp-wp_genesis 1290 $comment['comment_author'] = '';
mp-wp_genesis 1291 if ( isset($content_struct['author']) )
mp-wp_genesis 1292 $comment['comment_author'] = $content_struct['author'];
mp-wp_genesis 1293 $comment['comment_author_email'] = '';
mp-wp_genesis 1294 if ( isset($content_struct['author']) )
mp-wp_genesis 1295 $comment['comment_author_email'] = $content_struct['author_email'];
mp-wp_genesis 1296 $comment['comment_author_url'] = '';
mp-wp_genesis 1297 if ( isset($content_struct['author']) )
mp-wp_genesis 1298 $comment['comment_author_url'] = $content_struct['author_url'];
mp-wp_genesis 1299 $comment['user_ID'] = 0;
mp-wp_genesis 1300
mp-wp_genesis 1301 if ( get_option('require_name_email') ) {
mp-wp_genesis 1302 if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'] )
mp-wp_genesis 1303 return new IXR_Error( 403, __( 'Comment author name and email are required' ) );
mp-wp_genesis 1304 elseif ( !is_email($comment['comment_author_email']) )
mp-wp_genesis 1305 return new IXR_Error( 403, __( 'A valid email address is required' ) );
mp-wp_genesis 1306 }
mp-wp_genesis 1307 }
mp-wp_genesis 1308
mp-wp_genesis 1309 $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0;
mp-wp_genesis 1310
mp-wp_genesis 1311 $comment['comment_content'] = $content_struct['content'];
mp-wp_genesis 1312
mp-wp_genesis 1313 do_action('xmlrpc_call', 'wp.newComment');
mp-wp_genesis 1314
mp-wp_genesis 1315 return wp_new_comment($comment);
mp-wp_genesis 1316 }
mp-wp_genesis 1317
mp-wp_genesis 1318 /**
mp-wp_genesis 1319 * Retrieve all of the comment status.
mp-wp_genesis 1320 *
mp-wp_genesis 1321 * @since 2.7.0
mp-wp_genesis 1322 *
mp-wp_genesis 1323 * @param array $args Method parameters.
mp-wp_genesis 1324 * @return array
mp-wp_genesis 1325 */
mp-wp_genesis 1326 function wp_getCommentStatusList($args) {
mp-wp_genesis 1327 $this->escape( $args );
mp-wp_genesis 1328
mp-wp_genesis 1329 $blog_id = (int) $args[0];
mp-wp_genesis 1330 $username = $args[1];
mp-wp_genesis 1331 $password = $args[2];
mp-wp_genesis 1332
mp-wp_genesis 1333 if ( !$this->login_pass_ok( $username, $password ) )
mp-wp_genesis 1334 return $this->error;
mp-wp_genesis 1335
mp-wp_genesis 1336 set_current_user( 0, $username );
mp-wp_genesis 1337 if ( !current_user_can( 'moderate_comments' ) )
mp-wp_genesis 1338 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
mp-wp_genesis 1339
mp-wp_genesis 1340 do_action('xmlrpc_call', 'wp.getCommentStatusList');
mp-wp_genesis 1341
mp-wp_genesis 1342 return get_comment_statuses( );
mp-wp_genesis 1343 }
mp-wp_genesis 1344
mp-wp_genesis 1345 /**
mp-wp_genesis 1346 * Retrieve comment count.
mp-wp_genesis 1347 *
mp-wp_genesis 1348 * @since 2.5.0
mp-wp_genesis 1349 *
mp-wp_genesis 1350 * @param array $args Method parameters.
mp-wp_genesis 1351 * @return array
mp-wp_genesis 1352 */
mp-wp_genesis 1353 function wp_getCommentCount( $args ) {
mp-wp_genesis 1354 $this->escape($args);
mp-wp_genesis 1355
mp-wp_genesis 1356 $blog_id = (int) $args[0];
mp-wp_genesis 1357 $username = $args[1];
mp-wp_genesis 1358 $password = $args[2];
mp-wp_genesis 1359 $post_id = (int) $args[3];
mp-wp_genesis 1360
mp-wp_genesis 1361 if( !$this->login_pass_ok( $username, $password ) ) {
mp-wp_genesis 1362 return $this->error;
mp-wp_genesis 1363 }
mp-wp_genesis 1364
mp-wp_genesis 1365 set_current_user( 0, $username );
mp-wp_genesis 1366 if( !current_user_can( 'edit_posts' ) ) {
mp-wp_genesis 1367 return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) );
mp-wp_genesis 1368 }
mp-wp_genesis 1369
mp-wp_genesis 1370 do_action('xmlrpc_call', 'wp.getCommentCount');
mp-wp_genesis 1371
mp-wp_genesis 1372 $count = wp_count_comments( $post_id );
mp-wp_genesis 1373 return array(
mp-wp_genesis 1374 "approved" => $count->approved,
mp-wp_genesis 1375 "awaiting_moderation" => $count->moderated,
mp-wp_genesis 1376 "spam" => $count->spam,
mp-wp_genesis 1377 "total_comments" => $count->total_comments
mp-wp_genesis 1378 );
mp-wp_genesis 1379 }
mp-wp_genesis 1380
mp-wp_genesis 1381 /**
mp-wp_genesis 1382 * Retrieve post statuses.
mp-wp_genesis 1383 *
mp-wp_genesis 1384 * @since 2.5.0
mp-wp_genesis 1385 *
mp-wp_genesis 1386 * @param array $args Method parameters.
mp-wp_genesis 1387 * @return array
mp-wp_genesis 1388 */
mp-wp_genesis 1389 function wp_getPostStatusList( $args ) {
mp-wp_genesis 1390 $this->escape( $args );
mp-wp_genesis 1391
mp-wp_genesis 1392 $blog_id = (int) $args[0];
mp-wp_genesis 1393 $username = $args[1];
mp-wp_genesis 1394 $password = $args[2];
mp-wp_genesis 1395
mp-wp_genesis 1396 if( !$this->login_pass_ok( $username, $password ) ) {
mp-wp_genesis 1397 return $this->error;
mp-wp_genesis 1398 }
mp-wp_genesis 1399
mp-wp_genesis 1400 set_current_user( 0, $username );
mp-wp_genesis 1401 if( !current_user_can( 'edit_posts' ) ) {
mp-wp_genesis 1402 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
mp-wp_genesis 1403 }
mp-wp_genesis 1404
mp-wp_genesis 1405 do_action('xmlrpc_call', 'wp.getPostStatusList');
mp-wp_genesis 1406
mp-wp_genesis 1407 return get_post_statuses( );
mp-wp_genesis 1408 }
mp-wp_genesis 1409
mp-wp_genesis 1410 /**
mp-wp_genesis 1411 * Retrieve page statuses.
mp-wp_genesis 1412 *
mp-wp_genesis 1413 * @since 2.5.0
mp-wp_genesis 1414 *
mp-wp_genesis 1415 * @param array $args Method parameters.
mp-wp_genesis 1416 * @return array
mp-wp_genesis 1417 */
mp-wp_genesis 1418 function wp_getPageStatusList( $args ) {
mp-wp_genesis 1419 $this->escape( $args );
mp-wp_genesis 1420
mp-wp_genesis 1421 $blog_id = (int) $args[0];
mp-wp_genesis 1422 $username = $args[1];
mp-wp_genesis 1423 $password = $args[2];
mp-wp_genesis 1424
mp-wp_genesis 1425 if( !$this->login_pass_ok( $username, $password ) ) {
mp-wp_genesis 1426 return $this->error;
mp-wp_genesis 1427 }
mp-wp_genesis 1428
mp-wp_genesis 1429 set_current_user( 0, $username );
mp-wp_genesis 1430 if( !current_user_can( 'edit_posts' ) ) {
mp-wp_genesis 1431 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
mp-wp_genesis 1432 }
mp-wp_genesis 1433
mp-wp_genesis 1434 do_action('xmlrpc_call', 'wp.getPageStatusList');
mp-wp_genesis 1435
mp-wp_genesis 1436 return get_page_statuses( );
mp-wp_genesis 1437 }
mp-wp_genesis 1438
mp-wp_genesis 1439 /**
mp-wp_genesis 1440 * Retrieve page templates.
mp-wp_genesis 1441 *
mp-wp_genesis 1442 * @since 2.6.0
mp-wp_genesis 1443 *
mp-wp_genesis 1444 * @param array $args Method parameters.
mp-wp_genesis 1445 * @return array
mp-wp_genesis 1446 */
mp-wp_genesis 1447 function wp_getPageTemplates( $args ) {
mp-wp_genesis 1448 $this->escape( $args );
mp-wp_genesis 1449
mp-wp_genesis 1450 $blog_id = (int) $args[0];
mp-wp_genesis 1451 $username = $args[1];
mp-wp_genesis 1452 $password = $args[2];
mp-wp_genesis 1453
mp-wp_genesis 1454 if( !$this->login_pass_ok( $username, $password ) ) {
mp-wp_genesis 1455 return $this->error;
mp-wp_genesis 1456 }
mp-wp_genesis 1457
mp-wp_genesis 1458 set_current_user( 0, $username );
mp-wp_genesis 1459 if( !current_user_can( 'edit_pages' ) ) {
mp-wp_genesis 1460 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
mp-wp_genesis 1461 }
mp-wp_genesis 1462
mp-wp_genesis 1463 $templates = get_page_templates( );
mp-wp_genesis 1464 $templates['Default'] = 'default';
mp-wp_genesis 1465
mp-wp_genesis 1466 return $templates;
mp-wp_genesis 1467 }
mp-wp_genesis 1468
mp-wp_genesis 1469 /**
mp-wp_genesis 1470 * Retrieve blog options.
mp-wp_genesis 1471 *
mp-wp_genesis 1472 * @since 2.6.0
mp-wp_genesis 1473 *
mp-wp_genesis 1474 * @param array $args Method parameters.
mp-wp_genesis 1475 * @return array
mp-wp_genesis 1476 */
mp-wp_genesis 1477 function wp_getOptions( $args ) {
mp-wp_genesis 1478 $this->escape( $args );
mp-wp_genesis 1479
mp-wp_genesis 1480 $blog_id = (int) $args[0];
mp-wp_genesis 1481 $username = $args[1];
mp-wp_genesis 1482 $password = $args[2];
mp-wp_genesis 1483 $options = (array) $args[3];
mp-wp_genesis 1484
mp-wp_genesis 1485 if( !$this->login_pass_ok( $username, $password ) )
mp-wp_genesis 1486 return $this->error;
mp-wp_genesis 1487
mp-wp_genesis 1488 $user = set_current_user( 0, $username );
mp-wp_genesis 1489
mp-wp_genesis 1490 // If no specific options where asked for, return all of them
mp-wp_genesis 1491 if (count( $options ) == 0 ) {
mp-wp_genesis 1492 $options = array_keys($this->blog_options);
mp-wp_genesis 1493 }
mp-wp_genesis 1494
mp-wp_genesis 1495 return $this->_getOptions($options);
mp-wp_genesis 1496 }
mp-wp_genesis 1497
mp-wp_genesis 1498 /**
mp-wp_genesis 1499 * Retrieve blog options value from list.
mp-wp_genesis 1500 *
mp-wp_genesis 1501 * @since 2.6.0
mp-wp_genesis 1502 *
mp-wp_genesis 1503 * @param array $options Options to retrieve.
mp-wp_genesis 1504 * @return array
mp-wp_genesis 1505 */
mp-wp_genesis 1506 function _getOptions($options)
mp-wp_genesis 1507 {
mp-wp_genesis 1508 $data = array( );
mp-wp_genesis 1509 foreach( $options as $option ) {
mp-wp_genesis 1510 if( array_key_exists( $option, $this->blog_options ) )
mp-wp_genesis 1511 {
mp-wp_genesis 1512 $data[$option] = $this->blog_options[$option];
mp-wp_genesis 1513 //Is the value static or dynamic?
mp-wp_genesis 1514 if( isset( $data[$option]['option'] ) ) {
mp-wp_genesis 1515 $data[$option]['value'] = get_option( $data[$option]['option'] );
mp-wp_genesis 1516 unset($data[$option]['option']);
mp-wp_genesis 1517 }
mp-wp_genesis 1518 }
mp-wp_genesis 1519 }
mp-wp_genesis 1520
mp-wp_genesis 1521 return $data;
mp-wp_genesis 1522 }
mp-wp_genesis 1523
mp-wp_genesis 1524 /**
mp-wp_genesis 1525 * Update blog options.
mp-wp_genesis 1526 *
mp-wp_genesis 1527 * @since 2.6.0
mp-wp_genesis 1528 *
mp-wp_genesis 1529 * @param array $args Method parameters.
mp-wp_genesis 1530 * @return unknown
mp-wp_genesis 1531 */
mp-wp_genesis 1532 function wp_setOptions( $args ) {
mp-wp_genesis 1533 $this->escape( $args );
mp-wp_genesis 1534
mp-wp_genesis 1535 $blog_id = (int) $args[0];
mp-wp_genesis 1536 $username = $args[1];
mp-wp_genesis 1537 $password = $args[2];
mp-wp_genesis 1538 $options = (array) $args[3];
mp-wp_genesis 1539
mp-wp_genesis 1540 if( !$this->login_pass_ok( $username, $password ) )
mp-wp_genesis 1541 return $this->error;
mp-wp_genesis 1542
mp-wp_genesis 1543 $user = set_current_user( 0, $username );
mp-wp_genesis 1544 if( !current_user_can( 'manage_options' ) )
mp-wp_genesis 1545 return new IXR_Error( 403, __( 'You are not allowed to update options.' ) );
mp-wp_genesis 1546
mp-wp_genesis 1547 foreach( $options as $o_name => $o_value ) {
mp-wp_genesis 1548 $option_names[] = $o_name;
mp-wp_genesis 1549 if( empty( $o_value ) )
mp-wp_genesis 1550 continue;
mp-wp_genesis 1551
mp-wp_genesis 1552 if( !array_key_exists( $o_name, $this->blog_options ) )
mp-wp_genesis 1553 continue;
mp-wp_genesis 1554
mp-wp_genesis 1555 if( $this->blog_options[$o_name]['readonly'] == true )
mp-wp_genesis 1556 continue;
mp-wp_genesis 1557
mp-wp_genesis 1558 update_option( $this->blog_options[$o_name]['option'], $o_value );
mp-wp_genesis 1559 }
mp-wp_genesis 1560
mp-wp_genesis 1561 //Now return the updated values
mp-wp_genesis 1562 return $this->_getOptions($option_names);
mp-wp_genesis 1563 }
mp-wp_genesis 1564
mp-wp_genesis 1565 /* Blogger API functions.
mp-wp_genesis 1566 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
mp-wp_genesis 1567 */
mp-wp_genesis 1568
mp-wp_genesis 1569 /**
mp-wp_genesis 1570 * Retrieve blogs that user owns.
mp-wp_genesis 1571 *
mp-wp_genesis 1572 * Will make more sense once we support multiple blogs.
mp-wp_genesis 1573 *
mp-wp_genesis 1574 * @since 1.5.0
mp-wp_genesis 1575 *
mp-wp_genesis 1576 * @param array $args Method parameters.
mp-wp_genesis 1577 * @return array
mp-wp_genesis 1578 */
mp-wp_genesis 1579 function blogger_getUsersBlogs($args) {
mp-wp_genesis 1580
mp-wp_genesis 1581 $this->escape($args);
mp-wp_genesis 1582
mp-wp_genesis 1583 $user_login = $args[1];
mp-wp_genesis 1584 $user_pass = $args[2];
mp-wp_genesis 1585
mp-wp_genesis 1586 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1587 return $this->error;
mp-wp_genesis 1588 }
mp-wp_genesis 1589
mp-wp_genesis 1590 do_action('xmlrpc_call', 'blogger.getUsersBlogs');
mp-wp_genesis 1591
mp-wp_genesis 1592 set_current_user(0, $user_login);
mp-wp_genesis 1593 $is_admin = current_user_can('manage_options');
mp-wp_genesis 1594
mp-wp_genesis 1595 $struct = array(
mp-wp_genesis 1596 'isAdmin' => $is_admin,
mp-wp_genesis 1597 'url' => get_option('home') . '/',
mp-wp_genesis 1598 'blogid' => '1',
mp-wp_genesis 1599 'blogName' => get_option('blogname'),
mp-wp_genesis 1600 'xmlrpc' => get_option('home') . '/xmlrpc.php',
mp-wp_genesis 1601 );
mp-wp_genesis 1602
mp-wp_genesis 1603 return array($struct);
mp-wp_genesis 1604 }
mp-wp_genesis 1605
mp-wp_genesis 1606 /**
mp-wp_genesis 1607 * Retrieve user's data.
mp-wp_genesis 1608 *
mp-wp_genesis 1609 * Gives your client some info about you, so you don't have to.
mp-wp_genesis 1610 *
mp-wp_genesis 1611 * @since 1.5.0
mp-wp_genesis 1612 *
mp-wp_genesis 1613 * @param array $args Method parameters.
mp-wp_genesis 1614 * @return array
mp-wp_genesis 1615 */
mp-wp_genesis 1616 function blogger_getUserInfo($args) {
mp-wp_genesis 1617
mp-wp_genesis 1618 $this->escape($args);
mp-wp_genesis 1619
mp-wp_genesis 1620 $user_login = $args[1];
mp-wp_genesis 1621 $user_pass = $args[2];
mp-wp_genesis 1622
mp-wp_genesis 1623 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1624 return $this->error;
mp-wp_genesis 1625 }
mp-wp_genesis 1626
mp-wp_genesis 1627 set_current_user( 0, $user_login );
mp-wp_genesis 1628 if( !current_user_can( 'edit_posts' ) )
mp-wp_genesis 1629 return new IXR_Error( 401, __( 'Sorry, you do not have access to user data on this blog.' ) );
mp-wp_genesis 1630
mp-wp_genesis 1631 do_action('xmlrpc_call', 'blogger.getUserInfo');
mp-wp_genesis 1632
mp-wp_genesis 1633 $user_data = get_userdatabylogin($user_login);
mp-wp_genesis 1634
mp-wp_genesis 1635 $struct = array(
mp-wp_genesis 1636 'nickname' => $user_data->nickname,
mp-wp_genesis 1637 'userid' => $user_data->ID,
mp-wp_genesis 1638 'url' => $user_data->user_url,
mp-wp_genesis 1639 'lastname' => $user_data->last_name,
mp-wp_genesis 1640 'firstname' => $user_data->first_name
mp-wp_genesis 1641 );
mp-wp_genesis 1642
mp-wp_genesis 1643 return $struct;
mp-wp_genesis 1644 }
mp-wp_genesis 1645
mp-wp_genesis 1646 /**
mp-wp_genesis 1647 * Retrieve post.
mp-wp_genesis 1648 *
mp-wp_genesis 1649 * @since 1.5.0
mp-wp_genesis 1650 *
mp-wp_genesis 1651 * @param array $args Method parameters.
mp-wp_genesis 1652 * @return array
mp-wp_genesis 1653 */
mp-wp_genesis 1654 function blogger_getPost($args) {
mp-wp_genesis 1655
mp-wp_genesis 1656 $this->escape($args);
mp-wp_genesis 1657
mp-wp_genesis 1658 $post_ID = (int) $args[1];
mp-wp_genesis 1659 $user_login = $args[2];
mp-wp_genesis 1660 $user_pass = $args[3];
mp-wp_genesis 1661
mp-wp_genesis 1662 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1663 return $this->error;
mp-wp_genesis 1664 }
mp-wp_genesis 1665
mp-wp_genesis 1666 set_current_user( 0, $user_login );
mp-wp_genesis 1667 if( !current_user_can( 'edit_post', $post_ID ) )
mp-wp_genesis 1668 return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) );
mp-wp_genesis 1669
mp-wp_genesis 1670 do_action('xmlrpc_call', 'blogger.getPost');
mp-wp_genesis 1671
mp-wp_genesis 1672 $post_data = wp_get_single_post($post_ID, ARRAY_A);
mp-wp_genesis 1673
mp-wp_genesis 1674 $categories = implode(',', wp_get_post_categories($post_ID));
mp-wp_genesis 1675
mp-wp_genesis 1676 $content = '<title>'.stripslashes($post_data['post_title']).'</title>';
mp-wp_genesis 1677 $content .= '<category>'.$categories.'</category>';
mp-wp_genesis 1678 $content .= stripslashes($post_data['post_content']);
mp-wp_genesis 1679
mp-wp_genesis 1680 $struct = array(
mp-wp_genesis 1681 'userid' => $post_data['post_author'],
mp-wp_genesis 1682 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
mp-wp_genesis 1683 'content' => $content,
mp-wp_genesis 1684 'postid' => $post_data['ID']
mp-wp_genesis 1685 );
mp-wp_genesis 1686
mp-wp_genesis 1687 return $struct;
mp-wp_genesis 1688 }
mp-wp_genesis 1689
mp-wp_genesis 1690 /**
mp-wp_genesis 1691 * Retrieve list of recent posts.
mp-wp_genesis 1692 *
mp-wp_genesis 1693 * @since 1.5.0
mp-wp_genesis 1694 *
mp-wp_genesis 1695 * @param array $args Method parameters.
mp-wp_genesis 1696 * @return array
mp-wp_genesis 1697 */
mp-wp_genesis 1698 function blogger_getRecentPosts($args) {
mp-wp_genesis 1699
mp-wp_genesis 1700 $this->escape($args);
mp-wp_genesis 1701
mp-wp_genesis 1702 $blog_ID = (int) $args[1]; /* though we don't use it yet */
mp-wp_genesis 1703 $user_login = $args[2];
mp-wp_genesis 1704 $user_pass = $args[3];
mp-wp_genesis 1705 $num_posts = $args[4];
mp-wp_genesis 1706
mp-wp_genesis 1707 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1708 return $this->error;
mp-wp_genesis 1709 }
mp-wp_genesis 1710
mp-wp_genesis 1711 do_action('xmlrpc_call', 'blogger.getRecentPosts');
mp-wp_genesis 1712
mp-wp_genesis 1713 $posts_list = wp_get_recent_posts($num_posts);
mp-wp_genesis 1714
mp-wp_genesis 1715 set_current_user( 0, $user_login );
mp-wp_genesis 1716
mp-wp_genesis 1717 if (!$posts_list) {
mp-wp_genesis 1718 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.'));
mp-wp_genesis 1719 return $this->error;
mp-wp_genesis 1720 }
mp-wp_genesis 1721
mp-wp_genesis 1722 foreach ($posts_list as $entry) {
mp-wp_genesis 1723 if( !current_user_can( 'edit_post', $entry['ID'] ) )
mp-wp_genesis 1724 continue;
mp-wp_genesis 1725
mp-wp_genesis 1726 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
mp-wp_genesis 1727 $categories = implode(',', wp_get_post_categories($entry['ID']));
mp-wp_genesis 1728
mp-wp_genesis 1729 $content = '<title>'.stripslashes($entry['post_title']).'</title>';
mp-wp_genesis 1730 $content .= '<category>'.$categories.'</category>';
mp-wp_genesis 1731 $content .= stripslashes($entry['post_content']);
mp-wp_genesis 1732
mp-wp_genesis 1733 $struct[] = array(
mp-wp_genesis 1734 'userid' => $entry['post_author'],
mp-wp_genesis 1735 'dateCreated' => new IXR_Date($post_date),
mp-wp_genesis 1736 'content' => $content,
mp-wp_genesis 1737 'postid' => $entry['ID'],
mp-wp_genesis 1738 );
mp-wp_genesis 1739
mp-wp_genesis 1740 }
mp-wp_genesis 1741
mp-wp_genesis 1742 $recent_posts = array();
mp-wp_genesis 1743 for ($j=0; $j<count($struct); $j++) {
mp-wp_genesis 1744 array_push($recent_posts, $struct[$j]);
mp-wp_genesis 1745 }
mp-wp_genesis 1746
mp-wp_genesis 1747 return $recent_posts;
mp-wp_genesis 1748 }
mp-wp_genesis 1749
mp-wp_genesis 1750 /**
mp-wp_genesis 1751 * Retrieve blog_filename content.
mp-wp_genesis 1752 *
mp-wp_genesis 1753 * @since 1.5.0
mp-wp_genesis 1754 *
mp-wp_genesis 1755 * @param array $args Method parameters.
mp-wp_genesis 1756 * @return string
mp-wp_genesis 1757 */
mp-wp_genesis 1758 function blogger_getTemplate($args) {
mp-wp_genesis 1759
mp-wp_genesis 1760 $this->escape($args);
mp-wp_genesis 1761
mp-wp_genesis 1762 $blog_ID = (int) $args[1];
mp-wp_genesis 1763 $user_login = $args[2];
mp-wp_genesis 1764 $user_pass = $args[3];
mp-wp_genesis 1765 $template = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
mp-wp_genesis 1766
mp-wp_genesis 1767 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1768 return $this->error;
mp-wp_genesis 1769 }
mp-wp_genesis 1770
mp-wp_genesis 1771 do_action('xmlrpc_call', 'blogger.getTemplate');
mp-wp_genesis 1772
mp-wp_genesis 1773 set_current_user(0, $user_login);
mp-wp_genesis 1774 if ( !current_user_can('edit_themes') ) {
mp-wp_genesis 1775 return new IXR_Error(401, __('Sorry, this user can not edit the template.'));
mp-wp_genesis 1776 }
mp-wp_genesis 1777
mp-wp_genesis 1778 /* warning: here we make the assumption that the blog's URL is on the same server */
mp-wp_genesis 1779 $filename = get_option('home') . '/';
mp-wp_genesis 1780 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
mp-wp_genesis 1781
mp-wp_genesis 1782 $f = fopen($filename, 'r');
mp-wp_genesis 1783 $content = fread($f, filesize($filename));
mp-wp_genesis 1784 fclose($f);
mp-wp_genesis 1785
mp-wp_genesis 1786 /* so it is actually editable with a windows/mac client */
mp-wp_genesis 1787 // FIXME: (or delete me) do we really want to cater to bad clients at the expense of good ones by BEEPing up their line breaks? commented. $content = str_replace("\n", "\r\n", $content);
mp-wp_genesis 1788
mp-wp_genesis 1789 return $content;
mp-wp_genesis 1790 }
mp-wp_genesis 1791
mp-wp_genesis 1792 /**
mp-wp_genesis 1793 * Updates the content of blog_filename.
mp-wp_genesis 1794 *
mp-wp_genesis 1795 * @since 1.5.0
mp-wp_genesis 1796 *
mp-wp_genesis 1797 * @param array $args Method parameters.
mp-wp_genesis 1798 * @return bool True when done.
mp-wp_genesis 1799 */
mp-wp_genesis 1800 function blogger_setTemplate($args) {
mp-wp_genesis 1801
mp-wp_genesis 1802 $this->escape($args);
mp-wp_genesis 1803
mp-wp_genesis 1804 $blog_ID = (int) $args[1];
mp-wp_genesis 1805 $user_login = $args[2];
mp-wp_genesis 1806 $user_pass = $args[3];
mp-wp_genesis 1807 $content = $args[4];
mp-wp_genesis 1808 $template = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
mp-wp_genesis 1809
mp-wp_genesis 1810 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1811 return $this->error;
mp-wp_genesis 1812 }
mp-wp_genesis 1813
mp-wp_genesis 1814 do_action('xmlrpc_call', 'blogger.setTemplate');
mp-wp_genesis 1815
mp-wp_genesis 1816 set_current_user(0, $user_login);
mp-wp_genesis 1817 if ( !current_user_can('edit_themes') ) {
mp-wp_genesis 1818 return new IXR_Error(401, __('Sorry, this user can not edit the template.'));
mp-wp_genesis 1819 }
mp-wp_genesis 1820
mp-wp_genesis 1821 /* warning: here we make the assumption that the blog's URL is on the same server */
mp-wp_genesis 1822 $filename = get_option('home') . '/';
mp-wp_genesis 1823 $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
mp-wp_genesis 1824
mp-wp_genesis 1825 if ($f = fopen($filename, 'w+')) {
mp-wp_genesis 1826 fwrite($f, $content);
mp-wp_genesis 1827 fclose($f);
mp-wp_genesis 1828 } else {
mp-wp_genesis 1829 return new IXR_Error(500, __('Either the file is not writable, or something wrong happened. The file has not been updated.'));
mp-wp_genesis 1830 }
mp-wp_genesis 1831
mp-wp_genesis 1832 return true;
mp-wp_genesis 1833 }
mp-wp_genesis 1834
mp-wp_genesis 1835 /**
mp-wp_genesis 1836 * Create new post.
mp-wp_genesis 1837 *
mp-wp_genesis 1838 * @since 1.5.0
mp-wp_genesis 1839 *
mp-wp_genesis 1840 * @param array $args Method parameters.
mp-wp_genesis 1841 * @return int
mp-wp_genesis 1842 */
mp-wp_genesis 1843 function blogger_newPost($args) {
mp-wp_genesis 1844
mp-wp_genesis 1845 $this->escape($args);
mp-wp_genesis 1846
mp-wp_genesis 1847 $blog_ID = (int) $args[1]; /* though we don't use it yet */
mp-wp_genesis 1848 $user_login = $args[2];
mp-wp_genesis 1849 $user_pass = $args[3];
mp-wp_genesis 1850 $content = $args[4];
mp-wp_genesis 1851 $publish = $args[5];
mp-wp_genesis 1852
mp-wp_genesis 1853 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1854 return $this->error;
mp-wp_genesis 1855 }
mp-wp_genesis 1856
mp-wp_genesis 1857 do_action('xmlrpc_call', 'blogger.newPost');
mp-wp_genesis 1858
mp-wp_genesis 1859 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
mp-wp_genesis 1860 $user = set_current_user(0, $user_login);
mp-wp_genesis 1861 if ( !current_user_can($cap) )
mp-wp_genesis 1862 return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.'));
mp-wp_genesis 1863
mp-wp_genesis 1864 $post_status = ($publish) ? 'publish' : 'draft';
mp-wp_genesis 1865
mp-wp_genesis 1866 $post_author = $user->ID;
mp-wp_genesis 1867
mp-wp_genesis 1868 $post_title = xmlrpc_getposttitle($content);
mp-wp_genesis 1869 $post_category = xmlrpc_getpostcategory($content);
mp-wp_genesis 1870 $post_content = xmlrpc_removepostdata($content);
mp-wp_genesis 1871
mp-wp_genesis 1872 $post_date = current_time('mysql');
mp-wp_genesis 1873 $post_date_gmt = current_time('mysql', 1);
mp-wp_genesis 1874
mp-wp_genesis 1875 $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
mp-wp_genesis 1876
mp-wp_genesis 1877 $post_ID = wp_insert_post($post_data);
mp-wp_genesis 1878 if ( is_wp_error( $post_ID ) )
mp-wp_genesis 1879 return new IXR_Error(500, $post_ID->get_error_message());
mp-wp_genesis 1880
mp-wp_genesis 1881 if (!$post_ID)
mp-wp_genesis 1882 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
mp-wp_genesis 1883
mp-wp_genesis 1884 $this->attach_uploads( $post_ID, $post_content );
mp-wp_genesis 1885
mp-wp_genesis 1886 logIO('O', "Posted ! ID: $post_ID");
mp-wp_genesis 1887
mp-wp_genesis 1888 return $post_ID;
mp-wp_genesis 1889 }
mp-wp_genesis 1890
mp-wp_genesis 1891 /**
mp-wp_genesis 1892 * Edit a post.
mp-wp_genesis 1893 *
mp-wp_genesis 1894 * @since 1.5.0
mp-wp_genesis 1895 *
mp-wp_genesis 1896 * @param array $args Method parameters.
mp-wp_genesis 1897 * @return bool true when done.
mp-wp_genesis 1898 */
mp-wp_genesis 1899 function blogger_editPost($args) {
mp-wp_genesis 1900
mp-wp_genesis 1901 $this->escape($args);
mp-wp_genesis 1902
mp-wp_genesis 1903 $post_ID = (int) $args[1];
mp-wp_genesis 1904 $user_login = $args[2];
mp-wp_genesis 1905 $user_pass = $args[3];
mp-wp_genesis 1906 $content = $args[4];
mp-wp_genesis 1907 $publish = $args[5];
mp-wp_genesis 1908
mp-wp_genesis 1909 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1910 return $this->error;
mp-wp_genesis 1911 }
mp-wp_genesis 1912
mp-wp_genesis 1913 do_action('xmlrpc_call', 'blogger.editPost');
mp-wp_genesis 1914
mp-wp_genesis 1915 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
mp-wp_genesis 1916
mp-wp_genesis 1917 if (!$actual_post || $actual_post['post_type'] != 'post') {
mp-wp_genesis 1918 return new IXR_Error(404, __('Sorry, no such post.'));
mp-wp_genesis 1919 }
mp-wp_genesis 1920
mp-wp_genesis 1921 $this->escape($actual_post);
mp-wp_genesis 1922
mp-wp_genesis 1923 set_current_user(0, $user_login);
mp-wp_genesis 1924 if ( !current_user_can('edit_post', $post_ID) )
mp-wp_genesis 1925 return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.'));
mp-wp_genesis 1926
mp-wp_genesis 1927 extract($actual_post, EXTR_SKIP);
mp-wp_genesis 1928
mp-wp_genesis 1929 if ( ('publish' == $post_status) && !current_user_can('publish_posts') )
mp-wp_genesis 1930 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
mp-wp_genesis 1931
mp-wp_genesis 1932 $post_title = xmlrpc_getposttitle($content);
mp-wp_genesis 1933 $post_category = xmlrpc_getpostcategory($content);
mp-wp_genesis 1934 $post_content = xmlrpc_removepostdata($content);
mp-wp_genesis 1935
mp-wp_genesis 1936 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt');
mp-wp_genesis 1937
mp-wp_genesis 1938 $result = wp_update_post($postdata);
mp-wp_genesis 1939
mp-wp_genesis 1940 if (!$result) {
mp-wp_genesis 1941 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.'));
mp-wp_genesis 1942 }
mp-wp_genesis 1943 $this->attach_uploads( $ID, $post_content );
mp-wp_genesis 1944
mp-wp_genesis 1945 return true;
mp-wp_genesis 1946 }
mp-wp_genesis 1947
mp-wp_genesis 1948 /**
mp-wp_genesis 1949 * Remove a post.
mp-wp_genesis 1950 *
mp-wp_genesis 1951 * @since 1.5.0
mp-wp_genesis 1952 *
mp-wp_genesis 1953 * @param array $args Method parameters.
mp-wp_genesis 1954 * @return bool True when post is deleted.
mp-wp_genesis 1955 */
mp-wp_genesis 1956 function blogger_deletePost($args) {
mp-wp_genesis 1957 $this->escape($args);
mp-wp_genesis 1958
mp-wp_genesis 1959 $post_ID = (int) $args[1];
mp-wp_genesis 1960 $user_login = $args[2];
mp-wp_genesis 1961 $user_pass = $args[3];
mp-wp_genesis 1962 $publish = $args[4];
mp-wp_genesis 1963
mp-wp_genesis 1964 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 1965 return $this->error;
mp-wp_genesis 1966 }
mp-wp_genesis 1967
mp-wp_genesis 1968 do_action('xmlrpc_call', 'blogger.deletePost');
mp-wp_genesis 1969
mp-wp_genesis 1970 $actual_post = wp_get_single_post($post_ID,ARRAY_A);
mp-wp_genesis 1971
mp-wp_genesis 1972 if (!$actual_post || $actual_post['post_type'] != 'post') {
mp-wp_genesis 1973 return new IXR_Error(404, __('Sorry, no such post.'));
mp-wp_genesis 1974 }
mp-wp_genesis 1975
mp-wp_genesis 1976 set_current_user(0, $user_login);
mp-wp_genesis 1977 if ( !current_user_can('edit_post', $post_ID) )
mp-wp_genesis 1978 return new IXR_Error(401, __('Sorry, you do not have the right to delete this post.'));
mp-wp_genesis 1979
mp-wp_genesis 1980 $result = wp_delete_post($post_ID);
mp-wp_genesis 1981
mp-wp_genesis 1982 if (!$result) {
mp-wp_genesis 1983 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.'));
mp-wp_genesis 1984 }
mp-wp_genesis 1985
mp-wp_genesis 1986 return true;
mp-wp_genesis 1987 }
mp-wp_genesis 1988
mp-wp_genesis 1989 /* MetaWeblog API functions
mp-wp_genesis 1990 * specs on wherever Dave Winer wants them to be
mp-wp_genesis 1991 */
mp-wp_genesis 1992
mp-wp_genesis 1993 /**
mp-wp_genesis 1994 * Create a new post.
mp-wp_genesis 1995 *
mp-wp_genesis 1996 * @since 1.5.0
mp-wp_genesis 1997 *
mp-wp_genesis 1998 * @param array $args Method parameters.
mp-wp_genesis 1999 * @return int
mp-wp_genesis 2000 */
mp-wp_genesis 2001 function mw_newPost($args) {
mp-wp_genesis 2002 $this->escape($args);
mp-wp_genesis 2003
mp-wp_genesis 2004 $blog_ID = (int) $args[0]; // we will support this in the near future
mp-wp_genesis 2005 $user_login = $args[1];
mp-wp_genesis 2006 $user_pass = $args[2];
mp-wp_genesis 2007 $content_struct = $args[3];
mp-wp_genesis 2008 $publish = $args[4];
mp-wp_genesis 2009
mp-wp_genesis 2010 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 2011 return $this->error;
mp-wp_genesis 2012 }
mp-wp_genesis 2013 $user = set_current_user(0, $user_login);
mp-wp_genesis 2014
mp-wp_genesis 2015 do_action('xmlrpc_call', 'metaWeblog.newPost');
mp-wp_genesis 2016
mp-wp_genesis 2017 $cap = ( $publish ) ? 'publish_posts' : 'edit_posts';
mp-wp_genesis 2018 $error_message = __( 'Sorry, you are not allowed to publish posts on this blog.' );
mp-wp_genesis 2019 $post_type = 'post';
mp-wp_genesis 2020 $page_template = '';
mp-wp_genesis 2021 if( !empty( $content_struct['post_type'] ) ) {
mp-wp_genesis 2022 if( $content_struct['post_type'] == 'page' ) {
mp-wp_genesis 2023 $cap = ( $publish ) ? 'publish_pages' : 'edit_pages';
mp-wp_genesis 2024 $error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' );
mp-wp_genesis 2025 $post_type = 'page';
mp-wp_genesis 2026 if( !empty( $content_struct['wp_page_template'] ) )
mp-wp_genesis 2027 $page_template = $content_struct['wp_page_template'];
mp-wp_genesis 2028 }
mp-wp_genesis 2029 elseif( $content_struct['post_type'] == 'post' ) {
mp-wp_genesis 2030 // This is the default, no changes needed
mp-wp_genesis 2031 }
mp-wp_genesis 2032 else {
mp-wp_genesis 2033 // No other post_type values are allowed here
mp-wp_genesis 2034 return new IXR_Error( 401, __( 'Invalid post type.' ) );
mp-wp_genesis 2035 }
mp-wp_genesis 2036 }
mp-wp_genesis 2037
mp-wp_genesis 2038 if( !current_user_can( $cap ) ) {
mp-wp_genesis 2039 return new IXR_Error( 401, $error_message );
mp-wp_genesis 2040 }
mp-wp_genesis 2041
mp-wp_genesis 2042 // Let WordPress generate the post_name (slug) unless
mp-wp_genesis 2043 // one has been provided.
mp-wp_genesis 2044 $post_name = "";
mp-wp_genesis 2045 if(isset($content_struct["wp_slug"])) {
mp-wp_genesis 2046 $post_name = $content_struct["wp_slug"];
mp-wp_genesis 2047 }
mp-wp_genesis 2048
mp-wp_genesis 2049 // Only use a password if one was given.
mp-wp_genesis 2050 if(isset($content_struct["wp_password"])) {
mp-wp_genesis 2051 $post_password = $content_struct["wp_password"];
mp-wp_genesis 2052 }
mp-wp_genesis 2053
mp-wp_genesis 2054 // Only set a post parent if one was provided.
mp-wp_genesis 2055 if(isset($content_struct["wp_page_parent_id"])) {
mp-wp_genesis 2056 $post_parent = $content_struct["wp_page_parent_id"];
mp-wp_genesis 2057 }
mp-wp_genesis 2058
mp-wp_genesis 2059 // Only set the menu_order if it was provided.
mp-wp_genesis 2060 if(isset($content_struct["wp_page_order"])) {
mp-wp_genesis 2061 $menu_order = $content_struct["wp_page_order"];
mp-wp_genesis 2062 }
mp-wp_genesis 2063
mp-wp_genesis 2064 $post_author = $user->ID;
mp-wp_genesis 2065
mp-wp_genesis 2066 // If an author id was provided then use it instead.
mp-wp_genesis 2067 if(
mp-wp_genesis 2068 isset($content_struct["wp_author_id"])
mp-wp_genesis 2069 && ($user->ID != $content_struct["wp_author_id"])
mp-wp_genesis 2070 ) {
mp-wp_genesis 2071 switch($post_type) {
mp-wp_genesis 2072 case "post":
mp-wp_genesis 2073 if(!current_user_can("edit_others_posts")) {
mp-wp_genesis 2074 return(new IXR_Error(401, __("You are not allowed to post as this user")));
mp-wp_genesis 2075 }
mp-wp_genesis 2076 break;
mp-wp_genesis 2077 case "page":
mp-wp_genesis 2078 if(!current_user_can("edit_others_pages")) {
mp-wp_genesis 2079 return(new IXR_Error(401, __("You are not allowed to create pages as this user")));
mp-wp_genesis 2080 }
mp-wp_genesis 2081 break;
mp-wp_genesis 2082 default:
mp-wp_genesis 2083 return(new IXR_Error(401, __("Invalid post type.")));
mp-wp_genesis 2084 break;
mp-wp_genesis 2085 }
mp-wp_genesis 2086 $post_author = $content_struct["wp_author_id"];
mp-wp_genesis 2087 }
mp-wp_genesis 2088
mp-wp_genesis 2089 $post_title = $content_struct['title'];
mp-wp_genesis 2090 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
mp-wp_genesis 2091
mp-wp_genesis 2092 $post_status = $publish ? 'publish' : 'draft';
mp-wp_genesis 2093
mp-wp_genesis 2094 if( isset( $content_struct["{$post_type}_status"] ) ) {
mp-wp_genesis 2095 switch( $content_struct["{$post_type}_status"] ) {
mp-wp_genesis 2096 case 'draft':
mp-wp_genesis 2097 case 'private':
mp-wp_genesis 2098 case 'publish':
mp-wp_genesis 2099 $post_status = $content_struct["{$post_type}_status"];
mp-wp_genesis 2100 break;
mp-wp_genesis 2101 case 'pending':
mp-wp_genesis 2102 // Pending is only valid for posts, not pages.
mp-wp_genesis 2103 if( $post_type === 'post' ) {
mp-wp_genesis 2104 $post_status = $content_struct["{$post_type}_status"];
mp-wp_genesis 2105 }
mp-wp_genesis 2106 break;
mp-wp_genesis 2107 default:
mp-wp_genesis 2108 $post_status = $publish ? 'publish' : 'draft';
mp-wp_genesis 2109 break;
mp-wp_genesis 2110 }
mp-wp_genesis 2111 }
mp-wp_genesis 2112
mp-wp_genesis 2113 $post_excerpt = $content_struct['mt_excerpt'];
mp-wp_genesis 2114 $post_more = $content_struct['mt_text_more'];
mp-wp_genesis 2115
mp-wp_genesis 2116 $tags_input = $content_struct['mt_keywords'];
mp-wp_genesis 2117
mp-wp_genesis 2118 if(isset($content_struct["mt_allow_comments"])) {
mp-wp_genesis 2119 if(!is_numeric($content_struct["mt_allow_comments"])) {
mp-wp_genesis 2120 switch($content_struct["mt_allow_comments"]) {
mp-wp_genesis 2121 case "closed":
mp-wp_genesis 2122 $comment_status = "closed";
mp-wp_genesis 2123 break;
mp-wp_genesis 2124 case "open":
mp-wp_genesis 2125 $comment_status = "open";
mp-wp_genesis 2126 break;
mp-wp_genesis 2127 default:
mp-wp_genesis 2128 $comment_status = get_option("default_comment_status");
mp-wp_genesis 2129 break;
mp-wp_genesis 2130 }
mp-wp_genesis 2131 }
mp-wp_genesis 2132 else {
mp-wp_genesis 2133 switch((int) $content_struct["mt_allow_comments"]) {
mp-wp_genesis 2134 case 0:
mp-wp_genesis 2135 case 2:
mp-wp_genesis 2136 $comment_status = "closed";
mp-wp_genesis 2137 break;
mp-wp_genesis 2138 case 1:
mp-wp_genesis 2139 $comment_status = "open";
mp-wp_genesis 2140 break;
mp-wp_genesis 2141 default:
mp-wp_genesis 2142 $comment_status = get_option("default_comment_status");
mp-wp_genesis 2143 break;
mp-wp_genesis 2144 }
mp-wp_genesis 2145 }
mp-wp_genesis 2146 }
mp-wp_genesis 2147 else {
mp-wp_genesis 2148 $comment_status = get_option("default_comment_status");
mp-wp_genesis 2149 }
mp-wp_genesis 2150
mp-wp_genesis 2151 if(isset($content_struct["mt_allow_pings"])) {
mp-wp_genesis 2152 if(!is_numeric($content_struct["mt_allow_pings"])) {
mp-wp_genesis 2153 switch($content_struct['mt_allow_pings']) {
mp-wp_genesis 2154 case "closed":
mp-wp_genesis 2155 $ping_status = "closed";
mp-wp_genesis 2156 break;
mp-wp_genesis 2157 case "open":
mp-wp_genesis 2158 $ping_status = "open";
mp-wp_genesis 2159 break;
mp-wp_genesis 2160 default:
mp-wp_genesis 2161 $ping_status = get_option("default_ping_status");
mp-wp_genesis 2162 break;
mp-wp_genesis 2163 }
mp-wp_genesis 2164 }
mp-wp_genesis 2165 else {
mp-wp_genesis 2166 switch((int) $content_struct["mt_allow_pings"]) {
mp-wp_genesis 2167 case 0:
mp-wp_genesis 2168 $ping_status = "closed";
mp-wp_genesis 2169 break;
mp-wp_genesis 2170 case 1:
mp-wp_genesis 2171 $ping_status = "open";
mp-wp_genesis 2172 break;
mp-wp_genesis 2173 default:
mp-wp_genesis 2174 $ping_status = get_option("default_ping_status");
mp-wp_genesis 2175 break;
mp-wp_genesis 2176 }
mp-wp_genesis 2177 }
mp-wp_genesis 2178 }
mp-wp_genesis 2179 else {
mp-wp_genesis 2180 $ping_status = get_option("default_ping_status");
mp-wp_genesis 2181 }
mp-wp_genesis 2182
mp-wp_genesis 2183 if ($post_more) {
mp-wp_genesis 2184 $post_content = $post_content . "<!--more-->" . $post_more;
mp-wp_genesis 2185 }
mp-wp_genesis 2186
mp-wp_genesis 2187 $to_ping = $content_struct['mt_tb_ping_urls'];
mp-wp_genesis 2188 if ( is_array($to_ping) )
mp-wp_genesis 2189 $to_ping = implode(' ', $to_ping);
mp-wp_genesis 2190
mp-wp_genesis 2191 // Do some timestamp voodoo
mp-wp_genesis 2192 if ( !empty( $content_struct['date_created_gmt'] ) )
mp-wp_genesis 2193 $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
mp-wp_genesis 2194 elseif ( !empty( $content_struct['dateCreated']) )
mp-wp_genesis 2195 $dateCreated = $content_struct['dateCreated']->getIso();
mp-wp_genesis 2196
mp-wp_genesis 2197 if ( !empty( $dateCreated ) ) {
mp-wp_genesis 2198 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
mp-wp_genesis 2199 $post_date_gmt = iso8601_to_datetime($dateCreated, GMT);
mp-wp_genesis 2200 } else {
mp-wp_genesis 2201 $post_date = current_time('mysql');
mp-wp_genesis 2202 $post_date_gmt = current_time('mysql', 1);
mp-wp_genesis 2203 }
mp-wp_genesis 2204
mp-wp_genesis 2205 $catnames = $content_struct['categories'];
mp-wp_genesis 2206 logIO('O', 'Post cats: ' . var_export($catnames,true));
mp-wp_genesis 2207 $post_category = array();
mp-wp_genesis 2208
mp-wp_genesis 2209 if (is_array($catnames)) {
mp-wp_genesis 2210 foreach ($catnames as $cat) {
mp-wp_genesis 2211 $post_category[] = get_cat_ID($cat);
mp-wp_genesis 2212 }
mp-wp_genesis 2213 }
mp-wp_genesis 2214
mp-wp_genesis 2215 // We've got all the data -- post it:
mp-wp_genesis 2216 $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');
mp-wp_genesis 2217
mp-wp_genesis 2218 $post_ID = wp_insert_post($postdata, true);
mp-wp_genesis 2219 if ( is_wp_error( $post_ID ) )
mp-wp_genesis 2220 return new IXR_Error(500, $post_ID->get_error_message());
mp-wp_genesis 2221
mp-wp_genesis 2222 if (!$post_ID) {
mp-wp_genesis 2223 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
mp-wp_genesis 2224 }
mp-wp_genesis 2225
mp-wp_genesis 2226 if ( isset($content_struct['custom_fields']) ) {
mp-wp_genesis 2227 $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
mp-wp_genesis 2228 }
mp-wp_genesis 2229
mp-wp_genesis 2230 // Handle enclosures
mp-wp_genesis 2231 $enclosure = $content_struct['enclosure'];
mp-wp_genesis 2232 if( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) {
mp-wp_genesis 2233 add_post_meta( $post_ID, 'enclosure', $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] );
mp-wp_genesis 2234 }
mp-wp_genesis 2235
mp-wp_genesis 2236 $this->attach_uploads( $post_ID, $post_content );
mp-wp_genesis 2237
mp-wp_genesis 2238 logIO('O', "Posted ! ID: $post_ID");
mp-wp_genesis 2239
mp-wp_genesis 2240 return strval($post_ID);
mp-wp_genesis 2241 }
mp-wp_genesis 2242
mp-wp_genesis 2243 /**
mp-wp_genesis 2244 * Attach upload to a post.
mp-wp_genesis 2245 *
mp-wp_genesis 2246 * @since 2.1.0
mp-wp_genesis 2247 *
mp-wp_genesis 2248 * @param int $post_ID Post ID.
mp-wp_genesis 2249 * @param string $post_content Post Content for attachment.
mp-wp_genesis 2250 */
mp-wp_genesis 2251 function attach_uploads( $post_ID, $post_content ) {
mp-wp_genesis 2252 global $wpdb;
mp-wp_genesis 2253
mp-wp_genesis 2254 // find any unattached files
mp-wp_genesis 2255 $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '-1' AND post_type = 'attachment'" );
mp-wp_genesis 2256 if( is_array( $attachments ) ) {
mp-wp_genesis 2257 foreach( $attachments as $file ) {
mp-wp_genesis 2258 if( strpos( $post_content, $file->guid ) !== false ) {
mp-wp_genesis 2259 $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", $post_ID, $file->ID) );
mp-wp_genesis 2260 }
mp-wp_genesis 2261 }
mp-wp_genesis 2262 }
mp-wp_genesis 2263 }
mp-wp_genesis 2264
mp-wp_genesis 2265 /**
mp-wp_genesis 2266 * Edit a post.
mp-wp_genesis 2267 *
mp-wp_genesis 2268 * @since 1.5.0
mp-wp_genesis 2269 *
mp-wp_genesis 2270 * @param array $args Method parameters.
mp-wp_genesis 2271 * @return bool True on success.
mp-wp_genesis 2272 */
mp-wp_genesis 2273 function mw_editPost($args) {
mp-wp_genesis 2274
mp-wp_genesis 2275 $this->escape($args);
mp-wp_genesis 2276
mp-wp_genesis 2277 $post_ID = (int) $args[0];
mp-wp_genesis 2278 $user_login = $args[1];
mp-wp_genesis 2279 $user_pass = $args[2];
mp-wp_genesis 2280 $content_struct = $args[3];
mp-wp_genesis 2281 $publish = $args[4];
mp-wp_genesis 2282
mp-wp_genesis 2283 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 2284 return $this->error;
mp-wp_genesis 2285 }
mp-wp_genesis 2286 $user = set_current_user(0, $user_login);
mp-wp_genesis 2287
mp-wp_genesis 2288 do_action('xmlrpc_call', 'metaWeblog.editPost');
mp-wp_genesis 2289
mp-wp_genesis 2290 $cap = ( $publish ) ? 'publish_posts' : 'edit_posts';
mp-wp_genesis 2291 $error_message = __( 'Sorry, you are not allowed to publish posts on this blog.' );
mp-wp_genesis 2292 $post_type = 'post';
mp-wp_genesis 2293 $page_template = '';
mp-wp_genesis 2294 if( !empty( $content_struct['post_type'] ) ) {
mp-wp_genesis 2295 if( $content_struct['post_type'] == 'page' ) {
mp-wp_genesis 2296 $cap = ( $publish ) ? 'publish_pages' : 'edit_pages';
mp-wp_genesis 2297 $error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' );
mp-wp_genesis 2298 $post_type = 'page';
mp-wp_genesis 2299 if( !empty( $content_struct['wp_page_template'] ) )
mp-wp_genesis 2300 $page_template = $content_struct['wp_page_template'];
mp-wp_genesis 2301 }
mp-wp_genesis 2302 elseif( $content_struct['post_type'] == 'post' ) {
mp-wp_genesis 2303 // This is the default, no changes needed
mp-wp_genesis 2304 }
mp-wp_genesis 2305 else {
mp-wp_genesis 2306 // No other post_type values are allowed here
mp-wp_genesis 2307 return new IXR_Error( 401, __( 'Invalid post type.' ) );
mp-wp_genesis 2308 }
mp-wp_genesis 2309 }
mp-wp_genesis 2310
mp-wp_genesis 2311 if( !current_user_can( $cap ) ) {
mp-wp_genesis 2312 return new IXR_Error( 401, $error_message );
mp-wp_genesis 2313 }
mp-wp_genesis 2314
mp-wp_genesis 2315 $postdata = wp_get_single_post($post_ID, ARRAY_A);
mp-wp_genesis 2316
mp-wp_genesis 2317 // If there is no post data for the give post id, stop
mp-wp_genesis 2318 // now and return an error. Other wise a new post will be
mp-wp_genesis 2319 // created (which was the old behavior).
mp-wp_genesis 2320 if(empty($postdata["ID"])) {
mp-wp_genesis 2321 return(new IXR_Error(404, __("Invalid post id.")));
mp-wp_genesis 2322 }
mp-wp_genesis 2323
mp-wp_genesis 2324 $this->escape($postdata);
mp-wp_genesis 2325 extract($postdata, EXTR_SKIP);
mp-wp_genesis 2326
mp-wp_genesis 2327 // Let WordPress manage slug if none was provided.
mp-wp_genesis 2328 $post_name = "";
mp-wp_genesis 2329 if(isset($content_struct["wp_slug"])) {
mp-wp_genesis 2330 $post_name = $content_struct["wp_slug"];
mp-wp_genesis 2331 }
mp-wp_genesis 2332
mp-wp_genesis 2333 // Only use a password if one was given.
mp-wp_genesis 2334 if(isset($content_struct["wp_password"])) {
mp-wp_genesis 2335 $post_password = $content_struct["wp_password"];
mp-wp_genesis 2336 }
mp-wp_genesis 2337
mp-wp_genesis 2338 // Only set a post parent if one was given.
mp-wp_genesis 2339 if(isset($content_struct["wp_page_parent_id"])) {
mp-wp_genesis 2340 $post_parent = $content_struct["wp_page_parent_id"];
mp-wp_genesis 2341 }
mp-wp_genesis 2342
mp-wp_genesis 2343 // Only set the menu_order if it was given.
mp-wp_genesis 2344 if(isset($content_struct["wp_page_order"])) {
mp-wp_genesis 2345 $menu_order = $content_struct["wp_page_order"];
mp-wp_genesis 2346 }
mp-wp_genesis 2347
mp-wp_genesis 2348 $post_author = $postdata["post_author"];
mp-wp_genesis 2349
mp-wp_genesis 2350 // Only set the post_author if one is set.
mp-wp_genesis 2351 if(
mp-wp_genesis 2352 isset($content_struct["wp_author_id"])
mp-wp_genesis 2353 && ($user->ID != $content_struct["wp_author_id"])
mp-wp_genesis 2354 ) {
mp-wp_genesis 2355 switch($post_type) {
mp-wp_genesis 2356 case "post":
mp-wp_genesis 2357 if(!current_user_can("edit_others_posts")) {
mp-wp_genesis 2358 return(new IXR_Error(401, __("You are not allowed to change the post author as this user.")));
mp-wp_genesis 2359 }
mp-wp_genesis 2360 break;
mp-wp_genesis 2361 case "page":
mp-wp_genesis 2362 if(!current_user_can("edit_others_pages")) {
mp-wp_genesis 2363 return(new IXR_Error(401, __("You are not allowed to change the page author as this user.")));
mp-wp_genesis 2364 }
mp-wp_genesis 2365 break;
mp-wp_genesis 2366 default:
mp-wp_genesis 2367 return(new IXR_Error(401, __("Invalid post type.")));
mp-wp_genesis 2368 break;
mp-wp_genesis 2369 }
mp-wp_genesis 2370 $post_author = $content_struct["wp_author_id"];
mp-wp_genesis 2371 }
mp-wp_genesis 2372
mp-wp_genesis 2373 if(isset($content_struct["mt_allow_comments"])) {
mp-wp_genesis 2374 if(!is_numeric($content_struct["mt_allow_comments"])) {
mp-wp_genesis 2375 switch($content_struct["mt_allow_comments"]) {
mp-wp_genesis 2376 case "closed":
mp-wp_genesis 2377 $comment_status = "closed";
mp-wp_genesis 2378 break;
mp-wp_genesis 2379 case "open":
mp-wp_genesis 2380 $comment_status = "open";
mp-wp_genesis 2381 break;
mp-wp_genesis 2382 default:
mp-wp_genesis 2383 $comment_status = get_option("default_comment_status");
mp-wp_genesis 2384 break;
mp-wp_genesis 2385 }
mp-wp_genesis 2386 }
mp-wp_genesis 2387 else {
mp-wp_genesis 2388 switch((int) $content_struct["mt_allow_comments"]) {
mp-wp_genesis 2389 case 0:
mp-wp_genesis 2390 case 2:
mp-wp_genesis 2391 $comment_status = "closed";
mp-wp_genesis 2392 break;
mp-wp_genesis 2393 case 1:
mp-wp_genesis 2394 $comment_status = "open";
mp-wp_genesis 2395 break;
mp-wp_genesis 2396 default:
mp-wp_genesis 2397 $comment_status = get_option("default_comment_status");
mp-wp_genesis 2398 break;
mp-wp_genesis 2399 }
mp-wp_genesis 2400 }
mp-wp_genesis 2401 }
mp-wp_genesis 2402
mp-wp_genesis 2403 if(isset($content_struct["mt_allow_pings"])) {
mp-wp_genesis 2404 if(!is_numeric($content_struct["mt_allow_pings"])) {
mp-wp_genesis 2405 switch($content_struct["mt_allow_pings"]) {
mp-wp_genesis 2406 case "closed":
mp-wp_genesis 2407 $ping_status = "closed";
mp-wp_genesis 2408 break;
mp-wp_genesis 2409 case "open":
mp-wp_genesis 2410 $ping_status = "open";
mp-wp_genesis 2411 break;
mp-wp_genesis 2412 default:
mp-wp_genesis 2413 $ping_status = get_option("default_ping_status");
mp-wp_genesis 2414 break;
mp-wp_genesis 2415 }
mp-wp_genesis 2416 }
mp-wp_genesis 2417 else {
mp-wp_genesis 2418 switch((int) $content_struct["mt_allow_pings"]) {
mp-wp_genesis 2419 case 0:
mp-wp_genesis 2420 $ping_status = "closed";
mp-wp_genesis 2421 break;
mp-wp_genesis 2422 case 1:
mp-wp_genesis 2423 $ping_status = "open";
mp-wp_genesis 2424 break;
mp-wp_genesis 2425 default:
mp-wp_genesis 2426 $ping_status = get_option("default_ping_status");
mp-wp_genesis 2427 break;
mp-wp_genesis 2428 }
mp-wp_genesis 2429 }
mp-wp_genesis 2430 }
mp-wp_genesis 2431
mp-wp_genesis 2432 $post_title = $content_struct['title'];
mp-wp_genesis 2433 $post_content = apply_filters( 'content_save_pre', $content_struct['description'] );
mp-wp_genesis 2434 $catnames = $content_struct['categories'];
mp-wp_genesis 2435
mp-wp_genesis 2436 $post_category = array();
mp-wp_genesis 2437
mp-wp_genesis 2438 if (is_array($catnames)) {
mp-wp_genesis 2439 foreach ($catnames as $cat) {
mp-wp_genesis 2440 $post_category[] = get_cat_ID($cat);
mp-wp_genesis 2441 }
mp-wp_genesis 2442 }
mp-wp_genesis 2443
mp-wp_genesis 2444 $post_excerpt = $content_struct['mt_excerpt'];
mp-wp_genesis 2445 $post_more = $content_struct['mt_text_more'];
mp-wp_genesis 2446
mp-wp_genesis 2447 $post_status = $publish ? 'publish' : 'draft';
mp-wp_genesis 2448 if( isset( $content_struct["{$post_type}_status"] ) ) {
mp-wp_genesis 2449 switch( $content_struct["{$post_type}_status"] ) {
mp-wp_genesis 2450 case 'draft':
mp-wp_genesis 2451 case 'private':
mp-wp_genesis 2452 case 'publish':
mp-wp_genesis 2453 $post_status = $content_struct["{$post_type}_status"];
mp-wp_genesis 2454 break;
mp-wp_genesis 2455 case 'pending':
mp-wp_genesis 2456 // Pending is only valid for posts, not pages.
mp-wp_genesis 2457 if( $post_type === 'post' ) {
mp-wp_genesis 2458 $post_status = $content_struct["{$post_type}_status"];
mp-wp_genesis 2459 }
mp-wp_genesis 2460 break;
mp-wp_genesis 2461 default:
mp-wp_genesis 2462 $post_status = $publish ? 'publish' : 'draft';
mp-wp_genesis 2463 break;
mp-wp_genesis 2464 }
mp-wp_genesis 2465 }
mp-wp_genesis 2466
mp-wp_genesis 2467 $tags_input = $content_struct['mt_keywords'];
mp-wp_genesis 2468
mp-wp_genesis 2469 if ( ('publish' == $post_status) ) {
mp-wp_genesis 2470 if ( ( 'page' == $post_type ) && !current_user_can('publish_pages') )
mp-wp_genesis 2471 return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.'));
mp-wp_genesis 2472 else if ( !current_user_can('publish_posts') )
mp-wp_genesis 2473 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
mp-wp_genesis 2474 }
mp-wp_genesis 2475
mp-wp_genesis 2476 if ($post_more) {
mp-wp_genesis 2477 $post_content = $post_content . "<!--more-->" . $post_more;
mp-wp_genesis 2478 }
mp-wp_genesis 2479
mp-wp_genesis 2480 $to_ping = $content_struct['mt_tb_ping_urls'];
mp-wp_genesis 2481 if ( is_array($to_ping) )
mp-wp_genesis 2482 $to_ping = implode(' ', $to_ping);
mp-wp_genesis 2483
mp-wp_genesis 2484 // Do some timestamp voodoo
mp-wp_genesis 2485 if ( !empty( $content_struct['date_created_gmt'] ) )
mp-wp_genesis 2486 $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
mp-wp_genesis 2487 elseif ( !empty( $content_struct['dateCreated']) )
mp-wp_genesis 2488 $dateCreated = $content_struct['dateCreated']->getIso();
mp-wp_genesis 2489
mp-wp_genesis 2490 if ( !empty( $dateCreated ) ) {
mp-wp_genesis 2491 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
mp-wp_genesis 2492 $post_date_gmt = iso8601_to_datetime($dateCreated, GMT);
mp-wp_genesis 2493 } else {
mp-wp_genesis 2494 $post_date = $postdata['post_date'];
mp-wp_genesis 2495 $post_date_gmt = $postdata['post_date_gmt'];
mp-wp_genesis 2496 }
mp-wp_genesis 2497
mp-wp_genesis 2498 // We've got all the data -- post it:
mp-wp_genesis 2499 $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');
mp-wp_genesis 2500
mp-wp_genesis 2501 $result = wp_update_post($newpost, true);
mp-wp_genesis 2502 if ( is_wp_error( $result ) )
mp-wp_genesis 2503 return new IXR_Error(500, $result->get_error_message());
mp-wp_genesis 2504
mp-wp_genesis 2505 if (!$result) {
mp-wp_genesis 2506 return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.'));
mp-wp_genesis 2507 }
mp-wp_genesis 2508
mp-wp_genesis 2509 if ( isset($content_struct['custom_fields']) ) {
mp-wp_genesis 2510 $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
mp-wp_genesis 2511 }
mp-wp_genesis 2512
mp-wp_genesis 2513 // Handle enclosures
mp-wp_genesis 2514 $enclosure = $content_struct['enclosure'];
mp-wp_genesis 2515 if( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) {
mp-wp_genesis 2516 add_post_meta( $post_ID, 'enclosure', $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] );
mp-wp_genesis 2517 }
mp-wp_genesis 2518
mp-wp_genesis 2519 $this->attach_uploads( $ID, $post_content );
mp-wp_genesis 2520
mp-wp_genesis 2521 logIO('O',"(MW) Edited ! ID: $post_ID");
mp-wp_genesis 2522
mp-wp_genesis 2523 return true;
mp-wp_genesis 2524 }
mp-wp_genesis 2525
mp-wp_genesis 2526 /**
mp-wp_genesis 2527 * Retrieve post.
mp-wp_genesis 2528 *
mp-wp_genesis 2529 * @since 1.5.0
mp-wp_genesis 2530 *
mp-wp_genesis 2531 * @param array $args Method parameters.
mp-wp_genesis 2532 * @return array
mp-wp_genesis 2533 */
mp-wp_genesis 2534 function mw_getPost($args) {
mp-wp_genesis 2535
mp-wp_genesis 2536 $this->escape($args);
mp-wp_genesis 2537
mp-wp_genesis 2538 $post_ID = (int) $args[0];
mp-wp_genesis 2539 $user_login = $args[1];
mp-wp_genesis 2540 $user_pass = $args[2];
mp-wp_genesis 2541
mp-wp_genesis 2542 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 2543 return $this->error;
mp-wp_genesis 2544 }
mp-wp_genesis 2545
mp-wp_genesis 2546 set_current_user( 0, $user_login );
mp-wp_genesis 2547 if( !current_user_can( 'edit_post', $post_ID ) )
mp-wp_genesis 2548 return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) );
mp-wp_genesis 2549
mp-wp_genesis 2550 do_action('xmlrpc_call', 'metaWeblog.getPost');
mp-wp_genesis 2551
mp-wp_genesis 2552 $postdata = wp_get_single_post($post_ID, ARRAY_A);
mp-wp_genesis 2553
mp-wp_genesis 2554 if ($postdata['post_date'] != '') {
mp-wp_genesis 2555 $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']);
mp-wp_genesis 2556 $post_date_gmt = mysql2date('Ymd\TH:i:s', $postdata['post_date_gmt']);
mp-wp_genesis 2557
mp-wp_genesis 2558 $categories = array();
mp-wp_genesis 2559 $catids = wp_get_post_categories($post_ID);
mp-wp_genesis 2560 foreach($catids as $catid)
mp-wp_genesis 2561 $categories[] = get_cat_name($catid);
mp-wp_genesis 2562
mp-wp_genesis 2563 $tagnames = array();
mp-wp_genesis 2564 $tags = wp_get_post_tags( $post_ID );
mp-wp_genesis 2565 if ( !empty( $tags ) ) {
mp-wp_genesis 2566 foreach ( $tags as $tag )
mp-wp_genesis 2567 $tagnames[] = $tag->name;
mp-wp_genesis 2568 $tagnames = implode( ', ', $tagnames );
mp-wp_genesis 2569 } else {
mp-wp_genesis 2570 $tagnames = '';
mp-wp_genesis 2571 }
mp-wp_genesis 2572
mp-wp_genesis 2573 $post = get_extended($postdata['post_content']);
mp-wp_genesis 2574 $link = post_permalink($postdata['ID']);
mp-wp_genesis 2575
mp-wp_genesis 2576 // Get the author info.
mp-wp_genesis 2577 $author = get_userdata($postdata['post_author']);
mp-wp_genesis 2578
mp-wp_genesis 2579 $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
mp-wp_genesis 2580 $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
mp-wp_genesis 2581
mp-wp_genesis 2582 // Consider future posts as published
mp-wp_genesis 2583 if( $postdata['post_status'] === 'future' ) {
mp-wp_genesis 2584 $postdata['post_status'] = 'publish';
mp-wp_genesis 2585 }
mp-wp_genesis 2586
mp-wp_genesis 2587 $enclosure = array();
mp-wp_genesis 2588 foreach ( (array) get_post_custom($post_ID) as $key => $val) {
mp-wp_genesis 2589 if ($key == 'enclosure') {
mp-wp_genesis 2590 foreach ( (array) $val as $enc ) {
mp-wp_genesis 2591 $encdata = split("\n", $enc);
mp-wp_genesis 2592 $enclosure['url'] = trim(htmlspecialchars($encdata[0]));
mp-wp_genesis 2593 $enclosure['length'] = trim($encdata[1]);
mp-wp_genesis 2594 $enclosure['type'] = trim($encdata[2]);
mp-wp_genesis 2595 break 2;
mp-wp_genesis 2596 }
mp-wp_genesis 2597 }
mp-wp_genesis 2598 }
mp-wp_genesis 2599
mp-wp_genesis 2600 $resp = array(
mp-wp_genesis 2601 'dateCreated' => new IXR_Date($post_date),
mp-wp_genesis 2602 'userid' => $postdata['post_author'],
mp-wp_genesis 2603 'postid' => $postdata['ID'],
mp-wp_genesis 2604 'description' => $post['main'],
mp-wp_genesis 2605 'title' => $postdata['post_title'],
mp-wp_genesis 2606 'link' => $link,
mp-wp_genesis 2607 'permaLink' => $link,
mp-wp_genesis 2608 // commented out because no other tool seems to use this
mp-wp_genesis 2609 // 'content' => $entry['post_content'],
mp-wp_genesis 2610 'categories' => $categories,
mp-wp_genesis 2611 'mt_excerpt' => $postdata['post_excerpt'],
mp-wp_genesis 2612 'mt_text_more' => $post['extended'],
mp-wp_genesis 2613 'mt_allow_comments' => $allow_comments,
mp-wp_genesis 2614 'mt_allow_pings' => $allow_pings,
mp-wp_genesis 2615 'mt_keywords' => $tagnames,
mp-wp_genesis 2616 'wp_slug' => $postdata['post_name'],
mp-wp_genesis 2617 'wp_password' => $postdata['post_password'],
mp-wp_genesis 2618 'wp_author_id' => $author->ID,
mp-wp_genesis 2619 'wp_author_display_name' => $author->display_name,
mp-wp_genesis 2620 'date_created_gmt' => new IXR_Date($post_date_gmt),
mp-wp_genesis 2621 'post_status' => $postdata['post_status'],
mp-wp_genesis 2622 'custom_fields' => $this->get_custom_fields($post_ID)
mp-wp_genesis 2623 );
mp-wp_genesis 2624
mp-wp_genesis 2625 if (!empty($enclosure)) $resp['enclosure'] = $enclosure;
mp-wp_genesis 2626
mp-wp_genesis 2627 return $resp;
mp-wp_genesis 2628 } else {
mp-wp_genesis 2629 return new IXR_Error(404, __('Sorry, no such post.'));
mp-wp_genesis 2630 }
mp-wp_genesis 2631 }
mp-wp_genesis 2632
mp-wp_genesis 2633 /**
mp-wp_genesis 2634 * Retrieve list of recent posts.
mp-wp_genesis 2635 *
mp-wp_genesis 2636 * @since 1.5.0
mp-wp_genesis 2637 *
mp-wp_genesis 2638 * @param array $args Method parameters.
mp-wp_genesis 2639 * @return array
mp-wp_genesis 2640 */
mp-wp_genesis 2641 function mw_getRecentPosts($args) {
mp-wp_genesis 2642
mp-wp_genesis 2643 $this->escape($args);
mp-wp_genesis 2644
mp-wp_genesis 2645 $blog_ID = (int) $args[0];
mp-wp_genesis 2646 $user_login = $args[1];
mp-wp_genesis 2647 $user_pass = $args[2];
mp-wp_genesis 2648 $num_posts = (int) $args[3];
mp-wp_genesis 2649
mp-wp_genesis 2650 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 2651 return $this->error;
mp-wp_genesis 2652 }
mp-wp_genesis 2653
mp-wp_genesis 2654 do_action('xmlrpc_call', 'metaWeblog.getRecentPosts');
mp-wp_genesis 2655
mp-wp_genesis 2656 $posts_list = wp_get_recent_posts($num_posts);
mp-wp_genesis 2657
mp-wp_genesis 2658 if (!$posts_list) {
mp-wp_genesis 2659 return array( );
mp-wp_genesis 2660 }
mp-wp_genesis 2661
mp-wp_genesis 2662 set_current_user( 0, $user_login );
mp-wp_genesis 2663
mp-wp_genesis 2664 foreach ($posts_list as $entry) {
mp-wp_genesis 2665 if( !current_user_can( 'edit_post', $entry['ID'] ) )
mp-wp_genesis 2666 continue;
mp-wp_genesis 2667
mp-wp_genesis 2668 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
mp-wp_genesis 2669 $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt']);
mp-wp_genesis 2670
mp-wp_genesis 2671 $categories = array();
mp-wp_genesis 2672 $catids = wp_get_post_categories($entry['ID']);
mp-wp_genesis 2673 foreach($catids as $catid) {
mp-wp_genesis 2674 $categories[] = get_cat_name($catid);
mp-wp_genesis 2675 }
mp-wp_genesis 2676
mp-wp_genesis 2677 $tagnames = array();
mp-wp_genesis 2678 $tags = wp_get_post_tags( $entry['ID'] );
mp-wp_genesis 2679 if ( !empty( $tags ) ) {
mp-wp_genesis 2680 foreach ( $tags as $tag ) {
mp-wp_genesis 2681 $tagnames[] = $tag->name;
mp-wp_genesis 2682 }
mp-wp_genesis 2683 $tagnames = implode( ', ', $tagnames );
mp-wp_genesis 2684 } else {
mp-wp_genesis 2685 $tagnames = '';
mp-wp_genesis 2686 }
mp-wp_genesis 2687
mp-wp_genesis 2688 $post = get_extended($entry['post_content']);
mp-wp_genesis 2689 $link = post_permalink($entry['ID']);
mp-wp_genesis 2690
mp-wp_genesis 2691 // Get the post author info.
mp-wp_genesis 2692 $author = get_userdata($entry['post_author']);
mp-wp_genesis 2693
mp-wp_genesis 2694 $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0;
mp-wp_genesis 2695 $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0;
mp-wp_genesis 2696
mp-wp_genesis 2697 // Consider future posts as published
mp-wp_genesis 2698 if( $entry['post_status'] === 'future' ) {
mp-wp_genesis 2699 $entry['post_status'] = 'publish';
mp-wp_genesis 2700 }
mp-wp_genesis 2701
mp-wp_genesis 2702 $struct[] = array(
mp-wp_genesis 2703 'dateCreated' => new IXR_Date($post_date),
mp-wp_genesis 2704 'userid' => $entry['post_author'],
mp-wp_genesis 2705 'postid' => $entry['ID'],
mp-wp_genesis 2706 'description' => $post['main'],
mp-wp_genesis 2707 'title' => $entry['post_title'],
mp-wp_genesis 2708 'link' => $link,
mp-wp_genesis 2709 'permaLink' => $link,
mp-wp_genesis 2710 // commented out because no other tool seems to use this
mp-wp_genesis 2711 // 'content' => $entry['post_content'],
mp-wp_genesis 2712 'categories' => $categories,
mp-wp_genesis 2713 'mt_excerpt' => $entry['post_excerpt'],
mp-wp_genesis 2714 'mt_text_more' => $post['extended'],
mp-wp_genesis 2715 'mt_allow_comments' => $allow_comments,
mp-wp_genesis 2716 'mt_allow_pings' => $allow_pings,
mp-wp_genesis 2717 'mt_keywords' => $tagnames,
mp-wp_genesis 2718 'wp_slug' => $entry['post_name'],
mp-wp_genesis 2719 'wp_password' => $entry['post_password'],
mp-wp_genesis 2720 'wp_author_id' => $author->ID,
mp-wp_genesis 2721 'wp_author_display_name' => $author->display_name,
mp-wp_genesis 2722 'date_created_gmt' => new IXR_Date($post_date_gmt),
mp-wp_genesis 2723 'post_status' => $entry['post_status'],
mp-wp_genesis 2724 'custom_fields' => $this->get_custom_fields($entry['ID'])
mp-wp_genesis 2725 );
mp-wp_genesis 2726
mp-wp_genesis 2727 }
mp-wp_genesis 2728
mp-wp_genesis 2729 $recent_posts = array();
mp-wp_genesis 2730 for ($j=0; $j<count($struct); $j++) {
mp-wp_genesis 2731 array_push($recent_posts, $struct[$j]);
mp-wp_genesis 2732 }
mp-wp_genesis 2733
mp-wp_genesis 2734 return $recent_posts;
mp-wp_genesis 2735 }
mp-wp_genesis 2736
mp-wp_genesis 2737 /**
mp-wp_genesis 2738 * Retrieve the list of categories on a given blog.
mp-wp_genesis 2739 *
mp-wp_genesis 2740 * @since 1.5.0
mp-wp_genesis 2741 *
mp-wp_genesis 2742 * @param array $args Method parameters.
mp-wp_genesis 2743 * @return array
mp-wp_genesis 2744 */
mp-wp_genesis 2745 function mw_getCategories($args) {
mp-wp_genesis 2746
mp-wp_genesis 2747 $this->escape($args);
mp-wp_genesis 2748
mp-wp_genesis 2749 $blog_ID = (int) $args[0];
mp-wp_genesis 2750 $user_login = $args[1];
mp-wp_genesis 2751 $user_pass = $args[2];
mp-wp_genesis 2752
mp-wp_genesis 2753 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 2754 return $this->error;
mp-wp_genesis 2755 }
mp-wp_genesis 2756
mp-wp_genesis 2757 set_current_user( 0, $user_login );
mp-wp_genesis 2758 if( !current_user_can( 'edit_posts' ) )
mp-wp_genesis 2759 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view categories.' ) );
mp-wp_genesis 2760
mp-wp_genesis 2761 do_action('xmlrpc_call', 'metaWeblog.getCategories');
mp-wp_genesis 2762
mp-wp_genesis 2763 $categories_struct = array();
mp-wp_genesis 2764
mp-wp_genesis 2765 if ( $cats = get_categories('get=all') ) {
mp-wp_genesis 2766 foreach ( $cats as $cat ) {
mp-wp_genesis 2767 $struct['categoryId'] = $cat->term_id;
mp-wp_genesis 2768 $struct['parentId'] = $cat->parent;
mp-wp_genesis 2769 $struct['description'] = $cat->description;
mp-wp_genesis 2770 $struct['categoryName'] = $cat->name;
mp-wp_genesis 2771 $struct['htmlUrl'] = wp_specialchars(get_category_link($cat->term_id));
mp-wp_genesis 2772 $struct['rssUrl'] = wp_specialchars(get_category_feed_link($cat->term_id, 'rss2'));
mp-wp_genesis 2773
mp-wp_genesis 2774 $categories_struct[] = $struct;
mp-wp_genesis 2775 }
mp-wp_genesis 2776 }
mp-wp_genesis 2777
mp-wp_genesis 2778 return $categories_struct;
mp-wp_genesis 2779 }
mp-wp_genesis 2780
mp-wp_genesis 2781 /**
mp-wp_genesis 2782 * Uploads a file, following your settings.
mp-wp_genesis 2783 *
mp-wp_genesis 2784 * Adapted from a patch by Johann Richard.
mp-wp_genesis 2785 *
mp-wp_genesis 2786 * @link http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/
mp-wp_genesis 2787 *
mp-wp_genesis 2788 * @since 1.5.0
mp-wp_genesis 2789 *
mp-wp_genesis 2790 * @param array $args Method parameters.
mp-wp_genesis 2791 * @return array
mp-wp_genesis 2792 */
mp-wp_genesis 2793 function mw_newMediaObject($args) {
mp-wp_genesis 2794 global $wpdb;
mp-wp_genesis 2795
mp-wp_genesis 2796 $blog_ID = (int) $args[0];
mp-wp_genesis 2797 $user_login = $wpdb->escape($args[1]);
mp-wp_genesis 2798 $user_pass = $wpdb->escape($args[2]);
mp-wp_genesis 2799 $data = $args[3];
mp-wp_genesis 2800
mp-wp_genesis 2801 $name = sanitize_file_name( $data['name'] );
mp-wp_genesis 2802 $type = $data['type'];
mp-wp_genesis 2803 $bits = $data['bits'];
mp-wp_genesis 2804
mp-wp_genesis 2805 logIO('O', '(MW) Received '.strlen($bits).' bytes');
mp-wp_genesis 2806
mp-wp_genesis 2807 if ( !$this->login_pass_ok($user_login, $user_pass) )
mp-wp_genesis 2808 return $this->error;
mp-wp_genesis 2809
mp-wp_genesis 2810 do_action('xmlrpc_call', 'metaWeblog.newMediaObject');
mp-wp_genesis 2811
mp-wp_genesis 2812 set_current_user(0, $user_login);
mp-wp_genesis 2813 if ( !current_user_can('upload_files') ) {
mp-wp_genesis 2814 logIO('O', '(MW) User does not have upload_files capability');
mp-wp_genesis 2815 $this->error = new IXR_Error(401, __('You are not allowed to upload files to this site.'));
mp-wp_genesis 2816 return $this->error;
mp-wp_genesis 2817 }
mp-wp_genesis 2818
mp-wp_genesis 2819 if ( $upload_err = apply_filters( "pre_upload_error", false ) )
mp-wp_genesis 2820 return new IXR_Error(500, $upload_err);
mp-wp_genesis 2821
mp-wp_genesis 2822 if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) {
mp-wp_genesis 2823 // Get postmeta info on the object.
mp-wp_genesis 2824 $old_file = $wpdb->get_row("
mp-wp_genesis 2825 SELECT ID
mp-wp_genesis 2826 FROM {$wpdb->posts}
mp-wp_genesis 2827 WHERE post_title = '{$name}'
mp-wp_genesis 2828 AND post_type = 'attachment'
mp-wp_genesis 2829 ");
mp-wp_genesis 2830
mp-wp_genesis 2831 // Delete previous file.
mp-wp_genesis 2832 wp_delete_attachment($old_file->ID);
mp-wp_genesis 2833
mp-wp_genesis 2834 // Make sure the new name is different by pre-pending the
mp-wp_genesis 2835 // previous post id.
mp-wp_genesis 2836 $filename = preg_replace("/^wpid\d+-/", "", $name);
mp-wp_genesis 2837 $name = "wpid{$old_file->ID}-{$filename}";
mp-wp_genesis 2838 }
mp-wp_genesis 2839
mp-wp_genesis 2840 $upload = wp_upload_bits($name, $type, $bits);
mp-wp_genesis 2841 if ( ! empty($upload['error']) ) {
mp-wp_genesis 2842 $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']);
mp-wp_genesis 2843 logIO('O', '(MW) ' . $errorString);
mp-wp_genesis 2844 return new IXR_Error(500, $errorString);
mp-wp_genesis 2845 }
mp-wp_genesis 2846 // Construct the attachment array
mp-wp_genesis 2847 // attach to post_id -1
mp-wp_genesis 2848 $post_id = -1;
mp-wp_genesis 2849 $attachment = array(
mp-wp_genesis 2850 'post_title' => $name,
mp-wp_genesis 2851 'post_content' => '',
mp-wp_genesis 2852 'post_type' => 'attachment',
mp-wp_genesis 2853 'post_parent' => $post_id,
mp-wp_genesis 2854 'post_mime_type' => $type,
mp-wp_genesis 2855 'guid' => $upload[ 'url' ]
mp-wp_genesis 2856 );
mp-wp_genesis 2857
mp-wp_genesis 2858 // Save the data
mp-wp_genesis 2859 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
mp-wp_genesis 2860 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
mp-wp_genesis 2861
mp-wp_genesis 2862 return apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type ) );
mp-wp_genesis 2863 }
mp-wp_genesis 2864
mp-wp_genesis 2865 /* MovableType API functions
mp-wp_genesis 2866 * specs on http://www.movabletype.org/docs/mtmanual_programmatic.html
mp-wp_genesis 2867 */
mp-wp_genesis 2868
mp-wp_genesis 2869 /**
mp-wp_genesis 2870 * Retrieve the post titles of recent posts.
mp-wp_genesis 2871 *
mp-wp_genesis 2872 * @since 1.5.0
mp-wp_genesis 2873 *
mp-wp_genesis 2874 * @param array $args Method parameters.
mp-wp_genesis 2875 * @return array
mp-wp_genesis 2876 */
mp-wp_genesis 2877 function mt_getRecentPostTitles($args) {
mp-wp_genesis 2878
mp-wp_genesis 2879 $this->escape($args);
mp-wp_genesis 2880
mp-wp_genesis 2881 $blog_ID = (int) $args[0];
mp-wp_genesis 2882 $user_login = $args[1];
mp-wp_genesis 2883 $user_pass = $args[2];
mp-wp_genesis 2884 $num_posts = (int) $args[3];
mp-wp_genesis 2885
mp-wp_genesis 2886 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 2887 return $this->error;
mp-wp_genesis 2888 }
mp-wp_genesis 2889
mp-wp_genesis 2890 do_action('xmlrpc_call', 'mt.getRecentPostTitles');
mp-wp_genesis 2891
mp-wp_genesis 2892 $posts_list = wp_get_recent_posts($num_posts);
mp-wp_genesis 2893
mp-wp_genesis 2894 if (!$posts_list) {
mp-wp_genesis 2895 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.'));
mp-wp_genesis 2896 return $this->error;
mp-wp_genesis 2897 }
mp-wp_genesis 2898
mp-wp_genesis 2899 set_current_user( 0, $user_login );
mp-wp_genesis 2900
mp-wp_genesis 2901 foreach ($posts_list as $entry) {
mp-wp_genesis 2902 if( !current_user_can( 'edit_post', $entry['ID'] ) )
mp-wp_genesis 2903 continue;
mp-wp_genesis 2904
mp-wp_genesis 2905 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
mp-wp_genesis 2906 $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt']);
mp-wp_genesis 2907
mp-wp_genesis 2908 $struct[] = array(
mp-wp_genesis 2909 'dateCreated' => new IXR_Date($post_date),
mp-wp_genesis 2910 'userid' => $entry['post_author'],
mp-wp_genesis 2911 'postid' => $entry['ID'],
mp-wp_genesis 2912 'title' => $entry['post_title'],
mp-wp_genesis 2913 'date_created_gmt' => new IXR_Date($post_date_gmt)
mp-wp_genesis 2914 );
mp-wp_genesis 2915
mp-wp_genesis 2916 }
mp-wp_genesis 2917
mp-wp_genesis 2918 $recent_posts = array();
mp-wp_genesis 2919 for ($j=0; $j<count($struct); $j++) {
mp-wp_genesis 2920 array_push($recent_posts, $struct[$j]);
mp-wp_genesis 2921 }
mp-wp_genesis 2922
mp-wp_genesis 2923 return $recent_posts;
mp-wp_genesis 2924 }
mp-wp_genesis 2925
mp-wp_genesis 2926 /**
mp-wp_genesis 2927 * Retrieve list of all categories on blog.
mp-wp_genesis 2928 *
mp-wp_genesis 2929 * @since 1.5.0
mp-wp_genesis 2930 *
mp-wp_genesis 2931 * @param array $args Method parameters.
mp-wp_genesis 2932 * @return array
mp-wp_genesis 2933 */
mp-wp_genesis 2934 function mt_getCategoryList($args) {
mp-wp_genesis 2935
mp-wp_genesis 2936 $this->escape($args);
mp-wp_genesis 2937
mp-wp_genesis 2938 $blog_ID = (int) $args[0];
mp-wp_genesis 2939 $user_login = $args[1];
mp-wp_genesis 2940 $user_pass = $args[2];
mp-wp_genesis 2941
mp-wp_genesis 2942 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 2943 return $this->error;
mp-wp_genesis 2944 }
mp-wp_genesis 2945
mp-wp_genesis 2946 set_current_user( 0, $user_login );
mp-wp_genesis 2947 if( !current_user_can( 'edit_posts' ) )
mp-wp_genesis 2948 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view categories.' ) );
mp-wp_genesis 2949
mp-wp_genesis 2950 do_action('xmlrpc_call', 'mt.getCategoryList');
mp-wp_genesis 2951
mp-wp_genesis 2952 $categories_struct = array();
mp-wp_genesis 2953
mp-wp_genesis 2954 if ( $cats = get_categories('hide_empty=0&hierarchical=0') ) {
mp-wp_genesis 2955 foreach ($cats as $cat) {
mp-wp_genesis 2956 $struct['categoryId'] = $cat->term_id;
mp-wp_genesis 2957 $struct['categoryName'] = $cat->name;
mp-wp_genesis 2958
mp-wp_genesis 2959 $categories_struct[] = $struct;
mp-wp_genesis 2960 }
mp-wp_genesis 2961 }
mp-wp_genesis 2962
mp-wp_genesis 2963 return $categories_struct;
mp-wp_genesis 2964 }
mp-wp_genesis 2965
mp-wp_genesis 2966 /**
mp-wp_genesis 2967 * Retrieve post categories.
mp-wp_genesis 2968 *
mp-wp_genesis 2969 * @since 1.5.0
mp-wp_genesis 2970 *
mp-wp_genesis 2971 * @param array $args Method parameters.
mp-wp_genesis 2972 * @return array
mp-wp_genesis 2973 */
mp-wp_genesis 2974 function mt_getPostCategories($args) {
mp-wp_genesis 2975
mp-wp_genesis 2976 $this->escape($args);
mp-wp_genesis 2977
mp-wp_genesis 2978 $post_ID = (int) $args[0];
mp-wp_genesis 2979 $user_login = $args[1];
mp-wp_genesis 2980 $user_pass = $args[2];
mp-wp_genesis 2981
mp-wp_genesis 2982 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 2983 return $this->error;
mp-wp_genesis 2984 }
mp-wp_genesis 2985
mp-wp_genesis 2986 set_current_user( 0, $user_login );
mp-wp_genesis 2987 if( !current_user_can( 'edit_post', $post_ID ) )
mp-wp_genesis 2988 return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) );
mp-wp_genesis 2989
mp-wp_genesis 2990 do_action('xmlrpc_call', 'mt.getPostCategories');
mp-wp_genesis 2991
mp-wp_genesis 2992 $categories = array();
mp-wp_genesis 2993 $catids = wp_get_post_categories(intval($post_ID));
mp-wp_genesis 2994 // first listed category will be the primary category
mp-wp_genesis 2995 $isPrimary = true;
mp-wp_genesis 2996 foreach($catids as $catid) {
mp-wp_genesis 2997 $categories[] = array(
mp-wp_genesis 2998 'categoryName' => get_cat_name($catid),
mp-wp_genesis 2999 'categoryId' => (string) $catid,
mp-wp_genesis 3000 'isPrimary' => $isPrimary
mp-wp_genesis 3001 );
mp-wp_genesis 3002 $isPrimary = false;
mp-wp_genesis 3003 }
mp-wp_genesis 3004
mp-wp_genesis 3005 return $categories;
mp-wp_genesis 3006 }
mp-wp_genesis 3007
mp-wp_genesis 3008 /**
mp-wp_genesis 3009 * Sets categories for a post.
mp-wp_genesis 3010 *
mp-wp_genesis 3011 * @since 1.5.0
mp-wp_genesis 3012 *
mp-wp_genesis 3013 * @param array $args Method parameters.
mp-wp_genesis 3014 * @return bool True on success.
mp-wp_genesis 3015 */
mp-wp_genesis 3016 function mt_setPostCategories($args) {
mp-wp_genesis 3017
mp-wp_genesis 3018 $this->escape($args);
mp-wp_genesis 3019
mp-wp_genesis 3020 $post_ID = (int) $args[0];
mp-wp_genesis 3021 $user_login = $args[1];
mp-wp_genesis 3022 $user_pass = $args[2];
mp-wp_genesis 3023 $categories = $args[3];
mp-wp_genesis 3024
mp-wp_genesis 3025 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 3026 return $this->error;
mp-wp_genesis 3027 }
mp-wp_genesis 3028
mp-wp_genesis 3029 do_action('xmlrpc_call', 'mt.setPostCategories');
mp-wp_genesis 3030
mp-wp_genesis 3031 set_current_user(0, $user_login);
mp-wp_genesis 3032 if ( !current_user_can('edit_post', $post_ID) )
mp-wp_genesis 3033 return new IXR_Error(401, __('Sorry, you can not edit this post.'));
mp-wp_genesis 3034
mp-wp_genesis 3035 foreach($categories as $cat) {
mp-wp_genesis 3036 $catids[] = $cat['categoryId'];
mp-wp_genesis 3037 }
mp-wp_genesis 3038
mp-wp_genesis 3039 wp_set_post_categories($post_ID, $catids);
mp-wp_genesis 3040
mp-wp_genesis 3041 return true;
mp-wp_genesis 3042 }
mp-wp_genesis 3043
mp-wp_genesis 3044 /**
mp-wp_genesis 3045 * Retrieve an array of methods supported by this server.
mp-wp_genesis 3046 *
mp-wp_genesis 3047 * @since 1.5.0
mp-wp_genesis 3048 *
mp-wp_genesis 3049 * @param array $args Method parameters.
mp-wp_genesis 3050 * @return array
mp-wp_genesis 3051 */
mp-wp_genesis 3052 function mt_supportedMethods($args) {
mp-wp_genesis 3053
mp-wp_genesis 3054 do_action('xmlrpc_call', 'mt.supportedMethods');
mp-wp_genesis 3055
mp-wp_genesis 3056 $supported_methods = array();
mp-wp_genesis 3057 foreach($this->methods as $key=>$value) {
mp-wp_genesis 3058 $supported_methods[] = $key;
mp-wp_genesis 3059 }
mp-wp_genesis 3060
mp-wp_genesis 3061 return $supported_methods;
mp-wp_genesis 3062 }
mp-wp_genesis 3063
mp-wp_genesis 3064 /**
mp-wp_genesis 3065 * Retrieve an empty array because we don't support per-post text filters.
mp-wp_genesis 3066 *
mp-wp_genesis 3067 * @since 1.5.0
mp-wp_genesis 3068 *
mp-wp_genesis 3069 * @param array $args Method parameters.
mp-wp_genesis 3070 */
mp-wp_genesis 3071 function mt_supportedTextFilters($args) {
mp-wp_genesis 3072 do_action('xmlrpc_call', 'mt.supportedTextFilters');
mp-wp_genesis 3073 return apply_filters('xmlrpc_text_filters', array());
mp-wp_genesis 3074 }
mp-wp_genesis 3075
mp-wp_genesis 3076 /**
mp-wp_genesis 3077 * Retrieve trackbacks sent to a given post.
mp-wp_genesis 3078 *
mp-wp_genesis 3079 * @since 1.5.0
mp-wp_genesis 3080 *
mp-wp_genesis 3081 * @param array $args Method parameters.
mp-wp_genesis 3082 * @return mixed
mp-wp_genesis 3083 */
mp-wp_genesis 3084 function mt_getTrackbackPings($args) {
mp-wp_genesis 3085
mp-wp_genesis 3086 global $wpdb;
mp-wp_genesis 3087
mp-wp_genesis 3088 $post_ID = intval($args);
mp-wp_genesis 3089
mp-wp_genesis 3090 do_action('xmlrpc_call', 'mt.getTrackbackPings');
mp-wp_genesis 3091
mp-wp_genesis 3092 $actual_post = wp_get_single_post($post_ID, ARRAY_A);
mp-wp_genesis 3093
mp-wp_genesis 3094 if (!$actual_post) {
mp-wp_genesis 3095 return new IXR_Error(404, __('Sorry, no such post.'));
mp-wp_genesis 3096 }
mp-wp_genesis 3097
mp-wp_genesis 3098 $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) );
mp-wp_genesis 3099
mp-wp_genesis 3100 if (!$comments) {
mp-wp_genesis 3101 return array();
mp-wp_genesis 3102 }
mp-wp_genesis 3103
mp-wp_genesis 3104 $trackback_pings = array();
mp-wp_genesis 3105 foreach($comments as $comment) {
mp-wp_genesis 3106 if ( 'trackback' == $comment->comment_type ) {
mp-wp_genesis 3107 $content = $comment->comment_content;
mp-wp_genesis 3108 $title = substr($content, 8, (strpos($content, '</strong>') - 8));
mp-wp_genesis 3109 $trackback_pings[] = array(
mp-wp_genesis 3110 'pingTitle' => $title,
mp-wp_genesis 3111 'pingURL' => $comment->comment_author_url,
mp-wp_genesis 3112 'pingIP' => $comment->comment_author_IP
mp-wp_genesis 3113 );
mp-wp_genesis 3114 }
mp-wp_genesis 3115 }
mp-wp_genesis 3116
mp-wp_genesis 3117 return $trackback_pings;
mp-wp_genesis 3118 }
mp-wp_genesis 3119
mp-wp_genesis 3120 /**
mp-wp_genesis 3121 * Sets a post's publish status to 'publish'.
mp-wp_genesis 3122 *
mp-wp_genesis 3123 * @since 1.5.0
mp-wp_genesis 3124 *
mp-wp_genesis 3125 * @param array $args Method parameters.
mp-wp_genesis 3126 * @return int
mp-wp_genesis 3127 */
mp-wp_genesis 3128 function mt_publishPost($args) {
mp-wp_genesis 3129
mp-wp_genesis 3130 $this->escape($args);
mp-wp_genesis 3131
mp-wp_genesis 3132 $post_ID = (int) $args[0];
mp-wp_genesis 3133 $user_login = $args[1];
mp-wp_genesis 3134 $user_pass = $args[2];
mp-wp_genesis 3135
mp-wp_genesis 3136 if (!$this->login_pass_ok($user_login, $user_pass)) {
mp-wp_genesis 3137 return $this->error;
mp-wp_genesis 3138 }
mp-wp_genesis 3139
mp-wp_genesis 3140 do_action('xmlrpc_call', 'mt.publishPost');
mp-wp_genesis 3141
mp-wp_genesis 3142 set_current_user(0, $user_login);
mp-wp_genesis 3143 if ( !current_user_can('edit_post', $post_ID) )
mp-wp_genesis 3144 return new IXR_Error(401, __('Sorry, you can not edit this post.'));
mp-wp_genesis 3145
mp-wp_genesis 3146 $postdata = wp_get_single_post($post_ID,ARRAY_A);
mp-wp_genesis 3147
mp-wp_genesis 3148 $postdata['post_status'] = 'publish';
mp-wp_genesis 3149
mp-wp_genesis 3150 // retain old cats
mp-wp_genesis 3151 $cats = wp_get_post_categories($post_ID);
mp-wp_genesis 3152 $postdata['post_category'] = $cats;
mp-wp_genesis 3153 $this->escape($postdata);
mp-wp_genesis 3154
mp-wp_genesis 3155 $result = wp_update_post($postdata);
mp-wp_genesis 3156
mp-wp_genesis 3157 return $result;
mp-wp_genesis 3158 }
mp-wp_genesis 3159
mp-wp_genesis 3160 /* PingBack functions
mp-wp_genesis 3161 * specs on www.hixie.ch/specs/pingback/pingback
mp-wp_genesis 3162 */
mp-wp_genesis 3163
mp-wp_genesis 3164 /**
mp-wp_genesis 3165 * Retrieves a pingback and registers it.
mp-wp_genesis 3166 *
mp-wp_genesis 3167 * @since 1.5.0
mp-wp_genesis 3168 *
mp-wp_genesis 3169 * @param array $args Method parameters.
mp-wp_genesis 3170 * @return array
mp-wp_genesis 3171 */
mp-wp_genesis 3172 function pingback_ping($args) {
mp-wp_genesis 3173 global $wpdb;
mp-wp_genesis 3174
mp-wp_genesis 3175 do_action('xmlrpc_call', 'pingback.ping');
mp-wp_genesis 3176
mp-wp_genesis 3177 $this->escape($args);
mp-wp_genesis 3178
mp-wp_genesis 3179 $pagelinkedfrom = $args[0];
mp-wp_genesis 3180 $pagelinkedto = $args[1];
mp-wp_genesis 3181
mp-wp_genesis 3182 $title = '';
mp-wp_genesis 3183
mp-wp_genesis 3184 $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom);
mp-wp_genesis 3185 $pagelinkedto = str_replace('&', '&', $pagelinkedto);
mp-wp_genesis 3186 $pagelinkedto = str_replace('&', '&', $pagelinkedto);
mp-wp_genesis 3187
mp-wp_genesis 3188 // Check if the page linked to is in our site
mp-wp_genesis 3189 $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_option('home')));
mp-wp_genesis 3190 if( !$pos1 )
mp-wp_genesis 3191 return new IXR_Error(0, __('Is there no link to us?'));
mp-wp_genesis 3192
mp-wp_genesis 3193 // let's find which post is linked to
mp-wp_genesis 3194 // FIXME: does url_to_postid() cover all these cases already?
mp-wp_genesis 3195 // if so, then let's use it and drop the old code.
mp-wp_genesis 3196 $urltest = parse_url($pagelinkedto);
mp-wp_genesis 3197 if ($post_ID = url_to_postid($pagelinkedto)) {
mp-wp_genesis 3198 $way = 'url_to_postid()';
mp-wp_genesis 3199 } elseif (preg_match('#p/[0-9]{1,}#', $urltest['path'], $match)) {
mp-wp_genesis 3200 // the path defines the post_ID (archives/p/XXXX)
mp-wp_genesis 3201 $blah = explode('/', $match[0]);
mp-wp_genesis 3202 $post_ID = (int) $blah[1];
mp-wp_genesis 3203 $way = 'from the path';
mp-wp_genesis 3204 } elseif (preg_match('#p=[0-9]{1,}#', $urltest['query'], $match)) {
mp-wp_genesis 3205 // the querystring defines the post_ID (?p=XXXX)
mp-wp_genesis 3206 $blah = explode('=', $match[0]);
mp-wp_genesis 3207 $post_ID = (int) $blah[1];
mp-wp_genesis 3208 $way = 'from the querystring';
mp-wp_genesis 3209 } elseif (isset($urltest['fragment'])) {
mp-wp_genesis 3210 // an #anchor is there, it's either...
mp-wp_genesis 3211 if (intval($urltest['fragment'])) {
mp-wp_genesis 3212 // ...an integer #XXXX (simpliest case)
mp-wp_genesis 3213 $post_ID = (int) $urltest['fragment'];
mp-wp_genesis 3214 $way = 'from the fragment (numeric)';
mp-wp_genesis 3215 } elseif (preg_match('/post-[0-9]+/',$urltest['fragment'])) {
mp-wp_genesis 3216 // ...a post id in the form 'post-###'
mp-wp_genesis 3217 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']);
mp-wp_genesis 3218 $way = 'from the fragment (post-###)';
mp-wp_genesis 3219 } elseif (is_string($urltest['fragment'])) {
mp-wp_genesis 3220 // ...or a string #title, a little more complicated
mp-wp_genesis 3221 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']);
mp-wp_genesis 3222 $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title);
mp-wp_genesis 3223 if (! ($post_ID = $wpdb->get_var($sql)) ) {
mp-wp_genesis 3224 // returning unknown error '0' is better than die()ing
mp-wp_genesis 3225 return new IXR_Error(0, '');
mp-wp_genesis 3226 }
mp-wp_genesis 3227 $way = 'from the fragment (title)';
mp-wp_genesis 3228 }
mp-wp_genesis 3229 } else {
mp-wp_genesis 3230 // TODO: Attempt to extract a post ID from the given URL
mp-wp_genesis 3231 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.'));
mp-wp_genesis 3232 }
mp-wp_genesis 3233 $post_ID = (int) $post_ID;
mp-wp_genesis 3234
mp-wp_genesis 3235
mp-wp_genesis 3236 logIO("O","(PB) URL='$pagelinkedto' ID='$post_ID' Found='$way'");
mp-wp_genesis 3237
mp-wp_genesis 3238 $post = get_post($post_ID);
mp-wp_genesis 3239
mp-wp_genesis 3240 if ( !$post ) // Post_ID not found
mp-wp_genesis 3241 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.'));
mp-wp_genesis 3242
mp-wp_genesis 3243 if ( $post_ID == url_to_postid($pagelinkedfrom) )
mp-wp_genesis 3244 return new IXR_Error(0, __('The source URL and the target URL cannot both point to the same resource.'));
mp-wp_genesis 3245
mp-wp_genesis 3246 // Check if pings are on
mp-wp_genesis 3247 if ( !pings_open($post) )
mp-wp_genesis 3248 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.'));
mp-wp_genesis 3249
mp-wp_genesis 3250 // Let's check that the remote site didn't already pingback this entry
mp-wp_genesis 3251 $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) );
mp-wp_genesis 3252
mp-wp_genesis 3253 if ( $wpdb->num_rows ) // We already have a Pingback from this URL
mp-wp_genesis 3254 return new IXR_Error(48, __('The pingback has already been registered.'));
mp-wp_genesis 3255
mp-wp_genesis 3256 // very stupid, but gives time to the 'from' server to publish !
mp-wp_genesis 3257 sleep(1);
mp-wp_genesis 3258
mp-wp_genesis 3259 // Let's check the remote site
mp-wp_genesis 3260
mp-wp_genesis 3261
mp-wp_genesis 3262 // First, make sure we're not being used for DDoS!
mp-wp_genesis 3263
mp-wp_genesis 3264 if (gethostbyname(parse_url($pagelinkedfrom, PHP_URL_HOST)) <> $_SERVER['REMOTE_ADDR']) {
mp-wp_genesis 3265 die ("Sorry, you will have to send this from your actual IP.");
mp-wp_genesis 3266 mail("office@polimedia.us","trackback",$pagelinkedfrom);
mp-wp_genesis 3267 }
mp-wp_genesis 3268
mp-wp_genesis 3269 $linea = wp_remote_fopen( $pagelinkedfrom );
mp-wp_genesis 3270 if ( !$linea )
mp-wp_genesis 3271 return new IXR_Error(16, __('The source URL does not exist.'));
mp-wp_genesis 3272
mp-wp_genesis 3273 $linea = apply_filters('pre_remote_source', $linea, $pagelinkedto);
mp-wp_genesis 3274
mp-wp_genesis 3275 // Work around bug in strip_tags():
mp-wp_genesis 3276 $linea = str_replace('<!DOC', '<DOC', $linea);
mp-wp_genesis 3277 $linea = preg_replace( '/[\s\r\n\t]+/', ' ', $linea ); // normalize spaces
mp-wp_genesis 3278 $linea = preg_replace( "/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea );
mp-wp_genesis 3279
mp-wp_genesis 3280 preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle);
mp-wp_genesis 3281 $title = $matchtitle[1];
mp-wp_genesis 3282 if ( empty( $title ) )
mp-wp_genesis 3283 return new IXR_Error(32, __('We cannot find a title on that page.'));
mp-wp_genesis 3284
mp-wp_genesis 3285 $linea = strip_tags( $linea, '<a>' ); // just keep the tag we need
mp-wp_genesis 3286
mp-wp_genesis 3287 $p = explode( "\n\n", $linea );
mp-wp_genesis 3288
mp-wp_genesis 3289 $preg_target = preg_quote($pagelinkedto);
mp-wp_genesis 3290
mp-wp_genesis 3291 foreach ( $p as $para ) {
mp-wp_genesis 3292 if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link?
mp-wp_genesis 3293 preg_match("|<a[^>]+?".$preg_target."[^>]*>([^>]+?)</a>|", $para, $context);
mp-wp_genesis 3294
mp-wp_genesis 3295 // If the URL isn't in a link context, keep looking
mp-wp_genesis 3296 if ( empty($context) )
mp-wp_genesis 3297 continue;
mp-wp_genesis 3298
mp-wp_genesis 3299 // We're going to use this fake tag to mark the context in a bit
mp-wp_genesis 3300 // the marker is needed in case the link text appears more than once in the paragraph
mp-wp_genesis 3301 $excerpt = preg_replace('|\</?wpcontext\>|', '', $para);
mp-wp_genesis 3302
mp-wp_genesis 3303 // prevent really long link text
mp-wp_genesis 3304 if ( strlen($context[1]) > 100 )
mp-wp_genesis 3305 $context[1] = substr($context[1], 0, 100) . '...';
mp-wp_genesis 3306
mp-wp_genesis 3307 $marker = '<wpcontext>'.$context[1].'</wpcontext>'; // set up our marker
mp-wp_genesis 3308 $excerpt= str_replace($context[0], $marker, $excerpt); // swap out the link for our marker
mp-wp_genesis 3309 $excerpt = strip_tags($excerpt, '<wpcontext>'); // strip all tags but our context marker
mp-wp_genesis 3310 $excerpt = trim($excerpt);
mp-wp_genesis 3311 $preg_marker = preg_quote($marker);
mp-wp_genesis 3312 $excerpt = preg_replace("|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt);
mp-wp_genesis 3313 $excerpt = strip_tags($excerpt); // YES, again, to remove the marker wrapper
mp-wp_genesis 3314 break;
mp-wp_genesis 3315 }
mp-wp_genesis 3316 }
mp-wp_genesis 3317
mp-wp_genesis 3318 if ( empty($context) ) // Link to target not found
mp-wp_genesis 3319 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.'));
mp-wp_genesis 3320
mp-wp_genesis 3321 $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom);
mp-wp_genesis 3322
mp-wp_genesis 3323 $context = '[...] ' . wp_specialchars( $excerpt ) . ' [...]';
mp-wp_genesis 3324 $pagelinkedfrom = $wpdb->escape( $pagelinkedfrom );
mp-wp_genesis 3325
mp-wp_genesis 3326 $comment_post_ID = (int) $post_ID;
mp-wp_genesis 3327 $comment_author = $title;
mp-wp_genesis 3328 $this->escape($comment_author);
mp-wp_genesis 3329 $comment_author_url = $pagelinkedfrom;
mp-wp_genesis 3330 $comment_content = $context;
mp-wp_genesis 3331 $this->escape($comment_content);
mp-wp_genesis 3332 $comment_type = 'pingback';
mp-wp_genesis 3333
mp-wp_genesis 3334 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_content', 'comment_type');
mp-wp_genesis 3335
mp-wp_genesis 3336 $comment_ID = wp_new_comment($commentdata);
mp-wp_genesis 3337 do_action('pingback_post', $comment_ID);
mp-wp_genesis 3338
mp-wp_genesis 3339 return sprintf(__('Pingback from %1$s to %2$s registered. Keep the web talking! :-)'), $pagelinkedfrom, $pagelinkedto);
mp-wp_genesis 3340 }
mp-wp_genesis 3341
mp-wp_genesis 3342 /**
mp-wp_genesis 3343 * Retrieve array of URLs that pingbacked the given URL.
mp-wp_genesis 3344 *
mp-wp_genesis 3345 * Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html
mp-wp_genesis 3346 *
mp-wp_genesis 3347 * @since 1.5.0
mp-wp_genesis 3348 *
mp-wp_genesis 3349 * @param array $args Method parameters.
mp-wp_genesis 3350 * @return array
mp-wp_genesis 3351 */
mp-wp_genesis 3352 function pingback_extensions_getPingbacks($args) {
mp-wp_genesis 3353
mp-wp_genesis 3354 global $wpdb;
mp-wp_genesis 3355
mp-wp_genesis 3356 do_action('xmlrpc_call', 'pingback.extensions.getPingsbacks');
mp-wp_genesis 3357
mp-wp_genesis 3358 $this->escape($args);
mp-wp_genesis 3359
mp-wp_genesis 3360 $url = $args;
mp-wp_genesis 3361
mp-wp_genesis 3362 $post_ID = url_to_postid($url);
mp-wp_genesis 3363 if (!$post_ID) {
mp-wp_genesis 3364 // We aren't sure that the resource is available and/or pingback enabled
mp-wp_genesis 3365 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.'));
mp-wp_genesis 3366 }
mp-wp_genesis 3367
mp-wp_genesis 3368 $actual_post = wp_get_single_post($post_ID, ARRAY_A);
mp-wp_genesis 3369
mp-wp_genesis 3370 if (!$actual_post) {
mp-wp_genesis 3371 // No such post = resource not found
mp-wp_genesis 3372 return new IXR_Error(32, __('The specified target URL does not exist.'));
mp-wp_genesis 3373 }
mp-wp_genesis 3374
mp-wp_genesis 3375 $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) );
mp-wp_genesis 3376
mp-wp_genesis 3377 if (!$comments) {
mp-wp_genesis 3378 return array();
mp-wp_genesis 3379 }
mp-wp_genesis 3380
mp-wp_genesis 3381 $pingbacks = array();
mp-wp_genesis 3382 foreach($comments as $comment) {
mp-wp_genesis 3383 if ( 'pingback' == $comment->comment_type )
mp-wp_genesis 3384 $pingbacks[] = $comment->comment_author_url;
mp-wp_genesis 3385 }
mp-wp_genesis 3386
mp-wp_genesis 3387 return $pingbacks;
mp-wp_genesis 3388 }
mp-wp_genesis 3389 }
mp-wp_genesis 3390
mp-wp_genesis 3391 $wp_xmlrpc_server = new wp_xmlrpc_server();
mp-wp_genesis 3392
mp-wp_genesis 3393 ?>