3 include_once __DIR__ . "/../../vendor/autoload.php";
7 $addComment_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcString, Value::$xmlrpcString, Value::$xmlrpcString));
9 $addComment_doc = 'Adds a comment to an item. The first parameter
10 is the item ID, the second the name of the commenter, and the third
11 is the comment itself. Returns the number of comments against that
14 function addComment($req)
17 // since validation has already been carried out for us,
18 // we know we got exactly 3 string values
19 $encoder = new PhpXmlRpc\Encoder();
20 $n = $encoder->decode($req);
25 $dbh = dba_open("/tmp/comments.db", "c", "db2");
27 $countID = "${msgID}_count";
28 if (dba_exists($countID, $dbh)) {
29 $count = dba_fetch($countID, $dbh);
33 // add the new comment in
34 dba_insert($msgID . "_comment_${count}", $comment, $dbh);
35 dba_insert($msgID . "_name_${count}", $name, $dbh);
37 dba_replace($countID, $count, $dbh);
40 $err = "Unable to open comments database.";
42 // if we generated an error, create an error return response
44 return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
46 // otherwise, we create the right response
47 return new PhpXmlRpc\Response(new PhpXmlRpc\Value($count, "int"));
51 $getComments_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcString));
53 $getComments_doc = 'Returns an array of comments for a given ID, which
54 is the sole argument. Each array item is a struct containing name
57 function getComments($req)
61 $encoder = new PhpXmlRpc\Encoder();
62 $msgID = $encoder->decode($req->getParam(0));
63 $dbh = dba_open("/tmp/comments.db", "r", "db2");
65 $countID = "${msgID}_count";
66 if (dba_exists($countID, $dbh)) {
67 $count = dba_fetch($countID, $dbh);
68 for ($i = 0; $i < $count; $i++) {
69 $name = dba_fetch("${msgID}_name_${i}", $dbh);
70 $comment = dba_fetch("${msgID}_comment_${i}", $dbh);
71 // push a new struct onto the return array
74 "comment" => $comment,
79 // if we generated an error, create an error return response
81 return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
83 // otherwise, we create the right response
84 return new PhpXmlRpc\Response($encoder->encode($ra));
88 $srv = new PhpXmlRpc\Server(array(
89 "discuss.addComment" => array(
90 "function" => "addComment",
91 "signature" => $addComment_sig,
92 "docstring" => $addComment_doc,
94 "discuss.getComments" => array(
95 "function" => "getComments",
96 "signature" => $getComments_sig,
97 "docstring" => $getComments_doc,