|
1
|
|
|
<?php |
|
2
|
|
|
namespace Ellumilel\DocProps; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @link https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#Document_properties |
|
6
|
|
|
* |
|
7
|
|
|
* Class Core |
|
8
|
|
|
* @package Ellumilel\DocProps |
|
9
|
|
|
* @author Denis Tikhonov <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class Core |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
private $author = 'Unknown Author'; |
|
15
|
|
|
/** @var int */ |
|
16
|
|
|
private $revision = 0; |
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
private $urlCp = 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties'; |
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
private $urlDc = 'http://purl.org/dc/elements/1.1/'; |
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $urlDcType = 'http://purl.org/dc/dcmitype/'; |
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private $urlDcTerms = 'http://purl.org/dc/terms/'; |
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
private $urlSchema = 'http://www.w3.org/2001/XMLSchema-instance'; |
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
private $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Core constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $author |
|
34
|
|
|
* @param integer $revision |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct($author = '', $revision = 0) |
|
37
|
|
|
{ |
|
38
|
|
|
if (!empty($author)) { |
|
39
|
|
|
$this->author = $author; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->revision = $revision; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
|
|
public function buildCoreXML() |
|
49
|
|
|
{ |
|
50
|
|
|
$coreXml = ''; |
|
51
|
|
|
$coreXml .= $this->xml; |
|
52
|
|
|
$coreXml .= $this->getCoreProperties(); |
|
53
|
|
|
|
|
54
|
|
|
return $coreXml; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
private function getCoreProperties() |
|
61
|
|
|
{ |
|
62
|
|
|
$properties = '<cp:coreProperties xmlns:cp="'.$this->urlCp.'" xmlns:dc="'. |
|
63
|
|
|
$this->urlDc.'" xmlns:dcmitype="'.$this->urlDcType.'" xmlns:dcterms="'. |
|
64
|
|
|
$this->urlDcTerms.'" xmlns:xsi="'.$this->urlSchema.'">'; |
|
65
|
|
|
$properties .= $this->created(); |
|
66
|
|
|
$properties .= $this->creator(); |
|
67
|
|
|
$properties .= $this->revision(); |
|
68
|
|
|
$properties .= '</cp:coreProperties>'; |
|
69
|
|
|
|
|
70
|
|
|
return $properties; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* CreatedDate ex: '2016-08-30T15:52:19.00Z'; |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
private function created() |
|
78
|
|
|
{ |
|
79
|
|
|
return '<dcterms:created xsi:type="dcterms:W3CDTF">'.date("Y-m-d\TH:i:s.00\Z").'</dcterms:created>'; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
private function creator() |
|
86
|
|
|
{ |
|
87
|
|
|
return '<dc:creator>'.str_replace("'", "'", htmlspecialchars($this->author)).'</dc:creator>'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
private function revision() |
|
94
|
|
|
{ |
|
95
|
|
|
return '<cp:revision>'.$this->revision.'</cp:revision>'; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|