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

Michel Valdrighi michelvaldrighi at users.sourceforge.net
Fri Aug 27 08:46:30 UTC 2004


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

Modified Files:
	xmlrpc.php 
Log Message:
added mw.newMediaObject (not tested yet), fixed local/gmt dates confusion, removed debug edits, ate an apple too and taught a coworker how to use our espresso machine (it only takes a button to press)

Index: xmlrpc.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/xmlrpc.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** xmlrpc.php	26 Aug 2004 15:42:43 -0000	1.10
--- xmlrpc.php	27 Aug 2004 08:46:24 -0000	1.11
***************
*** 14,18 ****
  $post_default_category = 1; // posts submitted via the xmlrpc interface go into that category
  
! $xmlrpc_logging = 1;
  
  function logIO($io,$msg) {
--- 14,18 ----
  $post_default_category = 1; // posts submitted via the xmlrpc interface go into that category
  
! $xmlrpc_logging = 0;
  
  function logIO($io,$msg) {
***************
*** 35,49 ****
  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;
  }
  
--- 35,48 ----
  logIO("I", $HTTP_RAW_POST_DATA);
  
! function printr($var, $do_not_echo = false) {
! 	// from php.net/print_r user contributed notes 
! 	ob_start();
! 	print_r($var);
! 	$code =  htmlentities(ob_get_contents());
! 	ob_clean();
! 	if (!$do_not_echo) {
! 	  echo "<pre>$code</pre>";
! 	}
! 	return $code;
  }
  
***************
*** 67,70 ****
--- 66,70 ----
  		  'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
  		  'metaWeblog.getCategories' => 'this:mw_getCategories',
+ 		  'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
  
  		  'demo.sayHello' => 'this:sayHello',
***************
*** 170,174 ****
  	  $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']
--- 170,174 ----
  	  $struct = array(
  	    'userid'    => $post_data['post_author'],
! 	    'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
  	    'content'     => $content,
  	    'postid'  => $post_data['ID']
***************
*** 202,206 ****
  	  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']));
  
--- 202,206 ----
  	  foreach ($posts_list as $entry) {
  	  
! 	    $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
  	    $categories = implode(',', wp_get_post_cats(1, $entry['ID']));
  
***************
*** 478,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();
  
--- 478,482 ----
  
  	  $catnames = $content_struct['categories'];
! 	  logio('O', 'Post cats: ' . printr($catnames,true));
  	  $post_category = array();
  
***************
*** 595,599 ****
  	  if ($postdata['post_date'] != '') {
  
! 	    $post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']);
  
  	    $categories = array();
--- 594,598 ----
  	  if ($postdata['post_date'] != '') {
  
! 	    $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']);
  
  	    $categories = array();
***************
*** 653,657 ****
  	  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']);
--- 652,656 ----
  	  foreach ($posts_list as $entry) {
  	  
! 	    $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
  	    $categories = array();
  	    $catids = wp_get_post_cats('', $entry['ID']);
***************
*** 724,727 ****
--- 723,794 ----
  	}
  
+ 
+ 	/* metaweblog.newMediaObject uploads a file, following your settings */
+ 	function mw_newMediaObject($args) {
+ 	  // adapted from a patch by Johann Richard
+ 	  // http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/
+ 
+ 	  $blog_ID     = $args[0];
+ 	  $user_login  = $args[1];
+ 	  $user_pass   = $args[2];
+ 	  $data        = $args[3];
+ 
+ 	  $name = $data['name'];
+ 	  $type = $data['type'];
+ 	  $bits = $data['bits'];
+ 
+ 	  $file_realpath = get_settings('fileupload_realpath'); 
+ 	  $file_url = get_settings('fileupload_url');
+ 
+ 	  if (!$this->login_pass_ok($user_login, $user_pass)) {
+ 	    return $this->error;
+ 	  }
+ 
+ 	  $user_data = get_userdatabylogin($user_login);
+ 
+ 	  if(!get_settings('use_fileupload')) {
+ 	    // Uploads not allowed
+ 	    logIO('O', '(MW) Uploads not allowed');
+ 	    $this->error = new IXR_Error(405, 'No uploads allowed for this site.');
+ 	    return $this->error;
+ 	  } 
+ 
+ 	  if(get_settings('fileupload_minlevel') > $userlevel) {
+ 	    // User has not enough privileges
+ 	    logIO('O', '(MW) Not enough privilege: user level too low');
+ 	    $this->error = new IXR_Error(401, 'You are not allowed to upload files to this site.');
+ 	    return $this->error;
+ 	  }
+ 
+ 	  if(trim($file_realpath) == '' || trim($file_url) == '' ) {
+ 	    // WordPress is not correctly configured
+ 	    logIO('O', '(MW) Bad configuration. Real/URL path not defined');
+ 	    $this->error = new IXR_Error(500, 'Please configure WordPress with valid paths for file upload.');
+ 	    return $this->error;
+ 	  }
+ 
+ 	  $prefix = '/';
+ 
+ 	  if(!strlen(trim($name))) {
+ 	    // Create the path
+ 	    $localpath = $file_realpath.$prefix.$name;
+ 	    $url = $file_url.$prefix.$name;
+ 
+ 	    /* encode & write data (binary) */
+ 	    $ifp = fopen($localpath, 'wb');
+ 	    $success = fwrite($ifp, $bits);
+ 	    fclose($ifp);
+ 	    @chmod($localpath, 0666);
+ 
+ 	    if( $success ) {
+ 	      $resp = array($url);
+ 	      return $resp;
+ 	    } else {
+ 	      logIO('O', '(MW) Could not write file '.$name.' to '.$localpath);
+ 	      return new IXR_Error(500, 'Could not write file '.$name.' to '.$localpath);
+ 	    }
+ 	  }
+ 	}
+ 
  }
  




More information about the cvs mailing list