-
Notifications
You must be signed in to change notification settings - Fork 26
/
connect_class_dom.php
153 lines (113 loc) · 4.35 KB
/
connect_class_dom.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
<?php
/**
* @package mod
* @subpackage adobeconnect
* @author Akinsaya Delamarre ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('connect_class.php');
class connect_class_dom extends connect_class {
public function __construct($serverurl = '', $serverport = '',
$username = '', $password = '',
$cookie = '', $https) {
parent::__construct($serverurl, $serverport, $username, $password, $cookie, $https);
}
public function create_request($params = array(), $sentrequest = true) {
if (empty($params)) {
return false;
}
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement('params');
$dom->appendChild($root);
foreach($params as $key => $data) {
$datahtmlent = htmlentities($data);
$child = $dom->createElement('param', $datahtmlent);
$root->appendChild($child);
$attribute = $dom->createAttribute('name');
$child->appendChild($attribute);
$text = $dom->createTextNode($key);
$attribute->appendChild($text);
}
$this->_xmlrequest = $dom->saveXML();
if ($sentrequest) {
$this->_xmlresponse = $this->send_request();
}
}
/**
* Parses through xml and looks for the 'cookie' parameter
* @param string $xml the xml to parse through
* @return string $sessoin returns the session id
*/
public function read_cookie_xml($xml = '') {
global $USER, $COURSE, $CFG;
if (empty($xml)) {
if (is_siteadmin($USER->id)) {
notice(get_string('adminemptyxml', 'adobeconnect'),
$CFG->wwwroot . '/admin/settings.php?section=modsettingadobeconnect');
} else {
notice(get_string('emptyxml', 'adobeconnect'),
'', $COURSE);
}
}
$dom = new DomDocument();
$dom->loadXML($xml);
$domnodelist = $dom->getElementsByTagName('cookie');
if (isset($domnodelist->item(0)->nodeValue)) {
$this->_cookie = $domnodelist->item(0)->nodeValue;
} else {
$this->_cookie = null;
}
}
public function call_success() {
global $USER, $COURSE, $CFG;
if (empty($this->_xmlresponse)) {
if (is_siteadmin($USER->id)) {
notice(get_string('adminemptyxml', 'adobeconnect'),
$CFG->wwwroot . '/admin/settings.php?section=modsettingadobeconnect');
} else {
notice(get_string('emptyxml', 'adobeconnect'),
'', $COURSE);
}
}
$dom = new DomDocument();
$dom->loadXML($this->_xmlresponse);
$domnodelist = $dom->getElementsByTagName('status');
if ($domnodelist->item(0)->hasAttributes()) {
$domnode = $domnodelist->item(0)->attributes->getNamedItem('code');
if (!is_null($domnode)) {
if (0 == strcmp('ok', $domnode->nodeValue)) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
/**
* Sends the HTTP header login request and returns the response xml
* @param string username username to use for header x-user-id
*/
public function request_http_header_login($return_header = 0, $username = '', $stop = false) {
global $CFG;
$header = array();
$this->create_http_head_login_xml();
// The first parameter is 1 because we want to include the response header
// to extract the session cookie
if (!empty($username)) {
$header = array("$CFG->adobeconnect_admin_httpauth: " . $username);
}
$this->_xmlresponse = $this->send_request($return_header, $header, $stop);
$this->set_session_cookie($this->_xmlresponse);
return $this->_xmlresponse;
}
private function create_http_head_login_xml() {
$params = array('action' => 'login',
'external-auth' => 'use',
);
$this->create_request($params, false);
}
}