このサンプルプログラムの詳細は、まるむしアンテナのブログにて。
";
// //////////////////////////////
//以下固定
$bm = new BlogManager();
$bm->post_blog($kiji_mode,$kiji_title,$kiji_honbun);
class BlogManager {
function post_blog($kiji_mode,$kiji_title,$kiji_honbun){
global $wp_xmlrpc_path,$wp_host,$wp_user,$wp_passwd;
//クライアントの作成
echo "クライアント作成
";
$c = new XML_RPC_client( $wp_xmlrpc_path, $wp_host, 80 );
//送信データ
$blogid = new XML_RPC_Value($wp_blogid, 'string');
$username = new XML_RPC_Value($wp_user, 'string');
$passwd = new XML_RPC_Value($wp_passwd, 'string');
$content = new XML_RPC_Value(array(
'title' => new XML_RPC_Value($kiji_title, 'string'),
'description'=> new XML_RPC_Value($kiji_honbun, 'string'),
'dateCreated'=> new XML_RPC_Value(date("Ymd\TH:i:s",time()), 'dateTime.iso8601')
), 'struct');
$publish = new XML_RPC_Value($kiji_mode, 'boolean');
//XML-RPCメソッドのセット
$message = new XML_RPC_Message('metaWeblog.newPost',array($blogid, $username, $passwd, $content, $publish) );
$this->send_message($c,$message);
}
function get_users_blogs(){
global $wp_xmlrpc_path,$wp_host,$wp_user,$wp_passwd;
//クライアントの作成
echo "クライアント作成
";
$c = new XML_RPC_client( $wp_xmlrpc_path, $wp_host, 80 );
$appkey = new XML_RPC_Value ( '' , 'string' );
$username = new XML_RPC_Value ( $wp_user , 'string' );
$passwd = new XML_RPC_Value ( $wp_passwd, 'string' );
//メッセージ作成
echo "メッセージ作成
";
$message = new XML_RPC_Message( "blogger.getUsersBlogs",array($appkey, $username, $passwd) );
send_message($c,$message);
}
function send_message($c,$message){
//メッセージ送信
echo "メッセージ送信
";
$result = $c->send($message);
if( !$result ){
exit('Could not connect to the server.');
}else if( $result ->faultCode() ){
exit('XML-RPC fault ('.$result ->faultCode().'): '
.$result ->faultString());
}
return $result ;
}
}
?>