--- openads.module	2007-03-01 07:11:41.000000000 +0800
+++ openads.module	2007-08-24 11:43:00.000000000 +0800
@@ -44,6 +44,15 @@ function openads_admin_settings() {
     '#description' => t('The Openads adserver is highly configurable regarding the URL it uses. ' .
     		'The according settings can be found at <strong>Settings =&gt; Main Settings</strong> in your adserver adminstration interface.'),
   );
+
+  $form['adserver']['openads_delivery_method'] = array(
+    '#type' => 'radios',
+    '#title' => t('Delivery Method'),
+    '#description' => t('Select which delivery method to use - JavaScript or XML-RPC. <b>Note</b> to use XML-RPC method you must have the PEAR XML-RPC package installed and the Openads openads-xmlrpc.inc.php file must be in your PHP include path.'),
+    '#options' => array('js' => 'JavaScript', 'xmlrpc' => 'XML-RPC'),
+    '#default_value' => variable_get('openads_delivery_method', 'js'),
+  );
+
   $form['adserver']['openads_delivery_url'] = array(
     '#type' => 'textfield', 
     '#default_value' => variable_get('openads_delivery_url', ''), 
@@ -58,15 +67,47 @@ function openads_admin_settings() {
   ); 
   $form['adserver']['openads_js_delivery_filename'] = array(
     '#type' => 'textfield', 
-    '#default_value' => variable_get('openads_js_delivery_filename', ''), 
+    '#default_value' => variable_get('openads_js_delivery_filename', 'ajs.php'), 
     '#title' => t('The openads JavaScript delivery filename'),
     '#description' => t('The openads JavaScript delivery filename for example "ajs.php"')
   );   
+  $form['adserver']['openads_xmlrpc_delivery_filename'] = array(
+    '#type' => 'textfield', 
+    '#default_value' => variable_get('openads_xmlrpc_delivery_filename', 'axmlrpc.php'), 
+    '#title' => t('The openads XML-RPC delivery filename'),
+    '#description' => t('The openads XML-RPC delivery filename for example "axmlrpc.php"')
+  );   
+
+  $form['xmlrpc_options'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('XML-RPC Options'),
+    '#description' => t('The following options affect the XML-RPC connection settings'),
+  );
+  $form['xmlrpc_options']['openads_xmlrpc_port'] = array(
+    '#type' => 'textfield',
+    '#title' => t('XML-RPC Port'),
+    '#description' => t('If your XML-RPC server is on a non-standard port, specify it here.'),
+    '#default_value' => variable_get('openads_xmlrpc_port', 80),
+    '#size' => 4,
+  );
+  $form['xmlrpc_options']['openads_xmlrpc_use_ssl'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use SSL'),
+    '#description' => t('If you wish to use SSL to connect to your Openads XML-RPC server, check this option'),
+    '#default_value' => variable_get('openads_xmlrpc_use_ssl', ''),
+  );
+  $form['xmlrpc_options']['openads_xmlrpc_timeout'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Timeout'),
+    '#description' => t('Set the timeout in seconds to connect to the Openads XML-RPC server'),
+    '#default_value' => variable_get('openads_xmlrpc_timeout', 2),
+    '#size' => 4,
+  );
 
   $form['publisher'] = array(
     '#type' => 'fieldset',
     '#title' => t('Publisher'),
-    '#description' => t('The follwoing settings can be copied form the publisher page of your adserver.'),
+    '#description' => t('The following settings can be copied form the publisher page of your adserver.'),
   );
   $form['publisher']['openads_id'] = array(
     '#type' => 'textfield', 
@@ -276,13 +317,45 @@ function theme_openads_admin_settings_fo
 }
 
 function theme_openads_invoke($zoneid, $code) {
+  if (variable_get('openads_delivery_method', 'js') == 'js') {
 	$out = "
 	<script language=\"JavaScript\" type=\"text/javascript\"><!--
 	  az_adjs($zoneid,'$code');
 	--></script>";
+  }
+  else if (variable_get('openads_delivery_method', 'js') == 'xmlrpc') {
+    static $oaXmlRpc;
+    static $OA_context;
+
+    if (!isset($OA_context)) {
+      $OA_context = array();
+    }
+    if (!$oaXmlRpc) {
+      $xmlrpc_settings = _openads_get_xmlrpc_settings();
+      $oaXmlRpc = _openads_connect_xmlrpc($xmlrpc_settings);
+    }
+    $ad = $oaXmlRpc->view('zone:'. $zoneid, 0, '', '', 0, $OA_context);
+    $out = $ad['html'];
+  }
   return $out;
 }
 
+function _openads_get_xmlrpc_settings() {
+  $xmlrpc_settings['url'] = variable_get('openads_delivery_url', '');
+  list($xmlrpc_settings['host'], $xmlrpc_settings['path']) = split('/', $xmlrpc_settings['url'], 2);
+  $xmlrpc_settings['file'] = variable_get('openads_xmlrpc_delivery_filename', 'axmlrpc.php');
+  $xmlrpc_settings['port'] = variable_get('openads_xmlrpc_port', 80);
+  $xmlrpc_settings['ssl'] = (variable_get('openads_xmlrpc_use_ssl', 0) == 0) ? FALSE : TRUE ;
+  $xmlrpc_settings['timeout'] = variable_get('openads_xmlrpc_timeout', 2);
+  return $xmlrpc_settings;
+}
+
+function _openads_connect_xmlrpc($xmlrpc_settings) {
+  require('openads-xmlrpc.inc.php');
+  $oaXmlRpc = new OA_XmlRpc($xmlrpc_settings['host'], '/'. $xmlrpc_settings['path'] .'/'. $xmlrpc_settings['file'], $xmlrpc_settings['port'], $xmlrpc_settings['ssl'], $xmlrpc_settings['timeout']);
+  return $oaXmlRpc;
+}
+
 function theme_openads_channel() {
 	global $user;
 	$url = check_plain($_GET['q']);
@@ -305,4 +378,4 @@ function theme_openads_block($index) {
 	return openads_invoke($index);
 }
 
-?>
\ No newline at end of file
+?>
