KT_cmis_atom_server.inc.php
5.79 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
<?php
include_once(KT_ATOM_LIB_FOLDER . 'KT_atom_server.inc.php');
require_once(CMIS_API . '/ktRepositoryService.inc.php');
class KT_cmis_atom_server extends KT_atom_server {
// override and extend as needed
public $repositoryInfo;
public $headersSet = false;
protected function hook_beforeDocRender($doc)
{
if ($doc->isContentDownload())
{
// not going to create a feed/entry response, just returning the raw data
$this->output = $doc->getOutput();
// generic headers for all content downloads
header('Cache-Control: must-revalidate');
// these two are to override the default header values
header('Expires:');
header('Pragma:');
// prevent output of standard text/xml header
$this->headersSet = true;
return false;
}
else if ($doc->notModified())
{
// prevent output of standard text/xml header
$this->headersSet = true;
$this->setNoContent(true);
return false;
}
return true;
}
public function initServiceDocument()
{
$queryArray = split('/', trim($_SERVER['QUERY_STRING'], '/'));
$workspace = strtolower(trim($queryArray[0]));
if ($workspace == 'servicedocument')
{
$RepositoryService = new KTRepositoryService();
// fetch data for response
$repositories = $RepositoryService->getRepositories();
// hack for removing one level of access
$repositories = $repositories['results'];
// fetch for default first repo; NOTE that this will probably have to change at some point, quick and dirty for now
// hack for removing one level of access
$repositoryInfo = $RepositoryService->getRepositoryInfo($repositories[0]['repositoryId']);
$this->repositoryInfo = $repositoryInfo['results'];
}
}
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('cmisra: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'], $instance['accept'], $ws);
}
}
}
// ob_start();
// readfile('C:\Users\Paul\Documents\Downloads\cmis_mod_kt.xml');
// $this->output = ob_get_contents();
// ob_end_clean();
$this->output = $service->getAPPdoc();
}
public function registerService($workspace = NULL, $serviceName = NULL, $serviceClass = NULL, $title = NULL,
$serviceParameters = NULL, $collectionType = NULL, $accept = null)
{
$workspace = strtolower(trim($workspace));
$serviceName = strtolower(trim($serviceName));
$serviceRecord = array(
'fileName' => $fileName,
'serviceClass' => $serviceClass,
'title' => $title,
'parameters' => $serviceParameters,
'collectionType' => $collectionType,
'accept' => $accept
);
$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;
}
public function render()
{
ob_end_clean();
if (!$this->headersSet) {
header('Content-type: text/xml');
}
if ($this->renderBody) {
echo $this->output;
}
}
}
?>