-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.php
185 lines (167 loc) · 5 KB
/
comment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
include("xmlrpc.inc");
$mydir="/demo";
// define some utility functions
function bomb() { print "</body></html>"; exit(); }
function dispatch($client, $method, $args) {
$msg=new xmlrpcmsg($method, $args);
$resp=$client->send($msg);
if (!$resp) { print "<p>IO error: ".$client->errstr."</p>"; bomb(); }
if ($resp->faultCode()) {
print "<p>There was an error: " . $resp->faultCode() . " " .
$resp->faultString() . "</p>";
bomb();
}
return php_xmlrpc_decode($resp->value());
}
// create client for discussion server
$dclient=new xmlrpc_client("${mydir}/discuss.php",
"xmlrpc.usefulinc.com", 80);
// check if we're posting a comment, and send it if so
$storyid=$HTTP_POST_VARS["storyid"];
if ($storyid) {
// print "Returning to " . $HTTP_POST_VARS["returnto"];
$res=dispatch($dclient, "discuss.addComment",
array(new xmlrpcval($storyid),
new xmlrpcval(stripslashes
($HTTP_POST_VARS["name"])),
new xmlrpcval(stripslashes
($HTTP_POST_VARS["commenttext"]))));
// send the browser back to the originating page
Header("Location: ${mydir}/comment.php?catid=" .
$HTTP_POST_VARS["catid"] . "&chanid=" .
$HTTP_POST_VARS["chanid"] . "&oc=" .
$HTTP_POST_VARS["catid"]);
exit(0);
}
// now we've got here, we're exploring the story store
?>
<html><head><title>meerkat browser</title></head>
<body bgcolor="#ffffff">
<h2>Meerkat integration</h2>
<?php
$catid=$HTTP_GET_VARS["catid"];
if ($HTTP_GET_VARS["oc"]==$catid)
$chanid=$HTTP_GET_VARS["chanid"];
else
$chanid=0;
$client=new xmlrpc_client("/meerkat/xml-rpc/server.php",
"www.oreillynet.com", 80);
if ($HTTP_GET_VARS["comment"] &&
(!$HTTP_GET_VARS["cdone"])) {
// we're making a comment on a story,
// so display a comment form
?>
<h3>Make a comment on the story</h3>
<form method="post">
<p>Your name:<br /><input type="text" size="30" name="name" /></p>
<p>Your comment:<br /><textarea rows="5" cols="60"
name="commenttext"></textarea></p>
<input type="submit" value="Send comment" />
<input type="hidden" name="storyid"
value="<?php echo $HTTP_GET_VARS["comment"];?>" />
<input type="hidden" name="chanid"
value="<?php echo $chanid; ?>" />
<input type="hidden" name="catid"
value="<?php echo $catid; ?>" />
</form>
<?php
} else {
$categories=dispatch($client, "meerkat.getCategories", array());
if ($catid)
$sources = dispatch($client, "meerkat.getChannelsByCategory",
array(new xmlrpcval($catid, "int")));
if ($chanid) {
$stories = dispatch($client, "meerkat.getItems",
array(new xmlrpcval(
array(
"channel" => new xmlrpcval($chanid, "int"),
"ids" => new xmlrpcval(1, "int"),
"descriptions" => new xmlrpcval(200, "int"),
"num_items" => new xmlrpcval(5, "int"),
"dates" => new xmlrpcval(0, "int")
), "struct")));
}
?>
<form>
<p>Subject area:<br />
<select name="catid">
<?php
if (!$catid)
print "<option value=\"0\">Choose a category</option>\n";
while(list($k,$v) = each($categories)) {
print "<option value=\"" . $v['id'] ."\"";
if ($v['id']==$catid) print " selected=\"selected\"";
print ">". $v['title'] . "</option>\n";
}
?>
</select></p>
<?php
if ($catid) {
?>
<p>News source:<br />
<select name="chanid">
<?php
if (!$chanid)
print "<option value=\"0\">Choose a source</option>\n";
while(list($k,$v) = each($sources)) {
print "<option value=\"" . $v['id'] ."\"";
if ($v['id']==$chanid) print "\" selected=\"selected\"";
print ">". $v['title'] . "</option>\n";
}
?>
</select>
</p>
<?php
} // end if ($catid)
?>
<p><input type="submit" value="Update" /></p>
<input type="hidden" name="oc" value="<?php echo $catid; ?>" />
</form>
<?php
if ($chanid) {
?>
<h2>Stories available</h2>
<table>
<?php
while(list($k,$v) = each($stories)) {
print "<tr>";
print "<td><b>" . $v['title'] . "</b><br />";
print $v['description'] . "<br />";
print "<em><a target=\"_blank\" href=\"" .
$v['link'] . "\">Read full story</a> ";
print "<a href=\"comment.php?catid=${catid}&chanid=${chanid}&" .
"oc=${oc}&comment=" . $v['id'] . "\">Comment on this story</a>";
print "</em>";
print "</td>";
print "</tr>\n";
// now look for existing comments
$res=dispatch($dclient, "discuss.getComments",
array(new xmlrpcval($v['id'])));
if (sizeof($res)>0) {
print "<tr><td bgcolor=\"#dddddd\"><p><b><i>" .
"Comments on this story:</i></b></p>";
for($i=0; $i<sizeof($res); $i++) {
$s=$res[$i];
print "<p><b>From:</b> " . htmlentities($s['name']) . "<br />";
print "<b>Comment:</b> " . htmlentities($s['comment']) . "</p>";
}
print "</td></tr>\n";
}
print "<tr><td><hr /></td></tr>\n";
}
?>
</table>
<?php
} // end if ($chanid)
} // end if comment
?>
<hr />
<p>
<a href="http://meerkat.oreillynet.com"><img align="right"
src="http://meerkat.oreillynet.com/icons/meerkat-powered.jpg"
height="31" width="88" alt="Meerkat powered, yeah!"
border="0" hspace="8" /></a>
<em>$Id$</em></p>
</body>
</html>