forked from alxp/islandora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectionHelper.inc
75 lines (66 loc) · 2.11 KB
/
ConnectionHelper.inc
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
<?php
// $Id$
/*
* Created on Jan 24, 2008
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
module_load_include('inc', 'ConnectionHelper', '');
class ConnectionHelper {
function ConnectionHelper() {
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
}
function _fixURL($url, $_name, $_pass) {
if (empty($url)) {
$url=variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl');
}
$creds = urlencode($_name) . ':'. urlencode($_pass);
if (strpos($url, 'http://') === 0) {
$new_url = 'http://'. $creds . '@'. substr($url, 7);
}
elseif (strpos($url, 'https://') === 0) {
$new_url = 'https://'. $creds . '@'. substr($url, 8);
}
else {
drupal_set_message(t('Invalid URL: !url', array('!url' => $url)));
return NULL;
}
return $new_url;
}
function getSoapClient($url = NULL, $exceptions = TRUE) {
if (empty($url)) {
$url=variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl');
}
global $user;
if ($user->uid == 0) {
//anonymous user. We will need an entry in the fedora users.xml file
//with the appropriate entry for a username of anonymous password of anonymous
try {
$client = new SoapClient($this->_fixURL($url, 'anonymous', 'anonymous'), array(
'login' => 'anonymous',
'password' => 'anonymous',
'exceptions' => $exceptions,
));
}
catch (SoapFault $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage())));
return NULL;
}
}
else {
try {
$client = new SoapClient($this->_fixURL($url, $user->name, $user->pass), array(
'login' => $user->name,
'password' => $user->pass,
'exceptions' => TRUE,
));
}
catch (SoapFault $e) {
drupal_set_message(t("!e", array('!e' => $e->getMessage())));
return NULL;
}
}
return $client;
}
}