ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Properties.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
11 {
13 
14  private $docProps;
15 
17  {
18  $this->securityScanner = $securityScanner;
19  $this->docProps = $docProps;
20  }
21 
22  private function extractPropertyData($propertyData)
23  {
24  return simplexml_load_string(
25  $this->securityScanner->scan($propertyData),
26  'SimpleXMLElement',
28  );
29  }
30 
31  public function readCoreProperties($propertyData): void
32  {
33  $xmlCore = $this->extractPropertyData($propertyData);
34 
35  if (is_object($xmlCore)) {
36  $xmlCore->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
37  $xmlCore->registerXPathNamespace('dcterms', 'http://purl.org/dc/terms/');
38  $xmlCore->registerXPathNamespace('cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
39 
40  $this->docProps->setCreator((string) self::getArrayItem($xmlCore->xpath('dc:creator')));
41  $this->docProps->setLastModifiedBy((string) self::getArrayItem($xmlCore->xpath('cp:lastModifiedBy')));
42  $created = (string) self::getArrayItem($xmlCore->xpath('dcterms:created'));
43  $this->docProps->setCreated($created);
44  $modified = (string) self::getArrayItem($xmlCore->xpath('dcterms:modified'));
45  $this->docProps->setModified($modified);
46  $this->docProps->setTitle((string) self::getArrayItem($xmlCore->xpath('dc:title')));
47  $this->docProps->setDescription((string) self::getArrayItem($xmlCore->xpath('dc:description')));
48  $this->docProps->setSubject((string) self::getArrayItem($xmlCore->xpath('dc:subject')));
49  $this->docProps->setKeywords((string) self::getArrayItem($xmlCore->xpath('cp:keywords')));
50  $this->docProps->setCategory((string) self::getArrayItem($xmlCore->xpath('cp:category')));
51  }
52  }
53 
54  public function readExtendedProperties($propertyData): void
55  {
56  $xmlCore = $this->extractPropertyData($propertyData);
57 
58  if (is_object($xmlCore)) {
59  if (isset($xmlCore->Company)) {
60  $this->docProps->setCompany((string) $xmlCore->Company);
61  }
62  if (isset($xmlCore->Manager)) {
63  $this->docProps->setManager((string) $xmlCore->Manager);
64  }
65  }
66  }
67 
68  public function readCustomProperties($propertyData): void
69  {
70  $xmlCore = $this->extractPropertyData($propertyData);
71 
72  if (is_object($xmlCore)) {
73  foreach ($xmlCore as $xmlProperty) {
75  $cellDataOfficeAttributes = $xmlProperty->attributes();
76  if (isset($cellDataOfficeAttributes['name'])) {
77  $propertyName = (string) $cellDataOfficeAttributes['name'];
78  $cellDataOfficeChildren = $xmlProperty->children('http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
79 
80  $attributeType = $cellDataOfficeChildren->getName();
81  $attributeValue = (string) $cellDataOfficeChildren->{$attributeType};
82  $attributeValue = DocumentProperties::convertProperty($attributeValue, $attributeType);
83  $attributeType = DocumentProperties::convertPropertyType($attributeType);
84  $this->docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
85  }
86  }
87  }
88  }
89 
90  private static function getArrayItem(array $array, $key = 0)
91  {
92  return $array[$key] ?? null;
93  }
94 }
static getArrayItem(array $array, $key=0)
Definition: Properties.php:90
static getLibXmlLoaderOptions()
Get default options for libxml loader.
Definition: Settings.php:116
__construct(XmlScanner $securityScanner, DocumentProperties $docProps)
Definition: Properties.php:16
$key
Definition: croninfo.php:18