[wp-cvs] wordpress/wp-admin xmlrpc.php,1.9,1.10

Michel Valdrighi michelvaldrighi at users.sourceforge.net
Thu Aug 26 15:42:46 UTC 2004


Update of /cvsroot/cafelog/wordpress/wp-admin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28415/wp-admin

Modified Files:
	xmlrpc.php 
Log Message:
added mw.getRecentPosts, mw.getCategories, refactored the living shit out of the rest of the file

Index: xmlrpc.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/xmlrpc.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** xmlrpc.php	25 Aug 2004 16:28:20 -0000	1.9
--- xmlrpc.php	26 Aug 2004 15:42:43 -0000	1.10
***************
*** 6,9 ****
--- 6,10 ----
  include('../wp-config.php');
  include_once(ABSPATH . WPINC . '/class-IXR.php');
+ include_once(ABSPATH . WPINC . '/functions-post.php');
  
  // Turn off all warnings and errors.
***************
*** 13,17 ****
  $post_default_category = 1; // posts submitted via the xmlrpc interface go into that category
  
! $xmlrpc_logging = 0;
  
  function logIO($io,$msg) {
--- 14,18 ----
  $post_default_category = 1; // posts submitted via the xmlrpc interface go into that category
  
! $xmlrpc_logging = 1;
  
  function logIO($io,$msg) {
***************
*** 34,38 ****
  logIO("I", $HTTP_RAW_POST_DATA);
  
! 
  
  class wp_xmlrpc_server extends IXR_Server {
--- 35,50 ----
  logIO("I", $HTTP_RAW_POST_DATA);
  
! function printr ( $var, $do_not_echo = false )
! {
!    ob_start();
!    print_r($var);
!    $code =  htmlentities(ob_get_contents());
!    ob_clean();
!    if ( !$do_not_echo )
!    {
!        echo "<pre>$code</pre>";
!    }
!    return $code;
! }
  
  class wp_xmlrpc_server extends IXR_Server {
***************
*** 53,56 ****
--- 65,70 ----
  		  'metaWeblog.editPost' => 'this:mw_editPost',
  		  'metaWeblog.getPost' => 'this:mw_getPost',
+ 		  'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
+ 		  'metaWeblog.getCategories' => 'this:mw_getCategories',
  
  		  'demo.sayHello' => 'this:sayHello',
***************
*** 71,75 ****
  	function login_pass_ok($user_login, $user_pass) {
  	  if (!user_pass_ok($user_login, $user_pass)) {
! 	    $this->error = new IXR_Error(403, 'Bad login/pass combination.');
  	    return false;
  	  }
--- 85,89 ----
  	function login_pass_ok($user_login, $user_pass) {
  	  if (!user_pass_ok($user_login, $user_pass)) {
! 	    $this->error = new IXR_Error(403, 'Bad login/pass combination.'.$user_login);
  	    return false;
  	  }
***************
*** 146,162 ****
  
  	  $user_data = get_userdatabylogin($user_login);
! 	  $post_data = get_postdata($post_ID);
! 
! 	  $post_date = mysql2date('Ymd\TH:i:s', $post_data['Date']);
  
  	  $categories = implode(',', wp_get_post_cats(1, $post_ID));
  
! 	  $content  = '<title>'.stripslashes($post_data['Title']).'</title>';
  	  $content .= '<category>'.$categories.'</category>';
! 	  $content .= stripslashes($post_data['Content']);
  
  	  $struct = array(
! 	    'userid'    => $post_data['Author_ID'],
! 	    'dateCreateed' => mysql2date('Ymd\TH:i:s', $post_data['Date']),
  	    'content'     => $content,
  	    'postid'  => $post_data['ID']
--- 160,174 ----
  
  	  $user_data = get_userdatabylogin($user_login);
! 	  $post_data = wp_get_single_post($post_ID, ARRAY_A);
  
  	  $categories = implode(',', wp_get_post_cats(1, $post_ID));
  
! 	  $content  = '<title>'.stripslashes($post_data['post_title']).'</title>';
  	  $content .= '<category>'.$categories.'</category>';
! 	  $content .= stripslashes($post_data['post_content']);
  
  	  $struct = array(
! 	    'userid'    => $post_data['post_author'],
! 	    'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s\Z', $post_data['post_date_gmt'])),
  	    'content'     => $content,
  	    'postid'  => $post_data['ID']
***************
*** 177,251 ****
  	  $num_posts  = $args[4];
  
- 	  if ($num_posts > 0) {
- 	    $limit = " LIMIT $num_posts";
- 	  } else {
- 	    $limit = '';
- 	  }
- 
  	  if (!$this->login_pass_ok($user_login, $user_pass)) {
  	    return $this->error;
  	  }
  
! 	  $sql = "SELECT * FROM $wpdb->posts ORDER BY post_date DESC".$limit;
! 	  $result = $wpdb->get_results($sql);
  
! 	  if (!$result) {
  	    $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
  	    return $this->error;
  	  }
  
! 	  $i = 0;
! 	  foreach ($result as $row) {
! 	    $post_data = array(
! 	      'ID' => $row->ID,
! 	      'Author_ID' => $row->post_author,
! 	      'Date' => $row->post_date,
! 	      'Content' => $row->post_content,
! 	      'Title' => $row->post_title,
! 	      'Category' => $row->post_category
! 	    );
! 
! 	    $categories = implode(',', wp_get_post_cats(1, $post_data['ID']));
! 	    $post_date = mysql2date("Ymd\TH:i:s", $post_data['Date']);
  
! 	    $content  = '<title>'.stripslashes($post_data['Title']).'</title>';
  	    $content .= '<category>'.$categories.'</category>';
! 	    $content .= stripslashes($post_data['Content']);
! 
! 	    $author_data = get_userdata($post_data['Author_ID']);
! 
! 	    switch($author_data['user_idmode']) {
! 	    case 'nickname':
! 	      $author_name = $author_data['user_nickname'];
! 	    case 'login':
! 	      $author_name = $author_data['user_login'];
! 	      break;
! 	    case 'firstname':
! 	      $author_name = $author_data['user_firstname'];
! 	      break;
! 	    case 'lastname':
! 	      $author_name = $author_data['user_lastname'];
! 	      break;
! 	    case 'namefl':
! 	      $author_name = $author_data['user_firstname']." ".$author_data['user_lastname'];
! 	      break;
! 	    case 'namelf':
! 	      $author_name = $author_data['user_lastname']." ".$author_data['user_firstname'];
! 	      break;
! 	    default:
! 	      $author_name = $author_data['user_nickname'];
! 	      break;
! 	    }
  
! 	    $struct[$i] = array(
! 	      'authorName' => $author_name,
! 	      'userid' => $post_data['Author_ID'],
! 	      'dateCreated' => $post_date,
  	      'content' => $content,
! 	      'postid' => $post_data['ID'],
! 	      'category' => $categories
  	    );
  
- 	    $i++;
  	  }
  
--- 189,219 ----
  	  $num_posts  = $args[4];
  
  	  if (!$this->login_pass_ok($user_login, $user_pass)) {
  	    return $this->error;
  	  }
  
! 	  $posts_list = wp_get_recent_posts($num_posts);
  
! 	  if (!$posts_list) {
  	    $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
  	    return $this->error;
  	  }
  
! 	  foreach ($posts_list as $entry) {
! 	  
! 	    $post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']);
! 	    $categories = implode(',', wp_get_post_cats(1, $entry['ID']));
  
! 	    $content  = '<title>'.stripslashes($entry['post_itle']).'</title>';
  	    $content .= '<category>'.$categories.'</category>';
! 	    $content .= stripslashes($entry['post_content']);
  
! 	    $struct[] = array(
! 	      'userid' => $entry['post_author'],
! 	      'dateCreated' => new IXR_Date($post_date),
  	      'content' => $content,
! 	      'postid' => $entry['ID'],
  	    );
  
  	  }
  
***************
*** 286,290 ****
  
  	  /* so it is actually editable with a windows/mac client */
! 	  $content = str_replace("\n", "\r\n", $content); 
  
  	  return $content;
--- 254,258 ----
  
  	  /* so it is actually editable with a windows/mac client */
! 	  // 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); 
  
  	  return $content;
***************
*** 511,514 ****
--- 479,483 ----
  	  $catnames = $content_struct['categories'];
  	  // FIXME: commented until a fix to print_r is found: logio('O', 'Post cats: ' . print_r($catnames,true));
+ 	  //logio('O', 'Post cats: ' . printr($catnames,true));
  	  $post_category = array();
  
***************
*** 627,643 ****
  
  	    $post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']);
! 			
  	    $catids = wp_get_post_cats('', $post_ID);
  	    foreach($catids as $catid) {
! 	      $catname = get_cat_name($catid);
! 	      $catnameenc = new xmlrpcval($catname);
! 	      $catlist[] = $catnameenc;
  	    }
  	    $post = get_extended($postdata['post_content']);
  	    $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
  	    $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
  
  	    $resp = array(
! 				'link' => post_permalink($post_ID),
  				'title' => $postdata['post_title'],
  				'description' => $post['main'],
--- 596,614 ----
  
  	    $post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']);
! 
! 	    $categories = array();
  	    $catids = wp_get_post_cats('', $post_ID);
  	    foreach($catids as $catid) {
! 	      $categories[] = get_cat_name($catid);
  	    }
+ 
  	    $post = get_extended($postdata['post_content']);
+ 	    $link = post_permalink($entry['ID']);
+ 
  	    $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
  	    $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
  
  	    $resp = array(
! 				'link' => $link,
  				'title' => $postdata['post_title'],
  				'description' => $post['main'],
***************
*** 646,651 ****
  				'postid' => $postdata['ID'],
  				'content' => $postdata['post_content'],
! 				'permalink' => post_permalink($post_ID),
! 				'categories' => $catlist,
  				'mt_excerpt' => $postdata['post_excerpt'],
  				'mt_allow_comments' => $allow_comments,
--- 617,622 ----
  				'postid' => $postdata['ID'],
  				'content' => $postdata['post_content'],
! 				'permalink' => $link,
! 				'categories' => $categories,
  				'mt_excerpt' => $postdata['post_excerpt'],
  				'mt_allow_comments' => $allow_comments,
***************
*** 659,663 ****
  	  }
  	}
! 	
  }
  
--- 630,727 ----
  	  }
  	}
! 
! 
! 	/* metaweblog.getRecentPosts ...returns recent posts */
! 	function mw_getRecentPosts($args) {
! 
! 	  $blog_ID     = $args[0];
! 	  $user_login  = $args[1];
! 	  $user_pass   = $args[2];
! 	  $num_posts  = $args[4];
! 
! 	  if (!$this->login_pass_ok($user_login, $user_pass)) {
! 	    return $this->error;
! 	  }
! 
! 	  $posts_list = wp_get_recent_posts($num_posts);
! 
! 	  if (!$posts_list) {
! 	    $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.');
! 	    return $this->error;
! 	  }
! 
! 	  foreach ($posts_list as $entry) {
! 	  
! 	    $post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']);
! 	    $categories = array();
! 	    $catids = wp_get_post_cats('', $entry['ID']);
! 	    foreach($catids as $catid) {
! 	      $categories[] = get_cat_name($catid);
! 	    }
! 
! 	    $post = get_extended($entry['post_content']);
! 	    $link = post_permalink($entry['ID']);
! 
! 	    $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0;
! 	    $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0;
! 
! 	    $struct[] = array(
! 	      'link' => $link,
! 	      'title' => $entry['post_title'],
! 	      'description' => $post['main'],
! 	      'dateCreated' => new IXR_Date($post_date),
! 	      'userid' => $entry['post_author'],
! 	      'postid' => $entry['ID'],
! 	      'content' => $entry['post_content'],
! 	      'permalink' => $link,
! 	      'categories' => $categories,
! 	      'mt_excerpt' => $entry['post_excerpt'],
! 	      'mt_allow_comments' => $allow_comments,
! 	      'mt_allow_pings' => $allow_pings,
! 	      'mt_text_more' => $post['extended']
! 	    );
! 
! 	  }
! 
! 	  $recent_posts = array();
! 	  for ($j=0; $j<count($struct); $j++) {
! 	    array_push($recent_posts, $struct[$j]);
! 	  }
! 	  
! 	  return $recent_posts;
! 	}
! 
! 
! 	/* metaweblog.getCategories ...returns the list of categories on a given weblog */
! 	function mw_getCategories($args) {
! 
! 	  global $wpdb;
! 
! 	  $blog_ID     = $args[0];
! 	  $user_login  = $args[1];
! 	  $user_pass   = $args[2];
! 
! 	  if (!$this->login_pass_ok($user_login, $user_pass)) {
! 	    return $this->error;
! 	  }
! 
! 	  $categories_struct = array();
! 
! 	  // FIXME: can we avoid using direct SQL there?
! 	  if ($cats = $wpdb->get_results("SELECT cat_ID,cat_name FROM $wpdb->categories", ARRAY_A)) {
! 	    foreach ($cats as $cat) {
! 	      $struct['categoryId'] = $cat['cat_ID'];
! 	      $struct['description'] = $cat['cat_name'];
! 	      $struct['categoryName'] = $cat['cat_name'];
! 	      $struct['htmlUrl'] = htmlspecialchars(get_category_link(false, $cat['cat_ID'], $cat['cat_name']));
! 	      $struct['rssUrl'] = htmlspecialchars(get_category_rss_link(false, $cat['cat_ID'], $cat['cat_name']));
! 
! 	      $categories_struct[] = $struct;
! 	    }
! 	  }
! 
! 	  return $categories_struct;
! 	}
! 
  }
  




More information about the cvs mailing list