setDebug(0); $c->setAcceptedCompression(null); //Get all pathways $m = new xmlrpcmsg("WikiPathways.getPathwayList", array() ); $r = $c->send($m); $v = getvalue($r); echo "

Fetched list of {$v->arraysize()} pathways:

"; for($i = 0; $i < $v->arraysize(); $i++) { echo($v->arraymem($i)->scalarval() . "
\n"); } //Get an authentication token $m = new xmlrpcmsg("WikiPathways.login", array( new xmlrpcval($user), new xmlrpcval($pass) ) ); $r = $c->send($m); $v = getvalue($r); $token = $v->scalarval(); echo "

Fetched authentication code

User: $user

Token: $token"; //Get the latest GPML and revision id $m = new xmlrpcmsg("WikiPathways.getPathway", array( new xmlrpcval("Sandbox"), new xmlrpcval("Homo sapiens") ) ); $r = $c->send($m); $v = getvalue($r); $data = php_xmlrpc_decode($v); $gpml = base64_decode($data['gpml']); $revision = $data['revision']; echo "

Downloaded GPML

Fetched GPML, revision $revision

"; //Make changes to the GPML //E.g. change all colors to purple //Using regex: /Color=".{6}"/Color="a020f0" $gpmlMod = preg_replace('/Color=".{6}"/', 'Color="a020f0"', $gpml); //Encode the gpml code for sending it along with the xml-rpc response $gpmlMod64 = base64_encode($gpmlMod); //Update the pathway $m = new xmlrpcmsg("WikiPathways.updatePathway", array( new xmlrpcval("Sandbox"), new xmlrpcval("Homo sapiens"), new xmlrpcval("All colors to purple"), new xmlrpcval($gpmlMod64, "base64"), new xmlrpcval($revision, "int"), php_xmlrpc_encode(array("user" => $user, "token" => $token)) ) ); $r = $c->send($m); $v = getvalue($r); if($v->scalarval()) { echo "

GPML updated!

"; } else { echo "

Update failed!

"; } /** * Get the xml-rpc response value and while checking for errors and throw an exception * if an error is found **/ function getvalue($r) { if($r->faultCode()) { throw new Exception("xml-rpc error ({$r->faultCode()}): {$r->faultString()}"); } else { return $r->value(); } } ?>