-
Notifications
You must be signed in to change notification settings - Fork 27
/
etherpad-lite-client.php
213 lines (178 loc) · 5.66 KB
/
etherpad-lite-client.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
class EtherpadLiteClient
{
// INIT
// Private functions and functions to initialize the object
private $apikey;
private $baseurl;
private $apiversion = 1;
// Set parameters that will be needed
function setParams($key, $url = "http://localhost:9001/api", $version = 1)
{
$this->baseurl = $url;
$this->apikey = $key;
$this->apiversion = $version;
}
private function HTTPCall()
{
$args = func_num_args();
// Need a function to call, otherwise just give up
if($args == 0) {
return 1;
}
$call = $this->baseurl . "/" . $this->apiversion . "/" . func_get_arg(0) . "?apikey=" . $this->apikey;
// Append arguments to the call
$arg_list = func_get_args();
if($args > 1) {
for($i = 1; $i < $args; $i = $i+2) {
$call = $call . "&" . func_get_arg($i) . "=" . func_get_arg($i+1);
}
}
$conn = curl_init($call);
curl_setopt($conn, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($conn);
curl_close($conn);
return $result;
}
// GROUPS
// Pads can belong to a group. There will always be public pads that doesnt belong to a group (or we give this group the id 0)
// Creates a new group
function createGroup()
{
return $this->HTTPCall("createGroup");
}
// This functions helps you to map your application group ids to etherpad lite group ids
function createGroupIfNotExistsFor($groupMapper)
{
return $this->HTTPCall("createGroupIfNotExistsFor", "groupMapper", $groupMapper);
}
// Deletes a group
function deleteGroup($groupID)
{
return $this->HTTPCall("deleteGroup", "groupID", $groupID);
}
// returns all pads of this group
function listPads($groupID)
{
return $this->HTTPCall("listPads", "groupID", $groupID);
}
// creates a new pad in this group
function createGroupPad($groupID, $padName, $text = null)
{
if($text) {
return $this->HTTPCall("createGroupPad", "groupID", $groupID, "padName", $padName, "text", $text);
} else {
return $this->HTTPCall("createGroupPad", "groupID", $groupID, "padName", $padName);
}
}
// AUTHORS
// Theses authors are bind to the attributes the users choose (color and name).
// creates a new author
function createAuthor($name)
{
if($name) {
return $this->HTTPCall("createAuthor", "name", $name);
} else {
return $this->HTTPCall("createAuthor");
}
}
// this functions helps you to map your application author ids to etherpad lite author ids
function createAuthorIfNotExistsFor($authorMapper, $name)
{
if($name) {
return $this->HTTPCall("createAuthorIfNotExistsFor", "authorMapper", $authorMapper, "name", $name);
} else {
return $this->HTTPCall("createAuthorIfNotExistsFor", "authorMapper", $authorMapper);
}
}
// SESSIONS
// Sessions can be created between a group and a author. This allows
// an author to access more than one group. The sessionID will be set as
// a cookie to the client and is valid until a certian date.
// creates a new session
function createSession($groupID, $authorID, $validUntil)
{
return $this->HTTPCall("createSession", "groupID", $groupID, "authorID", $authorID, "validUntil", $validUntil);
}
// deletes a session
function deleteSession($sessionID)
{
return $this->HTTPCall("deleteSession", "sessionID", $sessionID);
}
// returns informations about a session
function getSessionInfo($sessionID)
{
return $this->HTTPCall("getSessionInfo", "sessionID", $sessionID);
}
// returns all sessions of a group
function listSessionsOfGroup($groupID)
{
return $this->HTTPCall("listSessionOfGroup", "groupID", $groupID);
}
// returns all sessions of an author
function listSessionsOfAuthor($authorID)
{
return $this->HTTPCall("listSessionsOfAuthor", "authorID", $authorID);
}
// PAD CONTENT
// Pad content can be updated and retrieved through the API
// returns the text of a pad
function getText($padID) // should take optional $rev
{
return $this->HTTPCall("getText", "padID", $padID);
}
// sets the text of a pad
function setText($padID, $text)
{
return $this->HTTPCall("setText", "padID", $padID, "text", $text);
}
// PAD
// Group pads are normal pads, but with the name schema
// GROUPID$PADNAME. A security manager controls access of them and its
// forbidden for normal pads to include a $ in the name.
// creates a new pad
function createPad($padID, $text)
{
if($text) {
return $this->HTTPCall("createPad", "padID", $padID, "text", $text);
} else {
return $this->HTTPCall("createPad", "padID", $padID);
}
}
// returns the number of revisions of this pad
function getRevisionsCount($padID)
{
return $this->HTTPCall("getRevisionsCount", "padID", $padID);
}
// deletes a pad
function deletePad($padID)
{
return $this->HTTPCall("deletePad", "padID", $padID);
}
// returns the read only link of a pad
function getReadOnlyID($padID)
{
return $this->HTTPCall("getReadOnlyID", "padID", $padID);
}
// sets a boolean for the public status of a pad
function setPublicStatus($padID, $publicStatus)
{
return $this->HTTPCall("setPublicStatus", "padID", $padID, "publicStatus", $publicStatus);
}
// return true of false
function getPublicStatus($padID)
{
return $this->HTTPCall("getPublicStatus", "padID", $padID);
}
// returns ok or a error message
function setPassword($padID, $password)
{
return $this->HTTPCall("setPassword", "padID", $padID, "password", $password);
}
// returns true or false
function isPasswordProtected($padID)
{
return $this->HTTPCall("isPasswordProtected", "padID", $padID);
}
}
?>