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 integer $revision |
34
|
|
|
*/ |
35
|
|
|
public function __construct($revision = 0) |
36
|
|
|
{ |
37
|
|
|
$this->revision = $revision; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function buildCoreXML() |
44
|
|
|
{ |
45
|
|
|
$coreXml = ''; |
46
|
|
|
$coreXml .= $this->xml; |
47
|
|
|
$coreXml .= $this->getCoreProperties(); |
48
|
|
|
|
49
|
|
|
return $coreXml; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
private function getCoreProperties() |
56
|
|
|
{ |
57
|
|
|
$properties = '<cp:coreProperties xmlns:cp="'.$this->urlCp.'" xmlns:dc="'. |
58
|
|
|
$this->urlDc.'" xmlns:dcmitype="'.$this->urlDcType.'" xmlns:dcterms="'. |
59
|
|
|
$this->urlDcTerms.'" xmlns:xsi="'.$this->urlSchema.'">'; |
60
|
|
|
$properties .= $this->created(); |
61
|
|
|
$properties .= $this->creator(); |
62
|
|
|
$properties .= $this->revision(); |
63
|
|
|
$properties .= '</cp:coreProperties>'; |
64
|
|
|
|
65
|
|
|
return $properties; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* CreatedDate ex: '2016-08-30T15:52:19.00Z'; |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
private function created() |
73
|
|
|
{ |
74
|
|
|
return '<dcterms:created xsi:type="dcterms:W3CDTF">'.date("Y-m-d\TH:i:s.00\Z").'</dcterms:created>'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
private function creator() |
81
|
|
|
{ |
82
|
|
|
return '<dc:creator>'.str_replace("'", "'", htmlspecialchars($this->author)).'</dc:creator>'; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
private function revision() |
89
|
|
|
{ |
90
|
|
|
return '<cp:revision>'.$this->revision.'</cp:revision>'; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $author |
95
|
|
|
* |
96
|
|
|
* @return $this |
97
|
|
|
*/ |
98
|
|
|
public function setAuthor($author) |
99
|
|
|
{ |
100
|
|
|
if (!empty($author)) { |
101
|
|
|
$this->author = $author; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|