14 protected $document = null;
15 protected $exportProfil =
false;
17 protected $exportFiles =
false;
18 protected $exportDocumentNumericIdentiers =
false;
19 protected $attributeToExport = array();
20 protected $includeSchemaReference =
false;
23 protected $verifyAttributeAccess =
true;
24 protected $writeToFile =
false;
31 $this->verifyAttributeAccess = $verifyAttributeAccess;
38 $this->structureAttributes = $structureAttributes;
45 $this->attributeToExport = $attributeToExport;
52 $this->exportDocumentNumericIdentiers = $exportDocumentNumericIdentiers;
59 $this->exportFiles = $exportFiles;
66 $this->includeSchemaReference = $includeSchemaReference;
73 $this->document = $document;
78 if ($this->exportFiles) {
81 return $this->export();
86 $this->export($filePath);
92 $lay->set(
"famname", strtolower($this->document->fromname));
93 $lay->set(
"id", ($this->exportDocumentNumericIdentiers ? $this->document->id :
''));
94 if ($this->document->locked != - 1) {
95 $lay->set(
"name", $this->document->name);
97 $lay->set(
"name",
"");
99 $lay->set(
"revision", $this->document->revision);
100 $lay->set(
"version", $this->document->getVersion());
101 $lay->set(
"state", $this->document->getState());
102 $lay->set(
"title", htmlspecialchars($this->document->getTitle() , ENT_QUOTES));
103 $lay->set(
"mdate", strftime(
"%FT%H:%M:%S", $this->document->revdate));
104 $lay->set(
"flat", (!$this->includeSchemaReference || !$this->structureAttributes));
105 $la = $this->document->GetFieldAttributes();
108 foreach (
$la as $k => $v) {
109 if ((!$v) || ($v->getOption(
"autotitle") ==
"yes") || ($v->usefor ==
'Q')) unset(
$la[$k]);
111 $option = new \exportOptionAttribute();
114 foreach (
$la as $k => & $v) {
115 if (($v->id != \Adoc::HIDDENFIELD) && ($v->type ==
'frame' || $v->type ==
"tab") && ((!$v->fieldSet) || $v->fieldSet->id == \Adoc::HIDDENFIELD)) {
118 "level" => $this->getStructXmlValue($v)
122 $lay->setBlockData(
"top", $level1);
125 $this->writeToFile =
true;
126 if ($this->exportFiles) {
127 $xmlcontent = $lay->gen();
133 $pos = strpos($xmlcontent,
"[FILE64");
136 while ($pos !==
false) {
137 if (fwrite($fo, substr($xmlcontent, $bpos, $pos - $bpos))) {
138 $bpos = strpos($xmlcontent,
"]", $pos) + 1;
140 $filepath = substr($xmlcontent, $pos + 8, ($bpos - $pos - 9));
145 $ff = fopen($filepath,
"r");
146 $size = 6 * 1024 * 57;
147 while ($buf = fread($ff,
$size)) {
148 fwrite($fo, base64_encode($buf));
150 $pos = strpos($xmlcontent,
"[FILE64", $bpos);
155 fwrite($fo, substr($xmlcontent, $bpos));
158 if (file_put_contents(
$outfile, $lay->gen()) ===
false) {
164 $this->writeToFile =
false;
179 $doc = $this->document;
180 if ($this->verifyAttributeAccess && !VerifyAttributeAccess::isAttributeAccessGranted($this->document, $attribute)) {
181 return sprintf(
"<%s granted=\"false\"/>", $attribute->id);
184 if ($indexValue > - 1) $v =
$doc->getMultipleRawValues($attribute->id, null, $indexValue);
185 else $v =
$doc->getRawValue($attribute->id, null);
187 if ($attribute->
getOption(
"autotitle") ==
"yes") {
188 return sprintf(
"<!--autotitle %s %s -->", $attribute->id, $v);
190 if (($v === null) && ($attribute->type !=
'array')) {
191 if (($attribute->type ==
'file') || ($attribute->type ==
'image'))
return sprintf(
'<%s mime="" title="" xsi:nil="true"/>', $attribute->id);
192 else return sprintf(
'<%s xsi:nil="true"/>', $attribute->id);
194 switch ($attribute->type) {
198 return sprintf(
"<%s>%s</%s>", $attribute->id, $v, $attribute->id);
201 $xmlvalues = array();
202 $av =
$doc->getArrayRawValues($attribute->id);
204 foreach ($av as $k => $col) {
205 $xmlvalues = array();
206 foreach ($col as $aid => $aval) {
207 $oa =
$doc->getAttribute($aid);
208 if (empty($this->attributeToExport[
$doc->fromid]) || in_array($aid, $this->attributeToExport[
$doc->fromid])) {
210 $xmlvalues[] = $this->getAttributeXmlValue($oa, $indexValue);
213 $axml[] = sprintf(
"<%s>%s</%s>", $attribute->id, implode(
"\n", $xmlvalues) , $attribute->id);
216 return implode(
"\n", $axml);
221 if ($this->exportDocumentNumericIdentiers) {
227 $name = htmlspecialchars($reg[3], ENT_QUOTES);
229 $href = $base . str_replace(
'&',
'&',
$doc->getFileLink($attribute->id));
230 if ($this->exportFiles) {
231 $path =
$doc->vault_filename_fromvalue($v,
true);
233 if (is_file(
$path)) {
234 if ($this->writeToFile) {
235 return sprintf(
'<%s vid="%s" mime="%s" title="%s">[FILE64:%s]</%s>', $attribute->id, $vid, $mime, $name,
$path, $attribute->id);
237 return sprintf(
'<%s vid="%s" mime="%s" title="%s">%s</%s>', $attribute->id, $vid, $mime, $name, base64_encode(file_get_contents(
$path)) , $attribute->id);
240 return sprintf(
'<!-- file not found --><%s vid="%s" mime="%s" title="%s"/>', $attribute->id, $vid, $mime, $name, $attribute->id);
243 return sprintf(
'<%s vid="%s" mime="%s" href="%s" title="%s"/>', $attribute->id, $vid, $mime, $href, $name);
246 return sprintf(
"<%s>%s</%s>", $attribute->id, $v, $attribute->id);
252 return sprintf(
'<%s xsi:nil="true"/>', $attribute->id);
265 $docRevOption = $attribute->
getOption(
"docrev",
"latest");
266 $latestTitle = ($docRevOption ===
"latest");
271 if (
$info[
"locked"] == - 1) {
274 } elseif ($docRevOption ===
"fixed") {
275 $revAttr = sprintf(
' revision="%d" ',
$info[
"revision"]);
276 } elseif (preg_match(
'/^state\(([^\)]+)\)/', $docRevOption, $matches)) {
277 $revAttr = sprintf(
' revision="state:%s" ', htmlspecialchars($matches[1], ENT_QUOTES));
281 $info[
"name"] = htmlspecialchars(
$info[
"name"], ENT_QUOTES);
283 if ($this->exportDocumentNumericIdentiers) {
284 return sprintf(
'<%s id="%s" name="%s"%s>%s</%s>', $attribute->id,
$docid,
$info[
"name"], $revAttr, $attribute->
encodeXml(
$info[
"title"]) , $attribute->id);
287 addWarningMsg(sprintf(_(
"Doc %s : Attribut \"%s\" reference revised identifier : importation not support revision links without identifiers") ,
$doc->getTitle() , $attribute->
getLabel()));
289 return sprintf(
'<%s name="%s"%s>%s</%s>', $attribute->id,
$info[
"name"], $revAttr, $attribute->
encodeXml(
$info[
"title"]) , $attribute->id);
292 if ($this->exportDocumentNumericIdentiers) {
293 return sprintf(
'<%s id="%s"%s>%s</%s>', $attribute->id,
$docid, $revAttr, $attribute->
encodeXml(
$info[
"title"]) , $attribute->id);
296 return sprintf(
'<%s>%s</%s>', $attribute->id, $attribute->
encodeXml(
$info[
"title"]) , $attribute->id);
300 if ((strpos($v,
'<BR>') ===
false) && (strpos($v,
"\n") ===
false)) {
301 return sprintf(
'<%s id="%s">%s</%s>', $attribute->id, $v, _(
"unreferenced document") , $attribute->id);
304 $tids = explode(
"\n", str_replace(
'<BR>',
"\n", $v));
308 foreach ($tids as $id) {
312 if ($lName) $foundName =
true;
315 if ($this->exportDocumentNumericIdentiers) {
316 $sIds = sprintf(
'id="%s"', implode(
',', $mId));
321 $sName = sprintf(
'name="%s"', implode(
',', $mName));
323 return sprintf(
'<%s %s %s>%s</%s>', $attribute->id, $sName, $sIds, _(
"multiple document") , $attribute->id);
328 return sprintf(
"<%s>%s</%s>", $attribute->id, $attribute->
encodeXml($v) , $attribute->id);
334 if ($attribute->isNormal ===
true) {
338 return $this->getAttributeXmlValue($attribute, $indexValue);
343 return $this->getStructXmlValue($attribute, $indexValue);
354 protected function getStructXmlValue(\
FieldSetAttribute $structAttribute, $indexValue = - 1)
356 $doc = $this->document;
358 $xmlvalues = array();
359 foreach (
$la as $k => $v) {
363 if ($v->fieldSet && $v->fieldSet->id == $structAttribute->id && (empty($this->attributeToExport[
$doc->fromid]) || in_array($v->id, $this->attributeToExport[
$doc->fromid]))) {
364 $value = $this->getXmlValue($v, $indexValue);
365 if ($v->type ==
"htmltext" && $this->exportFiles) {
367 if ($this->exportFiles) {
368 $value = preg_replace_callback(
'/(<img.*?)src="(((?=.*docid=(.*?)&)(?=.*attrid=(.*?)&)(?=.*index=(-?[0-9]+)))|(file\/(.*?)\/[0-9]+\/(.*?)\/(-?[0-9]+))).*?"/',
function ($matches)
370 if (isset($matches[7])) {
372 $attrid = $matches[9];
373 $index = $matches[10] ==
"-1" ? 0 : $matches[10];
376 $index = $matches[6] ==
"-1" ? 0 : $matches[6];
377 $attrid = $matches[5];
380 $attr = $docimg->getAttribute($attrid);
381 $tfiles = $docimg->vault_properties($attr);
382 $f = $tfiles[$index];
383 $f[
"name"] = htmlspecialchars($f[
"name"], ENT_QUOTES);
384 if (is_file($f[
"path"])) {
385 if ($this->writeToFile) {
386 return sprintf(
'%s title="%s" src="data:%s;base64,[FILE64:%s]"',
"\n" . $matches[1],
unaccent($f[
"name"]) , $f[
"mime_s"], $f[
"path"]);
388 return sprintf(
'%s title="%s" src="data:%s;base64,%s"',
"\n" . $matches[1],
unaccent($f[
"name"]) , $f[
"mime_s"], base64_encode(file_get_contents($f[
"path"])));
391 return sprintf(
'%s title="%s" src="data:%s;base64,file not found"',
"\n" . $matches[1],
unaccent($f[
"name"]) , $f[
"mime_s"]);
400 if (!$this->structureAttributes)
return implode(
"\n", $xmlvalues);
401 else return sprintf(
"<%s>%s</%s>", $structAttribute->id, implode(
"\n", $xmlvalues) , $structAttribute->id);
static encodeXml($s, $quot=false)
setIncludeSchemaReference($includeSchemaReference)
setExportDocumentNumericIdentiers($exportDocumentNumericIdentiers)
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
stringDateToIso($date, $format=false, $withT=false)
Exception class use exceptionCode to identifiy correctly exception.
getAttributeXmlValue(\NormalAttribute $attribute, $indexValue)
setExportFiles($exportFiles)
setVerifyAttributeAccess($verifyAttributeAccess)
getLayoutFile($app, $layfile)
getParam($name, $def="")
must be in core or global type
setAttributeToExport($attributeToExport)
new_Doc($dbaccess, $id= '', $latest=false)
getNameFromId($dbaccess, $id)
setStructureAttributes($structureAttributes)