Hi!

I have 2 drupal sites. I need to retrive from 1st site node information and submit it on 2nd site (and from 2nd to 1st).

I'm newbie, so I looked for some examples and can't find it. I saw this post, but probably it is not a php-code.

Can anyone show me exapmles of code to retrive node information from 1st site to other site? I need to include this code in module file.

Should I enable drupal.module on this 2 sites if I want to use xmlrpc.php?

Best regards and thanks for any help.

kors4r

Comments

kors4r’s picture

sorry...

kors4r’s picture

now I see in drupal.module this code (line - 315):

    $result = xmlrpc("http://$server/xmlrpc.php", 'drupal.login', $username, $password);

am I write????
in this case function xmlrps():
1. first connect to http://serwer.adress.net/xmlrpc.php file,
2. run function drupal_login() from drupal.module with variable: $username, $password

so, if on 1st site I have module: my.module, and in this module function my_something($param1, $param2) then if I want to run this function from 2nd site, I should run on 2nd site:

$result = xmlrpc("http://1st.site.adress.net/xmlrpc.php", "my.something", $param1, $param2);

IS IT SO SIMPLE?????

best regards

kors4r’s picture

I got it!!!!

for other drupal users:

I have 2 sites, on first I have mymodule.module, with this code:


<?php

function mymodule_cron() {
	
	mymodule_myfunc();
	
	}
	
function mymodule_myfunc($param = 'my implementation works') {
	
	$result = xmlrpc("http://2nd.site.adress.net/xmlrpc.php", 'mymodule2.insert', $param);
	
	if ($result === FALSE) {
	drupal_set_message(t('Error %code : %message', array('%code' => theme('placeholder', xmlrpc_errno()), '%message' =>  theme('placeholder', xmlrpc_error_msg()))), 'error');
	$message = xmlrpc_error_msg();
	watchdog('mymodule', t("Ups. $message"));
	}
	else
	watchdog('mymodule', t('OK.'));
	}
?>

on 2nd site I have mymodule2.mymodule, with:


<?php

function mymodule2_insert($param = 'run locally')
{
$query = "INSERT INTO {mymodule2_table} VALUES ('100', '100', '" . $param . "', '200', '100', '111', '100')";

$result = db_query($query);
return true;
}


//THIS HOOK IS NECESSARY!
//for other information, look here: http://api.drupal.org/api/4.7/function/hook_xmlrpc

function mymodule2_xmlrpc() {

//I don't know why, but it's array
   $xmlrpc = array();

//another time array (so it was in drupal.module, I don't understund it)
    $xmlrpc[] = array(
//here mymodule2.insert - so it is in $result on 1st site
      'mymodule2.insert',
//here mymodule2_insert - cause when on 1st site we run "xmlrpc("..address...", "mymodule2.insert")
//drupal on 2nd site should run mymodule2_insert in mymodule2.module file 
      'mymodule2_insert',
//very important! first is boolean, cause function mymodule2_insert() return this type
//second is "string", cause so is type of $param for mymodule2_insert()
//if in youre case you have more params, you should add 'string', 'string' (...) or other
//for more information, see: http://api.drupal.org/api/4.7/function/hook_xmlrpc
      array('boolean', 'string'),
//IMHO you can give it anything you want
      t('Insert data')
    );
  return $xmlrpc;
}

?>

8)

I'm very proud

best regards for everyone!