6 // define some utility functions
7 function bomb() { print "</body></html>"; exit(); }
8 function dispatch($client, $method, $args) {
9 $msg=new xmlrpcmsg($method, $args);
10 $resp=$client->send($msg);
11 if (!$resp) { print "<p>IO error: ".$client->errstr."</p>"; bomb(); }
12 if ($resp->faultCode()) {
13 print "<p>There was an error: " . $resp->faultCode() . " " .
14 $resp->faultString() . "</p>";
17 return php_xmlrpc_decode($resp->value());
20 // create client for discussion server
21 $dclient=new xmlrpc_client("${mydir}/discuss.php",
22 "xmlrpc.usefulinc.com", 80);
24 // check if we're posting a comment, and send it if so
25 @$storyid=$_POST["storyid"];
29 // print "Returning to " . $HTTP_POST_VARS["returnto"];
31 $res=dispatch($dclient, "discuss.addComment",
32 array(new xmlrpcval($storyid),
33 new xmlrpcval(stripslashes
35 new xmlrpcval(stripslashes
36 (@$_POST["commenttext"]))));
38 // send the browser back to the originating page
39 Header("Location: ${mydir}/comment.php?catid=" .
40 $_POST["catid"] . "&chanid=" .
41 $_POST["chanid"] . "&oc=" .
46 // now we've got here, we're exploring the story store
49 <html><head><title>meerkat browser</title></head>
50 <body bgcolor="#ffffff">
51 <h2>Meerkat integration</h2>
53 @$catid=$_GET["catid"];
54 if (@$_GET["oc"]==$catid)
55 @$chanid=$_GET["chanid"];
59 $client=new xmlrpc_client("/meerkat/xml-rpc/server.php",
60 "www.oreillynet.com", 80);
62 if (@$_GET["comment"] &&
64 // we're making a comment on a story,
65 // so display a comment form
67 <h3>Make a comment on the story</h3>
69 <p>Your name:<br /><input type="text" size="30" name="name" /></p>
70 <p>Your comment:<br /><textarea rows="5" cols="60"
71 name="commenttext"></textarea></p>
72 <input type="submit" value="Send comment" />
73 <input type="hidden" name="storyid"
74 value="<?php echo @$_GET["comment"];?>" />
75 <input type="hidden" name="chanid"
76 value="<?php echo $chanid; ?>" />
77 <input type="hidden" name="catid"
78 value="<?php echo $catid; ?>" />
83 $categories=dispatch($client, "meerkat.getCategories", array());
85 $sources = dispatch($client, "meerkat.getChannelsByCategory",
86 array(new xmlrpcval($catid, "int")));
88 $stories = dispatch($client, "meerkat.getItems",
91 "channel" => new xmlrpcval($chanid, "int"),
92 "ids" => new xmlrpcval(1, "int"),
93 "descriptions" => new xmlrpcval(200, "int"),
94 "num_items" => new xmlrpcval(5, "int"),
95 "dates" => new xmlrpcval(0, "int")
100 <p>Subject area:<br />
101 <select name="catid">
104 print "<option value=\"0\">Choose a category</option>\n";
105 while(list($k,$v) = each($categories)) {
106 print "<option value=\"" . $v['id'] ."\"";
107 if ($v['id']==$catid) print " selected=\"selected\"";
108 print ">". $v['title'] . "</option>\n";
115 <p>News source:<br />
116 <select name="chanid">
119 print "<option value=\"0\">Choose a source</option>\n";
120 while(list($k,$v) = each($sources)) {
121 print "<option value=\"" . $v['id'] ."\"";
122 if ($v['id']==$chanid) print "\" selected=\"selected\"";
123 print ">". $v['title'] . "</option>\n";
133 <p><input type="submit" value="Update" /></p>
134 <input type="hidden" name="oc" value="<?php echo $catid; ?>" />
141 <h2>Stories available</h2>
144 while(list($k,$v) = each($stories)) {
146 print "<td><b>" . $v['title'] . "</b><br />";
147 print $v['description'] . "<br />";
148 print "<em><a target=\"_blank\" href=\"" .
149 $v['link'] . "\">Read full story</a> ";
150 print "<a href=\"comment.php?catid=${catid}&chanid=${chanid}&" .
151 "oc=${oc}&comment=" . $v['id'] . "\">Comment on this story</a>";
155 // now look for existing comments
156 $res=dispatch($dclient, "discuss.getComments",
157 array(new xmlrpcval($v['id'])));
158 if (sizeof($res)>0) {
159 print "<tr><td bgcolor=\"#dddddd\"><p><b><i>" .
160 "Comments on this story:</i></b></p>";
161 for($i=0; $i<sizeof($res); $i++) {
163 print "<p><b>From:</b> " . htmlentities($s['name']) . "<br />";
164 print "<b>Comment:</b> " . htmlentities($s['comment']) . "</p>";
166 print "</td></tr>\n";
168 print "<tr><td><hr /></td></tr>\n";
174 } // end if ($chanid)
179 <a href="http://meerkat.oreillynet.com"><img align="right"
180 src="http://meerkat.oreillynet.com/icons/meerkat-powered.jpg"
181 height="31" width="88" alt="Meerkat powered, yeah!"
182 border="0" hspace="8" /></a>