integrating ms office and wordpress with vba and xml-rpc
juust | 20/10/2009Okay.
Yesterday I made some basic stuff to grab my Wordpress blog data with visual basic for applicationsn cos I don’t feel like programming php admin pages for tables.
So let’s make a basic xml-rpc crud plugin and put my agenda on vba remote control.
The basic xml-rpc plugin is simple, plug extra methods into the xml-rpc method array, and write a function per crud-method.
-
-
add_filter( 'xmlrpc_methods', 'add_agenda_xmlrpc_methods' );
-
-
function add_agenda_xmlrpc_methods( $methods ) {
-
$methods['agenda.addAgendaItem'] = 'addAgendaItem';
-
$methods['agenda.updateAgendaItem'] = 'updateAgendaItem';
-
$methods['agenda.deleteAgendaItem'] = 'deleteAgendaItem';
-
$methods['agenda.reportAgendaItem'] = 'reportAgendaItem';
-
return $methods;
-
}
-
-
function addAgendaItem($args) { }
-
-
function updateAgendaItem($args) { }
-
-
function deleteAgendaItem($args) { }
-
-
function reportAgendaItem($args) { }
-
-
//basic login helper function
-
function CheckLogin($user, $pwd) {}
There now, if I call on the xmlrpc.php file, the extra methods are added to the callback array and I can use the table CRUD functions from my vba desktop.
-
function addAgendaItem($args) {
-
-
$blog_id = (int) $args[0];
-
$username = $args[1];
-
$password = $args[2];
-
$AgendaItem = $args[3];
-
-
//remember : add a login check
-
//(for the example it is irrelevant)
-
-
global $wpdb;
-
$sql = "INSERT INTO ".$wpdb->prefix."Agenda (
-
`userid`, `tags`, `description`, `firstdate`, `enddate`, `link`, `price`, `location`
-
) VALUES (
-
'".$AgendaItem[0]['userid']."',
-
'".$AgendaItem[0]['tags']."',
-
'".$AgendaItem[0]['description']."',
-
'".$AgendaItem[0]['firstdate']."',
-
'".$AgendaItem[0]['enddate']."',
-
'".$AgendaItem[0]['link']."',
-
'".$AgendaItem[0]['price']."',
-
'".$AgendaItem[0]['location']."'
-
)";
-
$wpdb->query($wpdb->prepare($sql));
-
-
return $wpdb->insert_id;
-
}
note : the agendaitem is a struct in an array (see below), I use [0] to get the first struct (which is the actual array with field-value pairs, my record with agenda info).
Activate the plugin, and write a simple test
-
-
'Type to hold an agenda info record
-
Type AgendaItem
-
userid As String
-
tags As String
-
Description As String
-
firstdate As String
-
enddate As String
-
link As String
-
price As String
-
location As String
-
End Type
-
-
-
Function AddAgendaItem()
-
-
txtURL = "http://wwwblog.com/xmlrpc.php"
-
txtUserName = "MyUsername"
-
txtPassword = "MyPassword"
-
-
Dim objSvrHTTP As ServerXMLHTTP
-
Dim strT As String
-
Set objSvrHTTP = New ServerXMLHTTP
-
-
objSvrHTTP.Open "POST", txtURL, False, CStr(txtUserName), _
-
CStr(txtPassword)
-
-
objSvrHTTP.setRequestHeader "Accept", "application/xml"
-
objSvrHTTP.setRequestHeader "Content-Type", "application/xml"
-
-
strT = ""
-
strT = strT & "<methodcall>"
-
strT = strT & "<methodname>agenda.addAgendaItem</methodname>"
-
-
strT = strT & "<params>"
-
strT = strT & "<param><value><string>" & txtBlogId & "</string></value></param>"
-
strT = strT & "<param><value><string>" & txtUserName & "</string></value></param>"
-
strT = strT & "<param><value><string>" & txtPassword & "</string></value></param>"
-
-
'now we go make the struct, I use a Type (stdobject), normally
-
'you'd use a recordset
-
-
Dim a As AgendaItem
-
-
With a
-
.userid = 1
-
.Description = "rpc testing"
-
.firstdate = "2009/10/14"
-
.enddate = "2009/10/14"
-
.link = "http://www.juust.org/"
-
.price = "rpc testing"
-
.location = "limmen"
-
.tags = "php, xml-rpc"
-
End With
-
-
strT = strT & "<param><value><array>"
-
strT = strT & "<data>"
-
-
strT = strT & "<value><struct>"
-
-
strT = strT & "<member><name>userid</name><value><string>" & a.userid & "</string></value></member>"
-
strT = strT & "<member><name>tags</name><value><string>" & a.tags & "</string></value></member>"
-
strT = strT & "<member><name>description</name><value><string>" & a.Description & "</string></value></member>"
-
strT = strT & "<member><name>firstdate</name><value><string>" & a.firstdate & "</string></value></member>"
-
strT = strT & "<member><name>enddate</name><value><string>" & a.enddate & "</string></value></member>"
-
strT = strT & "<member><name>link</name><value><string>" & a.link & "</string></value></member>"
-
strT = strT & "<member><name>price</name><value><string>" & a.price & "</string></value></member>"
-
strT = strT & "<member><name>location</name><value><string>" & a.location & "</string></value></member>"
-
-
'close the struct
-
strT = strT & "</struct></value>"
-
strT = strT & "</data>"
-
-
'close the struct array
-
strT = strT & "</array></value></param>"
-
-
'end parameters
-
strT = strT & "</params>"
-
-
'end method
-
strT = strT & "</methodcall>"
-
-
'send the lot to the blog
-
objSvrHTTP.send strT
-
-
'print the response to debug
-
Debug.Print objSvrHTTP.responseText
-
-
End function
Et voila :

That’s yer basic Office-Wordpress XML-RPC integration.








