Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 203 lines (168 sloc) 6.512 kB
6f498b6 Some examples
root authored
1 <pre>
2 <?php
3 // Include the Class
4 include 'etherpad-lite-client.php';
5
6 // Create an instance
89d4f14 @JohnMcLear I need to stop changing the bloomin host name before commiting
JohnMcLear authored
7 $instance = new EtherpadLiteClient('EtherpadFTW','http://beta.etherpad.org:9001/api'); // Example URL: http://your.hostname.tld:8080/api
6f498b6 Some examples
root authored
8
5f7e47d @JohnMcLear Removed error reporting and included a link to the API draft
JohnMcLear authored
9 // All API calls return a JSON value as documented in the API here: https://github.com/Pita/etherpad-lite/wiki/HTTP-API
6f498b6 Some examples
root authored
10
11 echo "<h1>Pads</h1>";
12
13 /* Example: Create Author */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
14 try {
15 $author = $instance->createAuthor('John McLear'); // This really needs explaining..
16 $authorID = $author->authorID;
6f498b6 Some examples
root authored
17 echo "The AuthorID is now $authorID\n\n";
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
18 } catch (Exception $e) {
19 // the pad already exists or something else went wrong
20 echo "\n\ncreateAuthor Failed with message ". $e->getMessage();
21 }
6f498b6 Some examples
root authored
22
6b90a4b @JohnMcLear Added new functions and fixed bugs, mostly usermapping stuff, nothing…
JohnMcLear authored
23 /* Example: get Mapped Author ID based on a value from your web application such as the userID */
24 try {
25 $authormap = $instance->createAuthorIfNotExistsFor('John McLear', 'Cake'); // This would show my local UserID mapping John McLear as Cake on Etherpad
26 } catch (Exception $e) {
27 echo "\n\ncreateAuthorIfNotExistsFor Failed with message ". $e->getMessage();
28 }
29
30 //cake
31
6f498b6 Some examples
root authored
32
33 /* Example: Create a new Pad */
aac76d9 @TomNomNom Updated examples to include try/catch
authored
34 try {
35 $instance->createPad('testPad','Hello world');
36 } catch (Exception $e) {
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
37 echo "\n\ncreatePad Failed with message ". $e->getMessage();
aac76d9 @TomNomNom Updated examples to include try/catch
authored
38 }
6f498b6 Some examples
root authored
39
40 /* Example: Set Text into a Pad */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
41 try {
42 $instance->setText('testPad','Hello world');
43 } catch (Exception $e) {
44 echo "\n\nsetText Failed with message ". $e->getMessage();
45 }
6f498b6 Some examples
root authored
46
47 /* Example: Create a new Pad */
d12ab60 @TomNomNom Updated examples to include try/catch
authored
48 try {
49 $instance->createPad('testPad','Hello world');
50 } catch (Exception $e) {
51 // the pad already exists or something else went wrong
52 echo "Failed with message ". $e->getMessage();
53 }
6f498b6 Some examples
root authored
54
55 /* Example: Get Ready Only ID of a pad */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
56 try {
57 $readOnlyID = $instance->getReadOnlyID('testPad');
58 echo "The read only ID of this pad is: $readOnlyID->readOnlyID\n\n";
59 } catch (Exception $e) {
60 echo "\n\ngetReadOnlyID Failed with message ". $e->getMessage();
61 }
62
6f498b6 Some examples
root authored
63
64 /* Example: Get Public Status of a pad and include some logic -- This only works for group pads */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
65 try {
66 $getpublicStatus = $instance->getPublicStatus('testPad');
67 if ($getpublicStatus->publicStatus === false){echo "This Pad is not public\n\n";}else{echo "This Pad is public\n\n";}
68 } catch (Exception $e) {
69 // the pad already exists or something else went wrong
70 echo "\n\ngetPublicStatus Failed with message ". $e->getMessage();
71 }
6f498b6 Some examples
root authored
72
73 /* Example: Set Public Status of a pad -- This only works for group pads */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
74 try {
75 $instance->setPublicStatus('testPad',true); // true or false
76 } catch (Exception $e) {
77 // the pad already exists or something else went wrong
78 echo "\n\nsetPublicStatus Failed with message ". $e->getMessage();
79 }
80
6f498b6 Some examples
root authored
81
82 /* Example: Set Password on a pad -- This only works for group pads */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
83 try {
84 $instance->setPassword('testPad','aPassword');
85 } catch (Exception $e) {
86 // the pad already exists or something else went wrong
87 echo "\n\nsetPassword Failed with message ". $e->getMessage();
88 }
6f498b6 Some examples
root authored
89
90 /* Example: Get true/false if the pad is password protected and include some logic -- This only works for group pads*/
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
91 try {
92 $isPasswordProtected = $instance->isPasswordProtected('testPad');
93 if ($isPasswordProtected->isPasswordprotected === false){echo "Pad is not password protected\n\n";}else{echo "Pad is password protected\n\n";}
94 } catch (Exception $e) {
95 // the pad already exists or something else went wrong
96 echo "\n\nisPasswordProtected Failed with message ". $e->getMessage();
97 }
6f498b6 Some examples
root authored
98
99 /* Example: Get revisions Count of a pad */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
100 try {
101 $revisionCount = $instance->getRevisionsCount('testPad');
102 $revisionCount = $revisionCount->revisions;
103 echo "Pad has $revisionCount revisions\n\n";
104 } catch (Exception $e) {
105 // the pad already exists or something else went wrong
106 echo "\n\ngetRevisionsCount Failed with message ". $e->getMessage();
107 }
6f498b6 Some examples
root authored
108
109 /* Example: Get Pad Contents and echo to screen */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
110 try {
111 $padContents = $instance->getText('testPad');
112 echo "Pad text is: <br/><ul>$padContents->text\n\n</ul>";
113 echo "End of Pad Text\n\n<hr>";
114 } catch (Exception $e) {
115 // the pad already exists or something else went wrong
0223c66 @JohnMcLear Fixed typo and moved delete to end of sequence to stop some calls act…
JohnMcLear authored
116 echo "\n\ngetText Failed with message ". $e->getMessage();
117 }
118
119 /* Example: Delete Pad */
120 try {
121 $instance->deletePad('testPad');
122 } catch (Exception $e) {
123 // the pad doesn't exist?
124 echo "\n\ndeletePad Failed with message ". $e->getMessage();
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
125 }
126
6f498b6 Some examples
root authored
127 echo "<h1>Groups</h1>";
128
129 /* Example: Create Group */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
130 try {
131 $createGroup = $instance->createGroup();
132 $groupID = $createGroup->groupID;
133 echo "New GroupID is $groupID\n\n";
134 } catch (Exception $e) {
135 // the pad already exists or something else went wrong
136 echo "\n\ncreateGroup Failed with message ". $e->getMessage();
137 }
6f498b6 Some examples
root authored
138
139 /* Example: Create Group Pad */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
140 try {
141 $newPad = $instance->createGroupPad($groupID,'testpad','Example text body');
142 $padID = $newPad->padID;
143 echo "Created new pad with padID: $padID\n\n";
144 } catch (Exception $e) {
145 // the pad already exists or something else went wrong
146 echo "\n\ncreateGroupPad Failed with message ". $e->getMessage();
147 }
6f498b6 Some examples
root authored
148
149 /* Example: List Pads from a group */
d12ab60 @TomNomNom Updated examples to include try/catch
authored
150 try {
151 $padList = $instance->listPads($groupID);
152 echo "Available pads for this group:\n";
153 var_dump($padList->padIDs);
154 echo "\n";
155 } catch (Exception $e) {
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
156 echo "\n\nlistPads Failed: ". $e->getMessage();
d12ab60 @TomNomNom Updated examples to include try/catch
authored
157 }
6f498b6 Some examples
root authored
158
159 /* Example: Create Mapped Group -- This maps a humanly readable name to a groupID */
6b90a4b @JohnMcLear Added new functions and fixed bugs, mostly usermapping stuff, nothing…
JohnMcLear authored
160 try {
161 $mapGroup = $instance->createGroupIfNotExistsFor("Guests");
162 } catch (Exception $e) {
163 echo "\n\ndeleteGroupFailed: ". $e->getMessage();
164 }
6f498b6 Some examples
root authored
165
166 /* Example: Delete a Group */
2e8369e @JohnMcLear Added an example hostname definition and added try function to each c…
JohnMcLear authored
167 try {
168 $instance->deleteGroup($groupID);
169 } catch (Exception $e) {
170 echo "\n\ndeleteGroupFailed: ". $e->getMessage();
171 }
172
6f498b6 Some examples
root authored
173
174 echo "<hr>";
175 echo "<h1>Sessions</h1>";
176
177 /* Example: Create Session */
178 $validUntil = mktime(0, 0, 0, date("m"), date("d")+1, date("y")); // One day in the future
179 $sessionID = $instance->createSession($groupID, $authorID, $validUntil);
180 echo "New Session ID is $sessionID->sessionID\n\n";
181
182 /* Example: Get Session info */
183 echo "Session info:\n";
184 $sessionID = $sessionID->sessionID;
185 $sessioninfo = $instance->getSessionInfo($sessionID);
186 var_dump($sessioninfo);
187 echo "\n";
188
189 /* Example: List Sessions os Author */
190 echo "Sessions the Author $authorID is part of:\n";
191 $authorSessions = $instance->listSessionsOfAuthor($authorID);
192 var_dump($authorSessions);
193 echo "\n";
194
195 /* Example: List Sessions of Group */
196 $groupSessions = $instance->listSessionsOfGroup($groupID);
197 var_dump($groupSessions);
198
199 /* Example: Delete Session */
200 $instance->deleteSession($sessionID);
201
202 ?>
Something went wrong with that request. Please try again.