-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathAdobeConnectClient.class.php
More file actions
479 lines (414 loc) · 9.42 KB
/
AdobeConnectClient.class.php
File metadata and controls
479 lines (414 loc) · 9.42 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<?php
/*
* AdobeConnect 9 api client
* @see https://github.com/sc0rp10/AdobeConnect-php-api-client
* @see http://help.adobe.com/en_US/connect/9.0/webservices/index.html
* @version 0.1a
*
* Copyright 2012, sc0rp10
* https://weblab.pro
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*
*/
/**
* Class AdobeConnectClient
*/
class AdobeConnectClient {
const PERMISSION_VIEW = 'view';
const PERMISSION_HOST = 'host';
protected $curl;
protected $is_authorized = false;
protected $breezecookie = null;
protected $login;
protected $password;
protected $root_folder;
protected $template_folder;
protected $host;
/**
* @param $host
* @param $login
* @param $password
* @param $root_folder
* @param $template_folder
*/
public function __construct ($host, $login, $password, $root_folder = null, $template_folder = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$this->curl = $ch;
$this->login = $login;
$this->password = $password;
$this->root_folder = $root_folder;
$this->template_folder = $template_folder;
$this->host = $host;
}
/**
*
* @param null $login
* @param null $password
*
* @return AdobeConnectClient
*/
public function makeAuth ($login = null, $password = null) {
$this->login = $login ?: $this->login;
$this->password = $password ?: $this->password;
$result = null;
if (!$this->breezecookie) {
try {
$this->makeRequest('login', [
'login' => $this->login,
'password' => $this->password
]);
} catch (Exception $e) {
$e = new Exception(sprintf('Cannot auth with credentials: [%s:%s@%s]', $this->login, $this->password, $this->host), 0, $e);
$e->setHost($this->host);
$e->setLogin($this->login);
$e->setPassword($this->password);
throw $e;
}
};
$this->is_authorized = true;
return $this;
}
/**
* get common info about current user
*
* @return array
*/
public function getCommonInfo () {
return $this->makeRequest('common-info');
}
/**
* create user
*
* @param string $email
* @param string $password
* @param string $name
* @param string $type
*
* @return array
*/
public function createUser ($email, $password, $name, $type = 'user') {
$result = $this->makeRequest('principal-update', [
'name' => $name,
'email' => $email,
'password' => $password,
'type' => $type,
'has-children' => 0,
]);
return $result['principal']['@attributes']['principal-id'];
}
/**
* @return null
*/
public function getBreezeCookie () {
return $this->breezecookie;
}
/**
* @param string $email
* @param bool $only_id
*
* @return mixed
*
* @throws Exception
*
*/
public function getUserByEmail ($email, $only_id = false) {
$result = $this->makeRequest('principal-list', [
'filter-email' => $email
]);
if (empty($result['principal-list'])) {
throw new Exception(sprintf('Cannot find user [%s]', $email));
}
if ($only_id) {
return $result['principal-list']['principal']['@attributes']['principal-id'];
}
return $result;
}
/**
* update user fields
*
* @param string $email
* @param array $data
*
* @return mixed
*/
public function updateUser ($email, array $data = []) {
$principal_id = $this->getUserByEmail($email, true);
$data['principal-id'] = $principal_id;
return $this->makeRequest('principal-update', $data);
}
/**
* get all users list
*
* @return array
*/
public function getUsersList () {
$users = $this->makeRequest('principal-list');
$result = [];
foreach ($users['principal-list']['principal'] as $key => $value) {
$result[$key] = $value['@attributes'] + $value;
};
return $result;
}
/**
* get all meetings
*
* @return array
*/
public function getAllMeetings () {
return $this->makeRequest('report-my-meetings');
}
/**
* get shortcuts
*
* @return array
*/
public function getShortcuts () {
return $this->makeRequest('sco-shortcuts')['shortcuts']['sco'];
}
/**
* get shortcuts
*
* @param $sco_id
*
* @return array
*/
public function getScoInfo ($sco_id) {
return $this->makeRequest('sco-info', ['sco-id' => $sco_id]);
}
/**
* create meeting-folder
*
* @param string $name
* @param string $url
*
* @return array
*/
public function createFolder ($name, $url) {
$result = $this->makeRequest('sco-update', [
'type' => 'folder',
'name' => $name,
'folder-id' => $this->root_folder,
'depth' => 1,
'url-path' => $url
]);
return $result['sco']['@attributes']['sco-id'];
}
/**
*
* @return mixed
*/
public function getTemplates () {
return $this->makeRequest('sco-contents', [
'sco-id' => $this->template_folder
])['scos']['sco'];
}
/**
* create meeting
*
* @param int $folder_id
* @param string $name
* @param DateTime $date_begin
* @param DateTime $date_end
* @param string $url
* @param null $template_sco_id
*
* @return int
*/
public function createMeeting (
$folder_id,
$name,
DateTime $date_begin,
DateTime $date_end,
$url,
$template_sco_id = null
) {
$data = [
'type' => 'meeting',
'name' => $name,
'folder-id' => $folder_id,
'date-begin' => $date_begin->format(\DateTime::ISO8601),
'date-end' => $date_end->format(DateTime::ISO8601),
'url-path' => $url
];
if ($template_sco_id) {
$data['source-sco-id'] = $template_sco_id;
}
$result = $this->makeRequest('sco-update', $data);
return $result['sco']['@attributes']['sco-id'];
}
/**
* get info about meeting
* @param $meeting_id
*
* @return array
*/
public function getMeetingInfo ($meeting_id) {
$result = $this->makeRequest('sco-info', [
'sco-id' => $meeting_id
]);
return $result['sco'];
}
/**
* get meeting archives
*
* @param int $meeting_id
* @param DateTime $from
* @param DateTime $to
*
* @return array
*/
public function getMeetingArchive (
$meeting_id,
DateTime $from = null,
DateTime $to = null
) {
$request = [
'sco-id' => $meeting_id,
'filter-icon' => 'archive'
];
if ($from) {
$request['filter-gte-date-end'] = $from->format(DateTime::ISO8601);
}
if ($to) {
$request['filter-lt-date-end'] = $to->format(DateTime::ISO8601);
}
return $this->makeRequest('sco-contents', $request);
}
/**
* @return mixed
*/
public function getTemplateFolder () {
return $this->template_folder;
}
/**
* @return mixed
*/
public function getRootFolder () {
return $this->root_folder;
}
/**
* @return mixed
*/
public function getHost () {
return $this->host;
}
/**
* @param $principal_id
* @param $group_id
* @return mixed
*/
public function addUserToGroup ($principal_id, $group_id) {
return $this->makeRequest('group-membership-update', [
'group-id' => $group_id,
'principal-id' => $principal_id,
'is-member' => true,
]);
}
/**
* @param $principal_id
* @param $group_id
* @return mixed
*/
public function removeUserFromGroup ($principal_id, $group_id) {
return $this->makeRequest('group-membership-update', [
'group-id' => $group_id,
'principal-id' => $principal_id,
'is-member' => false,
]);
}
/**
* invite user to meeting
*
* @param int $meeting_id
* @param string $email
*
* @param string $permission
* @return mixed
*/
public function inviteUserToMeeting ($meeting_id, $email, $permission = self::PERMISSION_VIEW) {
$user_id = $this->getUserByEmail($email, true);
$result = $this->makeRequest('permissions-update', [
'principal-id' => $user_id,
'acl-id' => $meeting_id,
'permission-id' => $permission,
]);
return $result;
}
/**
* invite user to meeting
*
* @param int $meeting_id
* @param $group_id
* @param string $permission
*
* @return mixed
*/
public function inviteGroupToMeeting (
$meeting_id,
$group_id,
$permission = self::PERMISSION_VIEW
) {
$result = $this->makeRequest('permissions-update', [
'principal-id' => $group_id,
'acl-id' => $meeting_id,
'permission-id' => $permission
]);
return $result;
}
/**
*
*/
public function __destruct () {
curl_close($this->curl);
}
/**
* @param $action
* @param array $params
* @return mixed
* @throws Exception
* @throws Exception
*/
protected function makeRequest ($action, array $params = []) {
if ($this->breezecookie) {
$params['session'] = $this->breezecookie;
};
$url = $this->host;
$url .= 'api/xml?action=' . $action;
$url .= '&' . http_build_query($params);
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_HEADER, 1);
$response = curl_exec($this->curl);
if ($response === false) {
throw new Exception('Coulnd\'t perform the action: ' . $action . ' with [empty result]; ' . $url);
}
preg_match('/BREEZESESSION=(\w+);/', $response, $m);
if (isset($m[1])) {
$this->breezecookie = $m[1];
}
$temp = explode("\r\n\r\n", $response);
$result = '';
if (isset($temp[1])) {
$result = $temp[1];
}
libxml_use_internal_errors();
$xml = simplexml_load_string($result);
$errors = libxml_get_errors();
$json = json_encode($xml);
$data = json_decode($json, true);
if (
count($errors) > 0
||
!isset($data['status']['@attributes']['code'])
||
$data['status']['@attributes']['code'] !== 'ok'
) {
throw new Exception('Coulnd\'t perform the action: ' . $action . ' with [ ' . var_export(trim($response), true) . ' ]; ' . $url);
};
return $data;
}
}