{"id":979,"date":"2009-10-20T13:20:53","date_gmt":"2009-10-20T11:20:53","guid":{"rendered":"http:\/\/www.juust.org\/?p=979"},"modified":"2024-10-13T17:04:36","modified_gmt":"2024-10-13T15:04:36","slug":"integrating-ms-office-and-wordpress-with-vba-and-xml-rpc","status":"publish","type":"post","link":"https:\/\/www.juust.org\/index.php\/integrating-ms-office-and-wordpress-with-vba-and-xml-rpc\/2009\/10\/","title":{"rendered":"integrating ms office and wordpress with vba and xml-rpc"},"content":{"rendered":"<p>Okay. <\/p>\n<p>Yesterday I made some basic stuff to grab my WordPress blog data with visual basic for applicationsn cos I don&#8217;t feel like programming php admin pages for tables. <\/p>\n<p>So let&#8217;s make a basic xml-rpc crud plugin and put my agenda on vba remote control.<\/p>\n<p>The basic xml-rpc plugin is simple, plug extra methods into the xml-rpc method array, and write a function per crud-method. <\/p>\n<pre lang=\"php\">\r\n\r\nadd_filter( 'xmlrpc_methods', 'add_agenda_xmlrpc_methods' );\r\n\r\nfunction add_agenda_xmlrpc_methods( $methods ) {\r\n    $methods['agenda.addAgendaItem'] = 'addAgendaItem';\r\n    $methods['agenda.updateAgendaItem'] = 'updateAgendaItem';\r\n    $methods['agenda.deleteAgendaItem'] = 'deleteAgendaItem';\r\n    $methods['agenda.reportAgendaItem'] = 'reportAgendaItem';\r\n    return $methods;\r\n}\r\n\r\nfunction addAgendaItem($args) { }\r\n\r\nfunction updateAgendaItem($args) { }\r\n\r\nfunction deleteAgendaItem($args) { }\r\n\r\nfunction reportAgendaItem($args) { }\r\n\r\n\/\/basic login helper function\r\nfunction CheckLogin($user, $pwd) {}\r\n\r\n<\/pre>\n<p>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.<\/p>\n<pre lang=\"php\">\r\nfunction addAgendaItem($args) {\r\n\r\n        $blog_id\t= (int) $args[0];\r\n        $username\t= $args[1];\r\n        $password\t= $args[2];\r\n        $AgendaItem     = $args[3];\r\n\r\n\/\/remember : add a login check\r\n\/\/(for the example it is irrelevant)\r\n\r\n        global $wpdb;\r\n        $sql = \"INSERT INTO \".$wpdb->prefix.\"Agenda (\r\n                `userid`, `tags`, `description`, `firstdate`, `enddate`, `link`, `price`, `location`\r\n                ) VALUES (\r\n                '\".$AgendaItem[0]['userid'].\"',\r\n                '\".$AgendaItem[0]['tags'].\"',\r\n                '\".$AgendaItem[0]['description'].\"',\r\n                '\".$AgendaItem[0]['firstdate'].\"',\r\n                '\".$AgendaItem[0]['enddate'].\"',\r\n                '\".$AgendaItem[0]['link'].\"',\r\n                '\".$AgendaItem[0]['price'].\"',\r\n                '\".$AgendaItem[0]['location'].\"'                \r\n                )\";\r\n        $wpdb->query($wpdb->prepare($sql));\r\n\r\n        return $wpdb->insert_id;\r\n}\r\n<\/pre>\n<p>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).<\/p>\n<p>Activate the plugin, and write a simple test <\/p>\n<pre lang=\"vb\">\r\n\r\n'Type to hold an agenda info record\r\nType AgendaItem\r\n    userid As String\r\n    tags As String\r\n    Description As String\r\n    firstdate As String\r\n    enddate As String\r\n    link As String\r\n    price As String\r\n    location As String\r\nEnd Type\r\n\r\n\r\nFunction AddAgendaItem()\r\n\r\ntxtURL = \"http:\/\/wwwblog.com\/xmlrpc.php\"\r\ntxtUserName = \"MyUsername\"\r\ntxtPassword = \"MyPassword\"\r\n  \r\n  Dim objSvrHTTP As ServerXMLHTTP\r\n  Dim strT As String\r\n  Set objSvrHTTP = New ServerXMLHTTP\r\n  \r\n  objSvrHTTP.Open \"POST\", txtURL, False, CStr(txtUserName), _\r\n   CStr(txtPassword)\r\n  \r\n  objSvrHTTP.setRequestHeader \"Accept\", \"application\/xml\"\r\n  objSvrHTTP.setRequestHeader \"Content-Type\", \"application\/xml\"\r\n  \r\n    strT = \"\"\r\n    strT = strT & \"<methodcall>\"\r\n    strT = strT & \"<methodname>agenda.addAgendaItem<\/methodname>\"\r\n    \r\n    strT = strT & \"<params>\"\r\n    strT = strT & \"<param \/><value><string>\" & txtBlogId & \"<\/string><\/value>\"\r\n    strT = strT & \"<param \/><value><string>\" & txtUserName & \"<\/string><\/value>\"\r\n    strT = strT & \"<param \/><value><string>\" & txtPassword & \"<\/string><\/value>\"\r\n\r\n'now we go make the struct, I use a Type (stdobject), normally\r\n'you'd use a recordset\r\n\r\nDim a As AgendaItem\r\n\r\nWith a\r\n    .userid = 1\r\n    .Description = \"rpc testing\"\r\n    .firstdate = \"2009\/10\/14\"\r\n    .enddate = \"2009\/10\/14\"\r\n    .link = \"https:\/\/www.juust.org\/\"\r\n    .price = \"rpc testing\"\r\n    .location = \"limmen\"\r\n    .tags = \"php, xml-rpc\"\r\nEnd With\r\n\r\n    strT = strT & \"<param \/><value><array>\"\r\n    strT = strT & \"<data>\"\r\n    \r\n    strT = strT & \"<value><struct>\"\r\n\r\n    strT = strT & \"<member><name>userid<\/name><value><string>\" & a.userid & \"<\/string><\/value><\/member>\"\r\n    strT = strT & \"<member><name>tags<\/name><value><string>\" & a.tags & \"<\/string><\/value><\/member>\"\r\n    strT = strT & \"<member><name>description<\/name><value><string>\" & a.Description & \"<\/string><\/value><\/member>\"\r\n    strT = strT & \"<member><name>firstdate<\/name><value><string>\" & a.firstdate & \"<\/string><\/value><\/member>\"\r\n    strT = strT & \"<member><name>enddate<\/name><value><string>\" & a.enddate & \"<\/string><\/value><\/member>\"\r\n    strT = strT & \"<member><name>link<\/name><value><string>\" & a.link & \"<\/string><\/value><\/member>\"\r\n    strT = strT & \"<member><name>price<\/name><value><string>\" & a.price & \"<\/string><\/value><\/member>\"\r\n    strT = strT & \"<member><name>location<\/name><value><string>\" & a.location & \"<\/string><\/value><\/member>\"\r\n\r\n'close the struct    \r\n    strT = strT & \"<\/struct><\/value>\"\r\n    strT = strT & \"<\/data>\"\r\n\r\n'close the struct array\r\n    strT = strT & \"<\/array><\/value>\"\r\n\r\n'end parameters\r\n    strT = strT & \"<\/params>\"\r\n\r\n'end method\r\n    strT = strT & \"<\/methodcall>\"\r\n\r\n'send the lot to the blog  \r\n  objSvrHTTP.send strT\r\n\r\n'print the response to debug \r\n  Debug.Print  objSvrHTTP.responseText\r\n\r\nEnd function\r\n\r\n<\/pre>\n<p>Et voila : <\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.juust.org\/wp-content\/uploads\/2009\/10\/agenda-rpc.png\" alt=\"agenda rpc\" title=\"agenda rpc\" width=\"550\" height=\"150\" class=\"alignleft size-full wp-image-980\" \/><\/p>\n<p>That&#8217;s yer basic Office-Wordpress XML-RPC integration.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Okay. Yesterday I made some basic stuff to grab my WordPress blog data with visual basic for applicationsn cos I don&#8217;t feel like programming php admin pages for tables. So let&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":5796,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[4,500,13,22],"tags":[42,105],"class_list":["post-979","post","type-post","status-publish","format-standard","hentry","category-juust","category-vba","category-wordpress","category-xml-rpc","tag-vba","tag-xml-rpc"],"_links":{"self":[{"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/posts\/979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/users\/5796"}],"replies":[{"embeddable":true,"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/comments?post=979"}],"version-history":[{"count":1,"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/posts\/979\/revisions"}],"predecessor-version":[{"id":12753,"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/posts\/979\/revisions\/12753"}],"wp:attachment":[{"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/media?parent=979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/categories?post=979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.juust.org\/index.php\/wp-json\/wp\/v2\/tags?post=979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}