3 include_once __DIR__ . "/../../src/Autoloader.php";
4 PhpXmlRpc\Autoloader::register();
8 // define some utility functions
11 print "</body></html>";
15 function dispatch($client, $method, $args)
17 $req = new PhpXmlRpc\Request($method, $args);
18 $resp = $client->send($req);
20 print "<p>IO error: " . $client->errstr . "</p>";
23 if ($resp->faultCode()) {
24 print "<p>There was an error: " . $resp->faultCode() . " " .
25 $resp->faultString() . "</p>";
29 $encoder = new PhpXmlRpc\Encoder();
30 return $encoder->decode($resp->value());
33 // create client for discussion server
34 $dclient = new PhpXmlRpc\Client("http://xmlrpc.usefulinc.com/${mydir}discuss.php");
36 // check if we're posting a comment, and send it if so
37 @$storyid = $_POST["storyid"];
40 // print "Returning to " . $HTTP_POST_VARS["returnto"];
42 $res = dispatch($dclient, "discuss.addComment",
43 array(new PhpXmlRpc\Value($storyid),
44 new PhpXmlRpc\Value(stripslashes(@$_POST["name"])),
45 new PhpXmlRpc\Value(stripslashes(@$_POST["commenttext"])),));
47 // send the browser back to the originating page
48 Header("Location: ${mydir}/comment.php?catid=" .
49 $_POST["catid"] . "&chanid=" .
50 $_POST["chanid"] . "&oc=" .
55 // now we've got here, we're exploring the story store
59 <head><title>meerkat browser</title></head>
60 <body bgcolor="#ffffff">
61 <h2>Meerkat integration</h2>
63 @$catid = $_GET["catid"];
64 if (@$_GET["oc"] == $catid) {
65 @$chanid = $_GET["chanid"];
70 $client = new PhpXmlRpc\Client("http://www.oreillynet.com/meerkat/xml-rpc/server.php");
72 if (@$_GET["comment"] &&
75 // we're making a comment on a story,
76 // so display a comment form
78 <h3>Make a comment on the story</h3>
80 <p>Your name:<br/><input type="text" size="30" name="name"/></p>
82 <p>Your comment:<br/><textarea rows="5" cols="60"
83 name="commenttext"></textarea></p>
84 <input type="submit" value="Send comment"/>
85 <input type="hidden" name="storyid"
86 value="<?php echo @$_GET["comment"];
88 <input type="hidden" name="chanid"
89 value="<?php echo $chanid;
91 <input type="hidden" name="catid"
92 value="<?php echo $catid;
99 $categories = dispatch($client, "meerkat.getCategories", array());
101 $sources = dispatch($client, "meerkat.getChannelsByCategory",
102 array(new PhpXmlRpc\Value($catid, "int")));
105 $stories = dispatch($client, "meerkat.getItems",
106 array(new PhpXmlRpc\Value(
108 "channel" => new PhpXmlRpc\Value($chanid, "int"),
109 "ids" => new PhpXmlRpc\Value(1, "int"),
110 "descriptions" => new PhpXmlRpc\Value(200, "int"),
111 "num_items" => new PhpXmlRpc\Value(5, "int"),
112 "dates" => new PhpXmlRpc\Value(0, "int"),
117 <p>Subject area:<br/>
118 <select name="catid">
121 print "<option value=\"0\">Choose a category</option>\n";
123 while (list($k, $v) = each($categories)) {
124 print "<option value=\"" . $v['id'] . "\"";
125 if ($v['id'] == $catid) {
126 print " selected=\"selected\"";
128 print ">" . $v['title'] . "</option>\n";
136 <select name="chanid">
139 print "<option value=\"0\">Choose a source</option>\n";
141 while (list($k, $v) = each($sources)) {
142 print "<option value=\"" . $v['id'] . "\"";
143 if ($v['id'] == $chanid) {
144 print "\" selected=\"selected\"";
146 print ">" . $v['title'] . "</option>\n";
157 <p><input type="submit" value="Update"/></p>
158 <input type="hidden" name="oc" value="<?php echo $catid;
166 <h2>Stories available</h2>
169 while (list($k, $v) = each($stories)) {
171 print "<td><b>" . $v['title'] . "</b><br />";
172 print $v['description'] . "<br />";
173 print "<em><a target=\"_blank\" href=\"" .
174 $v['link'] . "\">Read full story</a> ";
175 print "<a href=\"comment.php?catid=${catid}&chanid=${chanid}&" .
176 "oc=${oc}&comment=" . $v['id'] . "\">Comment on this story</a>";
180 // now look for existing comments
181 $res = dispatch($dclient, "discuss.getComments",
182 array(new PhpXmlRpc\Value($v['id'])));
183 if (sizeof($res) > 0) {
184 print "<tr><td bgcolor=\"#dddddd\"><p><b><i>" .
185 "Comments on this story:</i></b></p>";
186 for ($i = 0; $i < sizeof($res); $i++) {
188 print "<p><b>From:</b> " . htmlentities($s['name']) . "<br />";
189 print "<b>Comment:</b> " . htmlentities($s['comment']) . "</p>";
191 print "</td></tr>\n";
193 print "<tr><td><hr /></td></tr>\n";
200 } // end if ($chanid)
205 <a href="http://meerkat.oreillynet.com"><img align="right"
206 src="http://meerkat.oreillynet.com/icons/meerkat-powered.jpg"
207 height="31" width="88" alt="Meerkat powered, yeah!"
208 border="0" hspace="8"/></a>