1 | <?php |
---|
2 | /* |
---|
3 | * --:: Exif Maker Notes Analyzer ::-------------------------------------------- |
---|
4 | * |
---|
5 | * Author : Grum |
---|
6 | * email : grum at piwigo.org |
---|
7 | * website : http://photos.grum.fr |
---|
8 | * |
---|
9 | * << May the Little SpaceFrog be with you ! >> |
---|
10 | * |
---|
11 | * |
---|
12 | * +-----------------------------------------------------------------------+ |
---|
13 | * | JpegMetaData - a PHP based Jpeg Metadata manager | |
---|
14 | * +-----------------------------------------------------------------------+ |
---|
15 | * | Copyright(C) 2010 Grum - http://www.grum.fr | |
---|
16 | * +-----------------------------------------------------------------------+ |
---|
17 | * | This program is free software; you can redistribute it and/or modify | |
---|
18 | * | it under the terms of the GNU General Public License as published by | |
---|
19 | * | the Free Software Foundation | |
---|
20 | * | | |
---|
21 | * | This program is distributed in the hope that it will be useful, but | |
---|
22 | * | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
23 | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
24 | * | General Public License for more details. | |
---|
25 | * | | |
---|
26 | * | You should have received a copy of the GNU General Public License | |
---|
27 | * | along with this program; if not, write to the Free Software | |
---|
28 | * | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
29 | * | USA. | |
---|
30 | * +-----------------------------------------------------------------------+ |
---|
31 | * |
---|
32 | * |
---|
33 | * ----------------------------------------------------------------------------- |
---|
34 | * |
---|
35 | * The Tag class is used to manage properties of a tag (all type of tags : exif, |
---|
36 | * xmp and iptc) |
---|
37 | * |
---|
38 | * A tag have different properties : |
---|
39 | * |
---|
40 | * - tagId : the tag id (typically, an integer for Exif & IPTC, a |
---|
41 | * string for XMP) |
---|
42 | * - tagName : a 'human readable' name for the tag, in most case it's |
---|
43 | * the official name defined in specifications |
---|
44 | * - tagNote : free to set note about a tag |
---|
45 | * - tagValue : the 'raw' value of the tag, not interpreted ; can be |
---|
46 | * of any type |
---|
47 | * - valueLabel : the interpreted value of the tag ; in most case it's a |
---|
48 | * String, but can be an Integer, a Float or an Array |
---|
49 | * - tagIsKnown : indicates if the tag is a known tag or not |
---|
50 | * - tagIsImplemented : indicates if the interpretation of the tag is |
---|
51 | * implemented or not |
---|
52 | * - tagIsTranslatable : indicates if the interpreted value for the tag is |
---|
53 | * translatable |
---|
54 | * - schema : the schema associated with the tag ('exif', 'iptc', 'xmp', 'magic') |
---|
55 | * |
---|
56 | * This class provides theses public functions : |
---|
57 | * - getId |
---|
58 | * - getName |
---|
59 | * - getValue |
---|
60 | * - getLabel |
---|
61 | * - getNote |
---|
62 | * - getSchema |
---|
63 | * - isKnown |
---|
64 | * - isImplemented |
---|
65 | * - isTranslatable |
---|
66 | * - setId |
---|
67 | * - setName |
---|
68 | * - setValue |
---|
69 | * - setLabel |
---|
70 | * - setNote |
---|
71 | * - setSchema |
---|
72 | * - setKnown |
---|
73 | * - setImplemented |
---|
74 | * - setTranslatable |
---|
75 | * |
---|
76 | * ----------------------------------------------------------------------------- |
---|
77 | */ |
---|
78 | |
---|
79 | class Tag |
---|
80 | { |
---|
81 | private $tagId = 0; |
---|
82 | private $tagName = "unknown tag"; |
---|
83 | private $tagNote = ""; |
---|
84 | private $tagValue = 0; |
---|
85 | private $valueLabel = "not decoded"; |
---|
86 | private $tagIsKnown = false; |
---|
87 | private $tagIsImplemented = false; |
---|
88 | private $tagIsTranslatable = false; |
---|
89 | private $tagSchema = ""; |
---|
90 | |
---|
91 | /** |
---|
92 | * All parameters for the Tag constructor are optional |
---|
93 | * |
---|
94 | * @param $tagId (optional) : the tag Id ; can be |
---|
95 | * Integer or String |
---|
96 | * @param $tagValue (optional) : the value of the tag ; can |
---|
97 | * be of any type |
---|
98 | * @param String $tagName (optional) : the 'human readable' name |
---|
99 | * for the tag |
---|
100 | * @param $valueLabel (optional) : the 'human readable' value |
---|
101 | * for the tag |
---|
102 | * @param String $tagNote (optional) : an optional information |
---|
103 | * about the tag |
---|
104 | * @param Boolean $tagIsKnown (optional) : determine if the tag is a |
---|
105 | * known tag or not |
---|
106 | * @param Boolean $tagIsImplemented (optional) : determine if the tag is an |
---|
107 | * implemented tag or not |
---|
108 | * @param Boolean $tagIstranslatable (optional) : determine if the tag value |
---|
109 | * can be translated or not |
---|
110 | * @param String $schema (optional) : schema associated with to |
---|
111 | * the tag |
---|
112 | */ |
---|
113 | function __construct($tagId=0xffff, $tagValue=0, $tagName="", $valueLabel="", $tagNote="", $tagIsKnown=false, $tagIsImplemented=false, $tagIsTranslatable=false, $schema="") |
---|
114 | { |
---|
115 | $this->tagId = $tagId; |
---|
116 | $this->tagValue = $tagValue; |
---|
117 | if($tagName!="") $this->tagName = $tagName; |
---|
118 | if($valueLabel!="") $this->valueLabel = $valueLabel; |
---|
119 | if($tagNote!="") $this->tagNote = $tagNote; |
---|
120 | $this->tagIsKnown=$tagIsKnown; |
---|
121 | $this->tagIsImplemented=$tagIsImplemented; |
---|
122 | $this->tagIsTranslatable=$tagIsTranslatable; |
---|
123 | $this->tagSchema = $schema; |
---|
124 | } |
---|
125 | |
---|
126 | function __destruct() |
---|
127 | { |
---|
128 | unset($this->tagId); |
---|
129 | unset($this->tagName); |
---|
130 | unset($this->tagNote); |
---|
131 | unset($this->tagValue); |
---|
132 | unset($this->valueLabel); |
---|
133 | unset($this->tagIsKnown); |
---|
134 | unset($this->tagIsImplemented); |
---|
135 | unset($this->tagIsTranslatable); |
---|
136 | unset($this->tagSchema); |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * returns the Tag Id |
---|
141 | * |
---|
142 | * @return Can be an integer (typically for exif and iptc tags) or a string |
---|
143 | * (typically for xmp tags) |
---|
144 | */ |
---|
145 | public function getId() |
---|
146 | { |
---|
147 | return($this->tagId); |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * returns the 'human readable' tag name |
---|
152 | * |
---|
153 | * @return String |
---|
154 | */ |
---|
155 | public function getName() |
---|
156 | { |
---|
157 | return($this->tagName); |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * returns the value of the tag |
---|
162 | * |
---|
163 | * @return can be of any type |
---|
164 | */ |
---|
165 | public function getValue() |
---|
166 | { |
---|
167 | return($this->tagValue); |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | * returns the 'human readable' value of the tag |
---|
172 | * |
---|
173 | * @return String, Array or DateTime object |
---|
174 | */ |
---|
175 | public function getLabel() |
---|
176 | { |
---|
177 | return($this->valueLabel); |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * returns true if the tag is a known tag |
---|
182 | * |
---|
183 | * @return Boolean |
---|
184 | */ |
---|
185 | public function isKnown() |
---|
186 | { |
---|
187 | return($this->tagIsKnown); |
---|
188 | } |
---|
189 | |
---|
190 | /** |
---|
191 | * returns true if the tag is implemented or not |
---|
192 | * |
---|
193 | * @return Boolean |
---|
194 | */ |
---|
195 | public function isImplemented() |
---|
196 | { |
---|
197 | return($this->tagIsImplemented); |
---|
198 | } |
---|
199 | |
---|
200 | /** |
---|
201 | * returns the note associated with the tag |
---|
202 | * |
---|
203 | * @return String |
---|
204 | */ |
---|
205 | public function getNote() |
---|
206 | { |
---|
207 | return($this->tagNote); |
---|
208 | } |
---|
209 | |
---|
210 | /** |
---|
211 | * returns the schema associated to the tag |
---|
212 | * |
---|
213 | * @return String |
---|
214 | */ |
---|
215 | public function getSchema() |
---|
216 | { |
---|
217 | return($this->tagSchema); |
---|
218 | } |
---|
219 | |
---|
220 | /** |
---|
221 | * returns true if the tag value can be translated |
---|
222 | * |
---|
223 | * @return Boolean |
---|
224 | */ |
---|
225 | public function isTranslatable() |
---|
226 | { |
---|
227 | return($this->tagIsTranslatable); |
---|
228 | } |
---|
229 | |
---|
230 | /** |
---|
231 | * set the Id for the tag |
---|
232 | * |
---|
233 | * @param String or Integer $value : the tag Id |
---|
234 | * @return the tag Id |
---|
235 | */ |
---|
236 | public function setId($value) |
---|
237 | { |
---|
238 | $this->tagId=$value; |
---|
239 | return($this->tagId); |
---|
240 | } |
---|
241 | |
---|
242 | /** |
---|
243 | * set the name for the tag |
---|
244 | * |
---|
245 | * @param String $value : the tag name |
---|
246 | * @return String : the tag name |
---|
247 | */ |
---|
248 | public function setName($value) |
---|
249 | { |
---|
250 | $this->tagName=$value; |
---|
251 | return($this->tagName); |
---|
252 | } |
---|
253 | |
---|
254 | /** |
---|
255 | * set the value for the tag |
---|
256 | * |
---|
257 | * @param $value : can ba of any type |
---|
258 | * @return : the tag value |
---|
259 | */ |
---|
260 | public function setValue($value) |
---|
261 | { |
---|
262 | $this->tagValue=$value; |
---|
263 | return($this->tagValue); |
---|
264 | } |
---|
265 | |
---|
266 | /** |
---|
267 | * set the 'human readable value' for the tag |
---|
268 | * |
---|
269 | * @param String or Integer or DateTime $value : the tag value |
---|
270 | * @return : the tag label |
---|
271 | */ |
---|
272 | public function setLabel($value) |
---|
273 | { |
---|
274 | $this->valueLabel=$value; |
---|
275 | return($this->valueLabel); |
---|
276 | } |
---|
277 | |
---|
278 | /** |
---|
279 | * set if the tag is known |
---|
280 | * |
---|
281 | * @param Boolean $value |
---|
282 | * @return Boolean |
---|
283 | */ |
---|
284 | public function setKnown($value) |
---|
285 | { |
---|
286 | $this->tagIsKnown=($value===true)?true:false; |
---|
287 | return($this->tagIsKnown); |
---|
288 | } |
---|
289 | |
---|
290 | /** |
---|
291 | * set if the tag is implemented |
---|
292 | * |
---|
293 | * @param Boolean $value |
---|
294 | * @return Boolean |
---|
295 | */ |
---|
296 | public function setImplemented($value) |
---|
297 | { |
---|
298 | $this->tagIsImplemented=($value===true)?true:false; |
---|
299 | return($this->tagIsImplemented); |
---|
300 | } |
---|
301 | |
---|
302 | /** |
---|
303 | * set a note for the tag |
---|
304 | * |
---|
305 | * @param String $value |
---|
306 | * @return String |
---|
307 | */ |
---|
308 | public function setNote($value) |
---|
309 | { |
---|
310 | $this->tagNote=$value; |
---|
311 | return($this->tagNote); |
---|
312 | } |
---|
313 | |
---|
314 | /** |
---|
315 | * set a schema to the tag |
---|
316 | * |
---|
317 | * @param String $value |
---|
318 | * @return String |
---|
319 | */ |
---|
320 | public function setSchema($value) |
---|
321 | { |
---|
322 | $this->tagSchema=$value; |
---|
323 | return($this->tagSchema); |
---|
324 | } |
---|
325 | |
---|
326 | |
---|
327 | /** |
---|
328 | * set if the tag value is translatable |
---|
329 | * |
---|
330 | * @param Boolean $value |
---|
331 | * @return Boolean |
---|
332 | */ |
---|
333 | public function setTranslatable($value) |
---|
334 | { |
---|
335 | $this->tagIsTranslatable=($value===true)?true:false; |
---|
336 | return($this->tagIsTranslatable); |
---|
337 | } |
---|
338 | |
---|
339 | public function toString($mode="all") |
---|
340 | { |
---|
341 | $returned=""; |
---|
342 | |
---|
343 | if($mode=="all") |
---|
344 | if(is_string($this->tagId)) |
---|
345 | $returned.="tag: ".str_replace(" ", " ", sprintf("%-34s", $this->tagId))." ; |
---|
346 | schema: ".str_replace(" ", " ", sprintf("%-5s", $this->tagSchema))." ; "; |
---|
347 | else |
---|
348 | $returned.="tag: 0x".sprintf("%04x", $this->tagId)." ; "; |
---|
349 | |
---|
350 | $returned.="name: ".str_replace(" ", " ", sprintf("%-34s", $this->tagName))." ; "; |
---|
351 | |
---|
352 | if($mode=="all") |
---|
353 | { |
---|
354 | if(is_array($this->tagValue)) |
---|
355 | $returned.=str_replace(" ", " ", sprintf("%-23s", "value: Array[".count($this->tagValue)."]"))."; "; |
---|
356 | elseif(is_string($this->tagValue)) |
---|
357 | { |
---|
358 | if(strlen($this->tagValue)>25) |
---|
359 | $returned.="value: ".str_replace(" ", " ", sprintf("%-25s", substr($this->tagValue,0,22)."..."))." ; "; |
---|
360 | else |
---|
361 | $returned.="value: ".str_replace(" ", " ", sprintf("%-25s", $this->tagValue))." ; "; |
---|
362 | |
---|
363 | } |
---|
364 | else |
---|
365 | $returned.="value: 0x".sprintf("%08x", $this->tagValue).str_replace(" ", " ", " ")." ; "; |
---|
366 | } |
---|
367 | |
---|
368 | $returned.="label: "; |
---|
369 | if(is_array($this->valueLabel)) |
---|
370 | { |
---|
371 | $returned.=print_r($this->valueLabel, true); |
---|
372 | } |
---|
373 | elseif(is_object($this->valueLabel)) |
---|
374 | { |
---|
375 | $returned.="Object[".get_class($this->valueLabel)."]"; |
---|
376 | if($this->valueLabel instanceof DateTime) |
---|
377 | { |
---|
378 | $returned.=$this->valueLabel->format('d/m/Y H:i:s'); |
---|
379 | } |
---|
380 | } |
---|
381 | else |
---|
382 | { |
---|
383 | $returned.=$this->valueLabel; |
---|
384 | } |
---|
385 | |
---|
386 | |
---|
387 | return($returned); |
---|
388 | } |
---|
389 | |
---|
390 | } |
---|
391 | |
---|
392 | ?> |
---|