KT_cmis_atom_server.inc.php
4.82 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
<?php
include_once(KT_ATOM_LIB_FOLDER . 'KT_atom_server.inc.php');
include_once('RepositoryService.inc.php');
class KT_cmis_atom_server extends KT_atom_server {
// override and extend as needed
public $repositoryInfo;
public function initServiceDocument()
{
$queryArray = split('/', trim($_SERVER['QUERY_STRING'], '/'));
$workspace = strtolower(trim($queryArray[0]));
if ($workspace == 'servicedocument')
{
include 'services/cmis/RepositoryService.inc.php';
$RepositoryService = new RepositoryService();
// fetch data for response
$repositories = $RepositoryService->getRepositories();
// fetch for default first repo; NOTE that this will probably have to change at some point, quick and dirty for now
$this->repositoryInfo = $RepositoryService->getRepositoryInfo($repositories[0]['repositoryId']);
}
}
public function serviceDocument()
{
$service = new KT_cmis_atom_serviceDoc(KT_APP_BASE_URI);
foreach($this->services as $workspace => $collection)
{
//Creating the Default Workspace for use with standard atomPub Clients
$ws = $service->newWorkspace();
$hadDetail=false;
if(isset($this->workspaceDetail[$workspace]))
{
if(is_array($this->workspaceDetail[$workspace]))
{
foreach ($this->workspaceDetail[$workspace] as $wsTag=>$wsValue)
{
$ws->appendChild($service->newElement($wsTag,$wsValue));
$hadDetail=true;
}
}
}
if(!$hadDetail) {
$ws->appendChild($service->newElement('atom:title',$workspace));
}
$ws->appendChild($service->newAttr('cmis:repositoryRelationship', $this->repositoryInfo['repositoryRelationship']));
// repository information
$element = $service->newElement('cmis:repositoryInfo');
foreach($this->repositoryInfo as $key => $repoData)
{
if ($key == 'rootFolderId')
{
$repoData = CMIS_APP_BASE_URI . $workspace . '/folder/' . rawurlencode($repoData);
}
if (!is_array($repoData))
{
$element->appendChild($service->newElement('cmis:' . $key, $repoData));
}
else
{
$elementSub = $service->newElement('cmis:' . $key);
foreach($repoData as $key2 => $data)
{
$elementSub->appendChild($service->newElement('cmis:' . $key2, CMISUtil::boolToString($data)));
}
$element->appendChild($elementSub);
}
}
$ws->appendChild($element);
foreach($collection as $serviceName => $serviceInstance)
{
foreach($serviceInstance as $instance)
{
$collectionStr = CMIS_APP_BASE_URI . $workspace . '/' . $serviceName . '/'
. (is_array($instance['parameters']) ? implode('/', $instance['parameters']).'/' : '');
$col = $service->newCollection($collectionStr, $instance['title'], $instance['collectionType'], $ws);
}
}
}
$this->output = $service->getAPPdoc();
}
public function registerService($workspace = NULL, $serviceName = NULL, $serviceClass = NULL, $title = NULL,
$serviceParameters = NULL, $collectionType = NULL)
{
$workspace = strtolower(trim($workspace));
$serviceName = strtolower(trim($serviceName));
$serviceRecord = array(
'fileName' => $fileName,
'serviceClass' => $serviceClass,
'title' => $title,
'parameters' => $serviceParameters,
'collectionType' => $collectionType
);
$this->services[$workspace][$serviceName][] = $serviceRecord;
}
public function getRegisteredService($workspace, $serviceName = NULL)
{
$serviceName = strtolower(trim($serviceName));
if(isset($this->services[$workspace][$serviceName]))
{
return $this->services[$workspace][$serviceName][0];
}
return false;
}
// TODO we probably want this version in the base class for auth purposes
public function render()
{
ob_end_clean();
// possible additional headers, e.g. basic auth request
// FIXME this won't work with the service document as no service object exists
if (!is_null($this->serviceObject))
{
$headers = $this->serviceObject->getHeaders();
foreach ($headers as $header)
{
header($header);
}
}
header('Content-type: text/xml');
echo $this->output;
}
}
?>