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 | * |
---|
55 | * This class provides theses public functions : |
---|
56 | * - getId |
---|
57 | * - getName |
---|
58 | * - getValue |
---|
59 | * - getLabel |
---|
60 | * - getNote |
---|
61 | * - isKnown |
---|
62 | * - isImplemented |
---|
63 | * - isTranslatable |
---|
64 | * - setId |
---|
65 | * - setName |
---|
66 | * - setValue |
---|
67 | * - setLabel |
---|
68 | * - setNote |
---|
69 | * - setKnown |
---|
70 | * - setImplemented |
---|
71 | * - setTranslatable |
---|
72 | * |
---|
73 | * ----------------------------------------------------------------------------- |
---|
74 | */ |
---|
75 | |
---|
76 | class Tag |
---|
77 | { |
---|
78 | private $tagId = 0; |
---|
79 | private $tagName = "unknown tag"; |
---|
80 | private $tagNote = ""; |
---|
81 | private $tagValue = 0; |
---|
82 | private $valueLabel = "not decoded"; |
---|
83 | private $tagIsKnown = false; |
---|
84 | private $tagIsImplemented = false; |
---|
85 | private $tagIsTranslatable = false; |
---|
86 | |
---|
87 | /** |
---|
88 | * All parameters for the Tag constructor are optional |
---|
89 | * |
---|
90 | * @param $tagId (optional) : the tag Id ; can be |
---|
91 | * Integer or String |
---|
92 | * @param $tagValue (optional) : the value of the tag ; can |
---|
93 | * be of any type |
---|
94 | * @param String $tagName (optional) : the 'human readable' name |
---|
95 | * for the tag |
---|
96 | * @param $valueLabel (optional) : the 'human readable' value |
---|
97 | * for the tag |
---|
98 | * @param String $tagNote (optional) : an optional information |
---|
99 | * about the tag |
---|
100 | * @param Boolean $tagIsKnown (optional) : determine if the tag is a |
---|
101 | * known tag or not |
---|
102 | * @param Boolean $tagIsImplemented (optional) : determine if the tag is an |
---|
103 | * implemented tag or not |
---|
104 | * @param Boolean $tagIstranslatable (optional) : determine if the tag value |
---|
105 | * can be translated or not |
---|
106 | * |
---|
107 | */ |
---|
108 | function __construct($tagId=0xffff, $tagValue=0, $tagName="", $valueLabel="", $tagNote="", $tagIsKnown=false, $tagIsImplemented=false, $tagIsTranslatable=false) |
---|
109 | { |
---|
110 | $this->tagId = $tagId; |
---|
111 | $this->tagValue = $tagValue; |
---|
112 | if($tagName!="") $this->tagName = $tagName; |
---|
113 | if($valueLabel!="") $this->valueLabel = $valueLabel; |
---|
114 | if($tagNote!="") $this->tagNote = $tagNote; |
---|
115 | $this->tagIsKnown=$tagIsKnown; |
---|
116 | $this->tagIsImplemented=$tagIsImplemented; |
---|
117 | $this->tagIsTranslatable=$tagIsTranslatable; |
---|
118 | } |
---|
119 | |
---|
120 | function __destruct() |
---|
121 | { |
---|
122 | unset($this->tagId); |
---|
123 | unset($this->tagName); |
---|
124 | unset($this->tagNote); |
---|
125 | unset($this->tagValue); |
---|
126 | unset($this->valueLabel); |
---|
127 | unset($this->tagIsKnown); |
---|
128 | unset($this->tagIsImplemented); |
---|
129 | unset($this->tagIsTranslatable); |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * returns the Tag Id |
---|
134 | * |
---|
135 | * @return Can be an integer (typically for exif and iptc tags) or a string |
---|
136 | * (typically for xmp tags) |
---|
137 | */ |
---|
138 | public function getId() |
---|
139 | { |
---|
140 | return($this->tagId); |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | * returns the 'human readable' tag name |
---|
145 | * |
---|
146 | * @return String |
---|
147 | */ |
---|
148 | public function getName() |
---|
149 | { |
---|
150 | return($this->tagName); |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * returns the value of the tag |
---|
155 | * |
---|
156 | * @return can be of any type |
---|
157 | */ |
---|
158 | public function getValue() |
---|
159 | { |
---|
160 | return($this->tagValue); |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * returns the 'human readable' value of the tag |
---|
165 | * |
---|
166 | * @return String, Array or DateTime object |
---|
167 | */ |
---|
168 | public function getLabel() |
---|
169 | { |
---|
170 | return($this->valueLabel); |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * returns true if the tag is a known tag |
---|
175 | * |
---|
176 | * @return Boolean |
---|
177 | */ |
---|
178 | public function isKnown() |
---|
179 | { |
---|
180 | return($this->tagIsKnown); |
---|
181 | } |
---|
182 | |
---|
183 | /** |
---|
184 | * returns true if the tag is implemented or not |
---|
185 | * |
---|
186 | * @return Boolean |
---|
187 | */ |
---|
188 | public function isImplemented() |
---|
189 | { |
---|
190 | return($this->tagIsImplemented); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * returns the note associated with the tag |
---|
195 | * |
---|
196 | * @return String |
---|
197 | */ |
---|
198 | public function getNote() |
---|
199 | { |
---|
200 | return($this->tagNote); |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * returns true if the tag value can be translated |
---|
205 | * |
---|
206 | * @return Boolean |
---|
207 | */ |
---|
208 | public function isTranslatable() |
---|
209 | { |
---|
210 | return($this->tagIsTranslatable); |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | * set the Id for the tag |
---|
215 | * |
---|
216 | * @param String or Integer $value : the tag Id |
---|
217 | * @return the tag Id |
---|
218 | */ |
---|
219 | public function setId($value) |
---|
220 | { |
---|
221 | $this->tagId=$value; |
---|
222 | return($this->tagId); |
---|
223 | } |
---|
224 | |
---|
225 | /** |
---|
226 | * set the name for the tag |
---|
227 | * |
---|
228 | * @param String $value : the tag name |
---|
229 | * @return String : the tag name |
---|
230 | */ |
---|
231 | public function setName($value) |
---|
232 | { |
---|
233 | $this->tagName=$value; |
---|
234 | return($this->tagName); |
---|
235 | } |
---|
236 | |
---|
237 | /** |
---|
238 | * set the value for the tag |
---|
239 | * |
---|
240 | * @param $value : can ba of any type |
---|
241 | * @return : the tag value |
---|
242 | */ |
---|
243 | public function setValue($value) |
---|
244 | { |
---|
245 | $this->tagValue=$value; |
---|
246 | return($this->tagValue); |
---|
247 | } |
---|
248 | |
---|
249 | /** |
---|
250 | * set the 'human readable value' for the tag |
---|
251 | * |
---|
252 | * @param String or Integer or DateTime $value : the tag value |
---|
253 | * @return : the tag label |
---|
254 | */ |
---|
255 | public function setLabel($value) |
---|
256 | { |
---|
257 | $this->valueLabel=$value; |
---|
258 | return($this->valueLabel); |
---|
259 | } |
---|
260 | |
---|
261 | /** |
---|
262 | * set if the tag is known |
---|
263 | * |
---|
264 | * @param Boolean $value |
---|
265 | * @return Boolean |
---|
266 | */ |
---|
267 | public function setKnown($value) |
---|
268 | { |
---|
269 | $this->tagIsKnown=($value===true)?true:false; |
---|
270 | return($this->tagIsKnown); |
---|
271 | } |
---|
272 | |
---|
273 | /** |
---|
274 | * set if the tag is implemented |
---|
275 | * |
---|
276 | * @param Boolean $value |
---|
277 | * @return Boolean |
---|
278 | */ |
---|
279 | public function setImplemented($value) |
---|
280 | { |
---|
281 | $this->tagIsImplemented=($value===true)?true:false; |
---|
282 | return($this->tagIsImplemented); |
---|
283 | } |
---|
284 | |
---|
285 | /** |
---|
286 | * set a note for the tag |
---|
287 | * |
---|
288 | * @param String $value |
---|
289 | * @return String |
---|
290 | */ |
---|
291 | public function setNote($value) |
---|
292 | { |
---|
293 | $this->tagNote=$value; |
---|
294 | return($this->tagNote); |
---|
295 | } |
---|
296 | |
---|
297 | /** |
---|
298 | * set if the tag value is translatable |
---|
299 | * |
---|
300 | * @param Boolean $value |
---|
301 | * @return Boolean |
---|
302 | */ |
---|
303 | public function setTranslatable($value) |
---|
304 | { |
---|
305 | $this->tagIsTranslatable=($value===true)?true:false; |
---|
306 | return($this->tagIsTranslatable); |
---|
307 | } |
---|
308 | |
---|
309 | public function toString($mode="all") |
---|
310 | { |
---|
311 | $returned=""; |
---|
312 | |
---|
313 | if($mode=="all") |
---|
314 | if(is_string($this->tagId)) |
---|
315 | $returned.="tag: ".str_replace(" ", " ", sprintf("%-34s", $this->tagId))." ; "; |
---|
316 | else |
---|
317 | $returned.="tag: 0x".sprintf("%04x", $this->tagId)." ; "; |
---|
318 | |
---|
319 | $returned.="name: ".str_replace(" ", " ", sprintf("%-34s", $this->tagName))." ; "; |
---|
320 | |
---|
321 | if($mode=="all") |
---|
322 | { |
---|
323 | if(is_array($this->tagValue)) |
---|
324 | $returned.=str_replace(" ", " ", sprintf("%-23s", "value: Array[".count($this->tagValue)."]"))."; "; |
---|
325 | elseif(is_string($this->tagValue)) |
---|
326 | { |
---|
327 | if(strlen($this->tagValue)>25) |
---|
328 | $returned.="value: ".str_replace(" ", " ", sprintf("%-25s", substr($this->tagValue,0,22)."..."))." ; "; |
---|
329 | else |
---|
330 | $returned.="value: ".str_replace(" ", " ", sprintf("%-25s", $this->tagValue))." ; "; |
---|
331 | |
---|
332 | } |
---|
333 | else |
---|
334 | $returned.="value: 0x".sprintf("%08x", $this->tagValue).str_replace(" ", " ", " ")." ; "; |
---|
335 | } |
---|
336 | |
---|
337 | $returned.="label: "; |
---|
338 | if(is_array($this->valueLabel)) |
---|
339 | { |
---|
340 | $returned.=print_r($this->valueLabel, true); |
---|
341 | } |
---|
342 | elseif(is_object($this->valueLabel)) |
---|
343 | { |
---|
344 | $returned.="Object[".get_class($this->valueLabel)."]"; |
---|
345 | if($this->valueLabel instanceof DateTime) |
---|
346 | { |
---|
347 | $returned.=$this->valueLabel->format('d/m/Y H:i:s'); |
---|
348 | } |
---|
349 | } |
---|
350 | else |
---|
351 | { |
---|
352 | $returned.=$this->valueLabel; |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | return($returned); |
---|
357 | } |
---|
358 | |
---|
359 | } |
---|
360 | |
---|
361 | ?> |
---|