1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EtherpadLite; |
4
|
|
|
|
5
|
|
|
use EtherpadLite\Exception\UnsupportedMethodException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Client |
9
|
|
|
* |
10
|
|
|
* @package EtherpadLite |
11
|
|
|
* |
12
|
|
|
* @method Response createGroup() creates a new group |
13
|
|
|
* @method Response createGroupIfNotExistsFor($groupMapper) this functions helps you to map your application group ids to etherpad lite group ids |
14
|
|
|
* @method Response deleteGroup($groupID) deletes a group |
15
|
|
|
* @method Response listPads($groupID) returns all pads of this group |
16
|
|
|
* @method Response createGroupPad($groupID, $padName, $text = null) creates a new pad in this group |
17
|
|
|
* @method Response listAllGroups() lists all existing groups |
18
|
|
|
* |
19
|
|
|
* @method Response createAuthor($name = null) creates a new author |
20
|
|
|
* @method Response createAuthorIfNotExistsFor($authorMapper, $name = null) this functions helps you to map your application author ids to etherpad lite author ids |
21
|
|
|
* @method Response listPadsOfAuthor($authorID) returns an array of all pads this author contributed to |
22
|
|
|
* @method Response getAuthorName($authorID) Returns the Author Name of the author |
23
|
|
|
* |
24
|
|
|
* @method Response createSession($groupID, $authorID, $validUntil) creates a new session. validUntil is an unix timestamp in seconds |
25
|
|
|
* @method Response deleteSession($sessionID) deletes a session by id |
26
|
|
|
* @method Response getSessionInfo($sessionID) returns informations about a session |
27
|
|
|
* @method Response listSessionsOfGroup($groupID) returns all sessions of a group |
28
|
|
|
* @method Response listSessionsOfAuthor($authorID) returns all sessions of an author |
29
|
|
|
* |
30
|
|
|
* @method Response getText($padID, $rev = null) returns the text of a pad |
31
|
|
|
* @method Response setText($padID, $text) sets the text of a pad |
32
|
|
|
* @method Response getHTML($padID, $rev = null) returns the text of a pad formatted as HTML |
33
|
|
|
* @method Response setHTML($padID, $html) sets the html of a pad |
34
|
|
|
* @method Response getAttributePool($padID) returns the attribute pool of a pad |
35
|
|
|
* @method Response getRevisionChangeset($padID, $revision = null) get the changeset at a given revision, or last revision if 'rev' is not defined. |
36
|
|
|
* @method Response createDiffHTML($padID, $startRev, $endRev) returns an object of diffs from 2 points in a pad |
37
|
|
|
* @method Response restoreRevision($padID, $revision) restores revision from past as new changeset |
38
|
|
|
* |
39
|
|
|
* @method Response getChatHistory($padID, $start = null, $end = null) a part of the chat history, when start and end are given, the whole chat histroy, when no extra parameters are given |
40
|
|
|
* @method Response getChatHead($padID) returns the chatHead (last number of the last chat-message) of the pad |
41
|
|
|
* @method Response appendChatMessage($padID, $text, $authorID, $time = null) creates a chat message, saves it to the database and sends it to all connected clients of this pad |
42
|
|
|
* |
43
|
|
|
* @method Response createPad($padID, $text = null) creates a new (non-group) pad. Note that if you need to create a group Pad, you should call createGroupPad. |
44
|
|
|
* @method Response getRevisionsCount($padID) returns the number of revisions of this pad |
45
|
|
|
* @method Response getSavedRevisionsCount($padID) returns the number of saved revisions of this pad |
46
|
|
|
* @method Response listSavedRevisions($padID) returns a list of saved revisions of this pad |
47
|
|
|
* @method Response saveRevision($padID, $revision = null) save a revision of a pad |
48
|
|
|
* @method Response padUsersCount($padID) returns the number of user that are currently editing this pad |
49
|
|
|
* @method Response padUsers($padID) returns the list of users that are currently editing this pad |
50
|
|
|
* @method Response deletePad($padID) deletes a pad |
51
|
|
|
* @method Response movePad($sourceID, $destinationID, $force = false) moves a pad. If force is true and the destination pad exists, it will be overwritten. |
52
|
|
|
* @method Response copyPad($sourceID, $destinationID, $force = false) copies a pad with full history and chat. If force is true and the destination pad exists, it will be overwritten. |
53
|
|
|
* @method Response getReadOnlyID($padID) returns the read only link of a pad |
54
|
|
|
* @method Response getPadID($readOnlyID) returns the id of a pad which is assigned to the readOnlyID |
55
|
|
|
* @method Response setPublicStatus($padID, $publicStatus) sets a boolean for the public status of a pad |
56
|
|
|
* @method Response getPublicStatus($padID) return true of false |
57
|
|
|
* @method Response setPassword($padID, $password) returns ok or a error message |
58
|
|
|
* @method Response isPasswordProtected($padID) returns true or false |
59
|
|
|
* @method Response listAuthorsOfPad($padID) returns an array of authors who contributed to this pad |
60
|
|
|
* @method Response getLastEdited($padID) returns the timestamp of the last revision of the pad |
61
|
|
|
* @method Response sendClientsMessage($padID, $msg) sends a custom message of type $msg to the pad |
62
|
|
|
* @method Response checkToken() returns ok when the current api token is valid |
63
|
|
|
* |
64
|
|
|
* @method Response listAllPads() lists all pads on this epl instance |
65
|
|
|
* |
66
|
|
|
*/ |
67
|
|
|
class Client |
68
|
|
|
{ |
69
|
|
|
const API_VERSION = '1.2.13'; |
70
|
|
|
|
71
|
|
|
private $apikey = null; |
72
|
|
|
private $url = null; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param $apikey |
76
|
|
|
* @param string $url |
77
|
|
|
*/ |
78
|
4 |
|
public function __construct($apikey, $url = 'http://localhost:9001') |
79
|
|
|
{ |
80
|
4 |
|
$this->apikey = $apikey; |
81
|
4 |
|
$this->url = $url; |
82
|
4 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param $method |
86
|
|
|
* @param array $args |
87
|
|
|
* @return Response |
88
|
|
|
* @throws Exception\UnsupportedMethodException |
89
|
|
|
*/ |
90
|
3 |
|
public function __call($method, $args = array()) |
91
|
|
|
{ |
92
|
3 |
|
if (!in_array($method, array_keys(self::getMethods()))) { |
93
|
3 |
|
throw new UnsupportedMethodException(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$request = new Request($this->url, $this->apikey, $method, $args); |
97
|
|
|
return new Response($request->send()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Generates a random padID |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
1 |
|
public function generatePadID() |
106
|
|
|
{ |
107
|
1 |
|
$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
108
|
1 |
|
$length = 16; |
109
|
1 |
|
$padID = ""; |
110
|
|
|
|
111
|
1 |
|
for ($i = 0; $i < $length; $i++) { |
112
|
1 |
|
$padID .= $chars[rand()%strlen($chars)]; |
113
|
1 |
|
} |
114
|
|
|
|
115
|
1 |
|
return $padID; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Array that holds the available methods and their required parameter names |
120
|
|
|
* |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
38 |
|
public static function getMethods() |
124
|
|
|
{ |
125
|
|
|
return array( |
126
|
38 |
|
'createGroup' => array(), |
127
|
38 |
|
'createGroupIfNotExistsFor' => array('groupMapper'), |
128
|
38 |
|
'deleteGroup' => array('groupID'), |
129
|
38 |
|
'listPads' => array('groupID'), |
130
|
38 |
|
'createGroupPad' => array('groupID', 'padName', 'text'), |
131
|
38 |
|
'listAllGroups' => array(), |
132
|
38 |
|
'createAuthor' => array('name'), |
133
|
38 |
|
'createAuthorIfNotExistsFor' => array('authorMapper', 'name'), |
134
|
38 |
|
'listPadsOfAuthor' => array('authorID'), |
135
|
38 |
|
'getAuthorName' => array('authorID'), |
136
|
38 |
|
'createSession' => array('groupID', 'authorID', 'validUntil'), |
137
|
38 |
|
'deleteSession' => array('sessionID'), |
138
|
38 |
|
'getSessionInfo' => array('sessionID'), |
139
|
38 |
|
'listSessionsOfGroup' => array('groupID'), |
140
|
38 |
|
'listSessionsOfAuthor' => array('authorID'), |
141
|
38 |
|
'getText' => array('padID', 'rev'), |
142
|
38 |
|
'setText' => array('padID', 'text'), |
143
|
38 |
|
'getHTML' => array('padID', 'rev'), |
144
|
38 |
|
'setHTML' => array('padID', 'html'), |
145
|
38 |
|
'getAttributePool' => array('padID'), |
146
|
38 |
|
'createDiffHTML' => array('padID', 'startRev', 'endRev'), |
147
|
38 |
|
'restoreRevision' => array('padID', 'rev'), |
148
|
38 |
|
'getRevisionChangeset' => array('padID'), |
149
|
38 |
|
'getChatHistory' => array('padID', 'start', 'end'), |
150
|
38 |
|
'getChatHead' => array('padID'), |
151
|
38 |
|
'appendChatMessage' => array('padID', 'text', 'authorID'), |
152
|
38 |
|
'createPad' => array('padID', 'text'), |
153
|
38 |
|
'getRevisionsCount' => array('padID'), |
154
|
38 |
|
'getSavedRevisionsCount' => array('padID'), |
155
|
38 |
|
'listSavedRevisions' => array('padID'), |
156
|
38 |
|
'saveRevision' => array('padID'), |
157
|
38 |
|
'padUsersCount' => array('padID'), |
158
|
38 |
|
'padUsers' => array('padID'), |
159
|
38 |
|
'deletePad' => array('padID'), |
160
|
38 |
|
'movePad' => array('sourceID', 'destinationID'), |
161
|
38 |
|
'copyPad' => array('sourceID', 'destinationID'), |
162
|
38 |
|
'getReadOnlyID' => array('padID'), |
163
|
38 |
|
'getPadID' => array('readOnlyID'), |
164
|
38 |
|
'setPublicStatus' => array('padID', 'publicStatus'), |
165
|
38 |
|
'getPublicStatus' => array('padID'), |
166
|
38 |
|
'setPassword' => array('padID', 'password'), |
167
|
38 |
|
'isPasswordProtected' => array('padID'), |
168
|
38 |
|
'listAuthorsOfPad' => array('padID'), |
169
|
38 |
|
'getLastEdited' => array('padID'), |
170
|
38 |
|
'sendClientsMessage' => array('padID', 'msg'), |
171
|
38 |
|
'checkToken' => array(), |
172
|
38 |
|
'listAllPads' => array(), |
173
|
38 |
|
); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|