|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kitodo\Dlf\Domain\Model; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
9
|
|
|
* |
|
10
|
|
|
* @license GNU General Public License version 3 or later. |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
class AnnotationTarget |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $url; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $objectId; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $id; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $rangeParameterName; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $rangeValue; |
|
41
|
|
|
|
|
42
|
|
|
public function __construct($url) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->url = $url; |
|
45
|
|
|
|
|
46
|
|
|
$path = parse_url($url, PHP_URL_PATH); |
|
47
|
|
|
$fragment = parse_url($url, PHP_URL_FRAGMENT); |
|
48
|
|
|
list($objectId, $id) = explode('/', trim($path, '/')); |
|
49
|
|
|
list($rangeParameterName, $rangeValue) = explode('=', $fragment); |
|
50
|
|
|
|
|
51
|
|
|
$this->objectId = $objectId; |
|
52
|
|
|
$this->id = $id; |
|
53
|
|
|
$this->rangeParameterName = $rangeParameterName; |
|
54
|
|
|
$this->rangeValue = preg_replace('/\s+/', '', $rangeValue); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getUrl(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->url; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getObjectId() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->objectId; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getId() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->id; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getRangeParameterName() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->rangeParameterName; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getRangeValue() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->rangeValue; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return bool |
|
99
|
|
|
*/ |
|
100
|
|
|
public function isValid() |
|
101
|
|
|
{ |
|
102
|
|
|
if (empty($this->getObjectId())) { |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
if (parse_url($this->getUrl(), PHP_URL_FRAGMENT)) { |
|
107
|
|
|
return !empty($this->getId()) && $this->isValidRange(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return true; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return bool |
|
115
|
|
|
*/ |
|
116
|
|
|
public function isValidRange() |
|
117
|
|
|
{ |
|
118
|
|
|
if (empty($this->rangeParameterName) && empty($this->rangeValue)) { |
|
119
|
|
|
return true; |
|
120
|
|
|
} elseif ($this->isFacsimileRange()) { |
|
121
|
|
|
return preg_match("/^(\d+)(,\d+){3}?$/", $this->rangeValue) === 1; |
|
122
|
|
|
} elseif ($this->isAudioRange()) { |
|
123
|
|
|
return preg_match("/^(?:\d+(?:\.\d*)?|\.\d+){0,1}(?:,(?:\d+(?:\.\d*)?|\.\d+))*$/", $this->rangeValue) === 1; |
|
124
|
|
|
} elseif ($this->isScoreRange()) { |
|
125
|
|
|
return preg_match("/^((\d+|start|end|all|(\d+|start)(-(\d+|end)){0,1})+)(,(\d+|start|end|all|(\d+|start)(-(\d+|end)){0,1})+){0,}?$/", $this->rangeValue) === 1; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return bool |
|
133
|
|
|
*/ |
|
134
|
|
|
public function isScoreRange() |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->getRangeParameterName() === 'measureRanges'; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return bool |
|
141
|
|
|
*/ |
|
142
|
|
|
public function isAudioRange() |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->getRangeParameterName() === 't'; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @return bool |
|
149
|
|
|
*/ |
|
150
|
|
|
public function isFacsimileRange() |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->getRangeParameterName() === 'xywh'; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|