1<pre> 2<?php 3// Include the Class 4include 'etherpad-lite-client.php'; 5 6// Create an instance 7$instance = new EtherpadLiteClient('EtherpadFTW','http://beta.etherpad.org:9001/api'); // Example URL: http://your.hostname.tld:8080/api 8 9// All API calls return a JSON value as documented in the API here: https://github.com/Pita/etherpad-lite/wiki/HTTP-API 10 11echo "<h1>Pads</h1>"; 12 13/* Example: Create Author */ 14try { 15 $author = $instance->createAuthor('John McLear'); // This really needs explaining.. 16 $authorID = $author->authorID; 17echo "The AuthorID is now $authorID\n\n"; 18} catch (Exception $e) { 19 // the pad already exists or something else went wrong 20 echo "\n\ncreateAuthor Failed with message ". $e->getMessage(); 21} 22 23/* Example: get Mapped Author ID based on a value from your web application such as the userID */ 24try { 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 32 33/* Example: Create a new Pad */ 34try { 35 $instance->createPad('testPad','Hello world'); 36} catch (Exception $e) { 37 echo "\n\ncreatePad Failed with message ". $e->getMessage(); 38} 39 40/* Example: Set Text into a Pad */ 41try { 42 $instance->setText('testPad','Hello world'); 43} catch (Exception $e) { 44 echo "\n\nsetText Failed with message ". $e->getMessage(); 45} 46 47/* Example: Create a new Pad */ 48try { 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} 54 55/* Example: Get Ready Only ID of a pad */ 56try { 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 63 64/* Example: Get Public Status of a pad and include some logic -- This only works for group pads */ 65try { 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} 72 73/* Example: Set Public Status of a pad -- This only works for group pads */ 74try { 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 81 82/* Example: Set Password on a pad -- This only works for group pads */ 83try { 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} 89 90/* Example: Get true/false if the pad is password protected and include some logic -- This only works for group pads*/ 91try { 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} 98 99/* Example: Get revisions Count of a pad */ 100try { 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} 108 109/* Example: Get Pad Contents and echo to screen */ 110try { 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 116 echo "\n\ngetText Failed with message ". $e->getMessage(); 117} 118 119/* Example: Delete Pad */ 120try { 121 $instance->deletePad('testPad'); 122} catch (Exception $e) { 123 // the pad doesn't exist? 124 echo "\n\ndeletePad Failed with message ". $e->getMessage(); 125} 126 127echo "<h1>Groups</h1>"; 128 129/* Example: Create Group */ 130try { 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} 138 139/* Example: Create Group Pad */ 140try { 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} 148 149/* Example: List Pads from a group */ 150try { 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) { 156 echo "\n\nlistPads Failed: ". $e->getMessage(); 157} 158 159/* Example: Create Mapped Group -- This maps a humanly readable name to a groupID */ 160try { 161 $mapGroup = $instance->createGroupIfNotExistsFor("Guests"); 162} catch (Exception $e) { 163 echo "\n\ndeleteGroupFailed: ". $e->getMessage(); 164} 165 166/* Example: Delete a Group */ 167try { 168 $instance->deleteGroup($groupID); 169} catch (Exception $e) { 170 echo "\n\ndeleteGroupFailed: ". $e->getMessage(); 171} 172 173 174echo "<hr>"; 175echo "<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); 180echo "New Session ID is $sessionID->sessionID\n\n"; 181 182/* Example: Get Session info */ 183echo "Session info:\n"; 184$sessionID = $sessionID->sessionID; 185$sessioninfo = $instance->getSessionInfo($sessionID); 186var_dump($sessioninfo); 187echo "\n"; 188 189/* Example: List Sessions os Author */ 190echo "Sessions the Author $authorID is part of:\n"; 191$authorSessions = $instance->listSessionsOfAuthor($authorID); 192var_dump($authorSessions); 193echo "\n"; 194 195/* Example: List Sessions of Group */ 196$groupSessions = $instance->listSessionsOfGroup($groupID); 197var_dump($groupSessions); 198 199/* Example: Delete Session */ 200$instance->deleteSession($sessionID); 201 202?> 203