1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the kaloa/xmp package. |
5
|
|
|
* |
6
|
|
|
* For full copyright and license information, please view the LICENSE file |
7
|
|
|
* that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Kaloa\Xmp; |
11
|
|
|
|
12
|
|
|
use DOMDocument; |
13
|
|
|
use DOMXPath; |
14
|
|
|
|
15
|
|
|
use Kaloa\Xmp\Properties\DublinCoreProperties; |
16
|
|
|
use Kaloa\Xmp\Properties\ExifProperties; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Provides a read-only interface to an Extensible Metadata Platform (XMP) |
20
|
|
|
* document. |
21
|
|
|
* |
22
|
|
|
* XMP data can be embedded within a variety of media file formats. For |
23
|
|
|
* instance, many image editors use XMP to add metadata to image files. This |
24
|
|
|
* class was originally written to retrieve data from digital photos. |
25
|
|
|
* |
26
|
|
|
* Usage example: |
27
|
|
|
* |
28
|
|
|
* <pre> |
29
|
|
|
* use Kaloa\Xmp\Reader; |
30
|
|
|
* |
31
|
|
|
* $stream = fopen('/path/to/image.jpg', 'rb'); |
32
|
|
|
* $reader = new Reader(); |
33
|
|
|
* $xmpDocument = $reader->getXmpDocument($stream); |
34
|
|
|
* fclose($stream); |
35
|
|
|
* $dcProps = $xmpDocument->getDublinCoreProperties(); |
36
|
|
|
* |
37
|
|
|
* printf("Image title(s): %s\n", implode(', ', $dcProps->getTitle())); |
38
|
|
|
* printf("Image tags: %s\n", implode(', ', $dcProps->getSubject())); |
39
|
|
|
* </pre> |
40
|
|
|
*/ |
41
|
|
|
class Document |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* Original XMP XML data. |
45
|
|
|
* |
46
|
|
|
* @var DOMDocument $dom |
47
|
|
|
*/ |
48
|
|
|
private $dom; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* DublinCore schema properties found in the XMP document. |
52
|
|
|
* |
53
|
|
|
* @var DublinCoreProperties |
54
|
|
|
*/ |
55
|
|
|
private $dublinCoreProperties; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Exif schema properties found in the XMP document. |
59
|
|
|
* |
60
|
|
|
* @var ExifProperties |
61
|
|
|
*/ |
62
|
|
|
private $exifProperties; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Initializes the instance. |
66
|
|
|
* |
67
|
|
|
* @param DOMDocument $dom XMP document |
68
|
|
|
*/ |
69
|
1 |
|
public function __construct(DOMDocument $dom) |
70
|
|
|
{ |
71
|
1 |
|
$this->dom = $dom; |
72
|
|
|
|
73
|
1 |
|
$xPath = new DOMXPath($dom); |
74
|
|
|
|
75
|
1 |
|
$xPath->registerNamespace( |
76
|
1 |
|
'dc', |
77
|
|
|
'http://purl.org/dc/elements/1.1/' |
78
|
1 |
|
); |
79
|
1 |
|
$xPath->registerNamespace( |
80
|
1 |
|
'rdf', |
81
|
|
|
'http://www.w3.org/1999/02/22-rdf-syntax-ns#' |
82
|
1 |
|
); |
83
|
1 |
|
$xPath->registerNamespace( |
84
|
1 |
|
'exif', |
85
|
|
|
'http://ns.adobe.com/exif/1.0/' |
86
|
1 |
|
); |
87
|
|
|
|
88
|
1 |
|
$this->dublinCoreProperties = new DublinCoreProperties($xPath); |
89
|
1 |
|
$this->exifProperties = new ExifProperties($xPath); |
90
|
1 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Returns Dublin Core (DC) schema properties found in the document. |
94
|
|
|
* |
95
|
|
|
* @return DublinCoreProperties |
96
|
|
|
*/ |
97
|
1 |
|
public function getDublinCoreProperties() |
98
|
|
|
{ |
99
|
1 |
|
return $this->dublinCoreProperties; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Returns EXIF schema properties found in the document. |
104
|
|
|
* |
105
|
|
|
* @return ExifProperties |
106
|
|
|
*/ |
107
|
1 |
|
public function getExifProperties() |
108
|
|
|
{ |
109
|
1 |
|
return $this->exifProperties; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|