depage-xmldb v2.3.1
XML documents in a relational database
Loading...
Searching...
No Matches
Base.php
Go to the documentation of this file.
1<?php
2
4
6
15class Base implements DoctypeInterface
16{
17 // list of elements that may created by a user
18 protected $availableNodes = [];
19
20 // list of valid parents given by nodename
21 protected $validParents = [
22 '*' => [
23 '*',
24 ],
25 ];
26
27 // list of names of nodes not to be affected by whitespace stripping
28 protected $preserveWhitespace = [];
29
30 protected $xmlDb;
31 protected $document;
32
37 public function __construct($xmlDb, $document)
38 {
39 $this->xmlDb = $xmlDb;
40 $this->document = $document;
41 }
42
49 public function getPermissions()
50 {
51 return (object) [
52 'validParents' => $this->getValidParents(),
53 'availableNodes' => $this->getAvailableNodes(),
54 ];
55 }
56
63 public function getValidParents()
64 {
66 }
67
73 public function getAvailableNodes()
74 {
76 }
77
84 public function getPreserveWhitespace()
85 {
87 }
88
101 public function getNewNodeFor($name)
102 {
103 $result = false;
104
105 if (isset($this->availableNodes[$name])) {
106 $nodeInfo = $this->availableNodes[$name];
107 $docInfo = $this->document->getNamespacesAndEntities();
108
109 if (isset($nodeInfo->xmlTemplateData)) {
110 $xml = $nodeInfo->xmlTemplateData;
111 } else {
112 $xml = "<$name {$docInfo->namespaces}";
113 if (!empty($nodeInfo->newName)) {
114 $xml .= " name=\"" . htmlspecialchars($nodeInfo->newName) . "\"";
115 }
116 if (isset($nodeInfo->attributes)) {
117 foreach ($nodeInfo->attributes as $attr => $value) {
118 $xml .= " $attr=\"" . htmlspecialchars($value) . "\"";
119 }
120 }
121 $xml .= '/>';
122 }
123 $doc = new \DOMDocument();
124 $doc->loadXML("<root xmlns:pg=\"http://cms.depagecms.net/ns/page\" xmlns:sec=\"http://cms.depagecms.net/ns/section\" xmlns:edit=\"http://cms.depagecms.net/ns/edit\">$xml</root>");
125
126 $result = $doc->documentElement->childNodes;
127 }
128
129 return $result;
130 }
131
140 public function isAllowedIn($nodeName, $targetNodeName)
141 {
142 $result = false;
143
144 if (isset($this->validParents['*'])) {
145 $result = in_array('*', $this->validParents['*']) || in_array($targetNodeName, $this->validParents['*']);
146 } elseif (isset($this->validParents[$nodeName])) {
147 $result = in_array('*', $this->validParents[$nodeName]) || in_array($targetNodeName, $this->validParents[$nodeName]);
148 }
149
150 return $result;
151 }
152
161 public function isAllowedAdd($node, $targetId)
162 {
163 return $this->isAllowedIn(
164 $node->nodeName,
165 $this->document->getNodeNameById($targetId)
166 );
167 }
168
177 public function isAllowedCopy($nodeId, $targetId)
178 {
179 return $this->isAllowedMove($nodeId, $targetId);
180 }
181
190 public function isAllowedMove($nodeId, $targetId)
191 {
192 return $this->isAllowedIn(
193 $this->document->getNodeNameById($nodeId),
194 $this->document->getNodeNameById($targetId)
195 );
196 }
197
205 public function isAllowedDelete($nodeId)
206 {
207 return true;
208 }
209
215 public function onDocumentChange()
216 {
217 return true;
218 }
219
231 public function onAddNode(\DomNode $node, $targetId, $targetIndex, $extras)
232 {
233 return true;
234 }
235
244 public function onCopyNode($nodeId, $copyId)
245 {
246 return true;
247 }
248
257 public function onMoveNode($nodeId, $oldParentId)
258 {
259 return true;
260 }
261
270 public function onDeleteNode($nodeId, $parentId)
271 {
272 return true;
273 }
274
285 public function onSetAttribute($nodeId, $attrName, $oldVal, $newVal)
286 {
287 return true;
288 }
289
295 public function onHistorySave()
296 {
297 return true;
298 }
299
307 public function testDocument($xml)
308 {
309 return false;
310 }
311
320 public function testDocumentForHistory($xml)
321 {
322 return false;
323 }
324}
Default doctype handler of a document.
Definition Base.php:16
isAllowedDelete($nodeId)
checks whether a node may be deleted
Definition Base.php:205
__construct($xmlDb, $document)
Definition Base.php:37
getPreserveWhitespace()
gets the names of the nodes whose whitespace is not stripped while the document is saved
Definition Base.php:84
getNewNodeFor($name)
builds the node that is created by Document\addNodeByName()
Definition Base.php:101
onCopyNode($nodeId, $copyId)
called when a node is copied
Definition Base.php:244
getValidParents()
gets the names of the nodes a node may be placed in, indexed by the name of the node
Definition Base.php:63
isAllowedCopy($nodeId, $targetId)
checks whether a node may be copied to a target node
Definition Base.php:177
testDocumentForHistory($xml)
called when a version of the document is written to the history; the document may be changed here
Definition Base.php:320
testDocument($xml)
called when a document is read; the document may be changed here
Definition Base.php:307
getAvailableNodes()
gets the nodes that may be created by name, indexed by their name
Definition Base.php:73
onHistorySave()
called when a version of the document is written to the history
Definition Base.php:295
isAllowedMove($nodeId, $targetId)
checks whether a node may be moved to a target node
Definition Base.php:190
getPermissions()
gets the rules of the document
Definition Base.php:49
onMoveNode($nodeId, $oldParentId)
called when a node is moved
Definition Base.php:257
onAddNode(\DomNode $node, $targetId, $targetIndex, $extras)
called when a node is added to the document
Definition Base.php:231
onSetAttribute($nodeId, $attrName, $oldVal, $newVal)
called when an attribute of a node is changed
Definition Base.php:285
onDocumentChange()
called after the document has been changed and committed
Definition Base.php:215
isAllowedIn($nodeName, $targetNodeName)
checks whether a node may be placed in another node
Definition Base.php:140
isAllowedAdd($node, $targetId)
checks whether a node may be added to a target node
Definition Base.php:161
onDeleteNode($nodeId, $parentId)
called when a node is deleted
Definition Base.php:270
Interface of the doctype handler of a document.