Convert docs files to unix newlines
[plcapi.git] / demo / client / comment.php
1 <?php
2 include("xmlrpc.inc");
3
4 $mydir="/demo";
5
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>";
15                 bomb();
16         }
17         return php_xmlrpc_decode($resp->value());
18 }
19
20 // create client for discussion server
21 $dclient=new xmlrpc_client("${mydir}/discuss.php",
22                                                                                                          "xmlrpc.usefulinc.com", 80);
23
24 // check if we're posting a comment, and send it if so
25 @$storyid=$_POST["storyid"];
26 if ($storyid) {
27
28
29         //      print "Returning to " . $HTTP_POST_VARS["returnto"];
30
31         $res=dispatch($dclient, "discuss.addComment",
32                                                                 array(new xmlrpcval($storyid),
33                                                                                         new xmlrpcval(stripslashes
34                                                                                                                                                 (@$_POST["name"])),
35                                                                                         new xmlrpcval(stripslashes
36                                                                                                                                                 (@$_POST["commenttext"]))));
37
38         // send the browser back to the originating page
39         Header("Location: ${mydir}/comment.php?catid=" .
40                                  $_POST["catid"] . "&chanid=" .
41                                  $_POST["chanid"] . "&oc=" .
42                                  $_POST["catid"]);
43         exit(0);
44 }
45
46 // now we've got here, we're exploring the story store
47
48 ?>
49 <html><head><title>meerkat browser</title></head>
50 <body bgcolor="#ffffff">
51 <h2>Meerkat integration</h2>
52 <?php
53 @$catid=$_GET["catid"];
54 if (@$_GET["oc"]==$catid)
55         @$chanid=$_GET["chanid"];
56 else
57         $chanid=0;
58
59 $client=new xmlrpc_client("/meerkat/xml-rpc/server.php",
60                                                                                                         "www.oreillynet.com", 80);
61
62 if (@$_GET["comment"] &&
63                 (!@$_GET["cdone"])) {
64         // we're making a comment on a story,
65         // so display a comment form
66 ?>
67 <h3>Make a comment on the story</h3>
68 <form method="post">
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; ?>" />
79
80 </form>
81 <?php
82 } else {
83         $categories=dispatch($client, "meerkat.getCategories", array());
84         if ($catid)
85                 $sources = dispatch($client, "meerkat.getChannelsByCategory",
86                                                                                                 array(new xmlrpcval($catid, "int")));
87         if ($chanid) {
88                 $stories = dispatch($client, "meerkat.getItems",
89                                         array(new xmlrpcval(
90                                                 array(
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")
96                                                 ), "struct")));
97         }
98 ?>
99 <form>
100 <p>Subject area:<br />
101 <select name="catid">
102 <?php
103         if (!$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";
109         }
110 ?>
111 </select></p>
112 <?php
113         if ($catid) {
114 ?>
115 <p>News source:<br />
116 <select name="chanid">
117 <?php
118                 if (!$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";
124                 }
125 ?>
126 </select>
127 </p>
128
129 <?php
130                 } // end if ($catid)
131 ?>
132
133 <p><input type="submit" value="Update" /></p>
134 <input type="hidden" name="oc" value="<?php echo $catid; ?>" />
135 </form>
136
137 <?php
138          if ($chanid) {
139 ?>
140
141 <h2>Stories available</h2>
142 <table>
143 <?php
144          while(list($k,$v) = each($stories)) {
145                  print "<tr>";
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>";
152                  print "</em>";
153                  print "</td>";
154                  print "</tr>\n";
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++) {
162                                  $s=$res[$i];
163                                  print "<p><b>From:</b> " . htmlentities($s['name']) . "<br />";
164                                  print "<b>Comment:</b> " . htmlentities($s['comment']) . "</p>";
165                          }
166                          print "</td></tr>\n";
167                  }
168                  print "<tr><td><hr /></td></tr>\n";
169          }
170 ?>
171 </table>
172
173 <?php
174                 } // end if ($chanid)
175 } // end if comment
176 ?>
177 <hr />
178 <p>
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>
183 </p>
184 </body>
185 </html>