forked from tomnomnom/etherpad-lite-client
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexamples.php
202 lines (168 loc) · 6.36 KB
/
examples.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
<pre>
<?php
// Include the Class
include 'etherpad-lite-client.php';
// Create an instance
$instance = new EtherpadLiteClient('EtherpadFTW','http://beta.etherpad.org:9001/api'); // Example URL: http://your.hostname.tld:8080/api
// All API calls return a JSON value as documented in the API here: https://github.com/Pita/etherpad-lite/wiki/HTTP-API
echo "<h1>Pads</h1>";
/* Example: Create Author */
try {
$author = $instance->createAuthor('John McLear'); // This really needs explaining..
$authorID = $author->authorID;
echo "The AuthorID is now $authorID\n\n";
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\ncreateAuthor Failed with message ". $e->getMessage();
}
/* Example: get Mapped Author ID based on a value from your web application such as the userID */
try {
$authormap = $instance->createAuthorIfNotExistsFor('John McLear', 'Cake'); // This would show my local UserID mapping John McLear as Cake on Etherpad
} catch (Exception $e) {
echo "\n\ncreateAuthorIfNotExistsFor Failed with message ". $e->getMessage();
}
//cake
/* Example: Create a new Pad */
try {
$instance->createPad('testPad','Hello world');
} catch (Exception $e) {
echo "\n\ncreatePad Failed with message ". $e->getMessage();
}
/* Example: Set Text into a Pad */
try {
$instance->setText('testPad','Hello world');
} catch (Exception $e) {
echo "\n\nsetText Failed with message ". $e->getMessage();
}
/* Example: Create a new Pad */
try {
$instance->createPad('testPad','Hello world');
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "Failed with message ". $e->getMessage();
}
/* Example: Get Ready Only ID of a pad */
try {
$readOnlyID = $instance->getReadOnlyID('testPad');
echo "The read only ID of this pad is: $readOnlyID->readOnlyID\n\n";
} catch (Exception $e) {
echo "\n\ngetReadOnlyID Failed with message ". $e->getMessage();
}
/* Example: Get Public Status of a pad and include some logic -- This only works for group pads */
try {
$getpublicStatus = $instance->getPublicStatus('testPad');
if ($getpublicStatus->publicStatus === false){echo "This Pad is not public\n\n";}else{echo "This Pad is public\n\n";}
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\ngetPublicStatus Failed with message ". $e->getMessage();
}
/* Example: Set Public Status of a pad -- This only works for group pads */
try {
$instance->setPublicStatus('testPad',true); // true or false
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\nsetPublicStatus Failed with message ". $e->getMessage();
}
/* Example: Set Password on a pad -- This only works for group pads */
try {
$instance->setPassword('testPad','aPassword');
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\nsetPassword Failed with message ". $e->getMessage();
}
/* Example: Get true/false if the pad is password protected and include some logic -- This only works for group pads*/
try {
$isPasswordProtected = $instance->isPasswordProtected('testPad');
if ($isPasswordProtected->isPasswordprotected === false){echo "Pad is not password protected\n\n";}else{echo "Pad is password protected\n\n";}
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\nisPasswordProtected Failed with message ". $e->getMessage();
}
/* Example: Get revisions Count of a pad */
try {
$revisionCount = $instance->getRevisionsCount('testPad');
$revisionCount = $revisionCount->revisions;
echo "Pad has $revisionCount revisions\n\n";
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\ngetRevisionsCount Failed with message ". $e->getMessage();
}
/* Example: Get Pad Contents and echo to screen */
try {
$padContents = $instance->getText('testPad');
echo "Pad text is: <br/><ul>$padContents->text\n\n</ul>";
echo "End of Pad Text\n\n<hr>";
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\ngetText Failed with message ". $e->getMessage();
}
/* Example: Delete Pad */
try {
$instance->deletePad('testPad');
} catch (Exception $e) {
// the pad doesn't exist?
echo "\n\ndeletePad Failed with message ". $e->getMessage();
}
echo "<h1>Groups</h1>";
/* Example: Create Group */
try {
$createGroup = $instance->createGroup();
$groupID = $createGroup->groupID;
echo "New GroupID is $groupID\n\n";
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\ncreateGroup Failed with message ". $e->getMessage();
}
/* Example: Create Group Pad */
try {
$newPad = $instance->createGroupPad($groupID,'testpad','Example text body');
$padID = $newPad->padID;
echo "Created new pad with padID: $padID\n\n";
} catch (Exception $e) {
// the pad already exists or something else went wrong
echo "\n\ncreateGroupPad Failed with message ". $e->getMessage();
}
/* Example: List Pads from a group */
try {
$padList = $instance->listPads($groupID);
echo "Available pads for this group:\n";
var_dump($padList->padIDs);
echo "\n";
} catch (Exception $e) {
echo "\n\nlistPads Failed: ". $e->getMessage();
}
/* Example: Create Mapped Group -- This maps a humanly readable name to a groupID */
try {
$mapGroup = $instance->createGroupIfNotExistsFor("Guests");
} catch (Exception $e) {
echo "\n\ndeleteGroupFailed: ". $e->getMessage();
}
/* Example: Delete a Group */
try {
$instance->deleteGroup($groupID);
} catch (Exception $e) {
echo "\n\ndeleteGroupFailed: ". $e->getMessage();
}
echo "<hr>";
echo "<h1>Sessions</h1>";
/* Example: Create Session */
$validUntil = mktime(0, 0, 0, date("m"), date("d")+1, date("y")); // One day in the future
$sessionID = $instance->createSession($groupID, $authorID, $validUntil);
echo "New Session ID is $sessionID->sessionID\n\n";
/* Example: Get Session info */
echo "Session info:\n";
$sessionID = $sessionID->sessionID;
$sessioninfo = $instance->getSessionInfo($sessionID);
var_dump($sessioninfo);
echo "\n";
/* Example: List Sessions os Author */
echo "Sessions the Author $authorID is part of:\n";
$authorSessions = $instance->listSessionsOfAuthor($authorID);
var_dump($authorSessions);
echo "\n";
/* Example: List Sessions of Group */
$groupSessions = $instance->listSessionsOfGroup($groupID);
var_dump($groupSessions);
/* Example: Delete Session */
$instance->deleteSession($sessionID);
?>