1 | <?php |
---|
2 | /* |
---|
3 | * --:: JPEG MetaDatas ::------------------------------------------------------- |
---|
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 | * | JpegMetaData - a PHP based Jpeg Metadata manager | |
---|
13 | * +-----------------------------------------------------------------------+ |
---|
14 | * | Copyright(C) 2010 Grum - http://www.grum.fr | |
---|
15 | * +-----------------------------------------------------------------------+ |
---|
16 | * | This program is free software; you can redistribute it and/or modify | |
---|
17 | * | it under the terms of the GNU General Public License as published by | |
---|
18 | * | the Free Software Foundation | |
---|
19 | * | | |
---|
20 | * | This program is distributed in the hope that it will be useful, but | |
---|
21 | * | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
22 | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
23 | * | General Public License for more details. | |
---|
24 | * | | |
---|
25 | * | You should have received a copy of the GNU General Public License | |
---|
26 | * | along with this program; if not, write to the Free Software | |
---|
27 | * | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
28 | * | USA. | |
---|
29 | * +-----------------------------------------------------------------------+ |
---|
30 | * |
---|
31 | * |
---|
32 | * ----------------------------------------------------------------------------- |
---|
33 | * |
---|
34 | * The KnownTags is a generic class to manage the definition of tags |
---|
35 | * |
---|
36 | * Tags are defined in an array $tags : |
---|
37 | * - key => the Tag ID (UShort for exif & Iptc, String for Xmp) |
---|
38 | * - value => an array with theses properties |
---|
39 | * |
---|
40 | * Common properties |
---|
41 | * 'tagName' => String : the official name of the tag (used for |
---|
42 | * translation) |
---|
43 | * 'tagValues' => Array : an array to associate a label for each known |
---|
44 | * values |
---|
45 | * 'translatable' => Boolean : set to true if the value can be translated |
---|
46 | * 'implemented' => Boolean : set to true if the tag needs a specific |
---|
47 | * interpretation and is implemented |
---|
48 | * 'schema' => String : schema associated with the tag |
---|
49 | * exif : "tiff", "exif", "gps", "pentax", ... |
---|
50 | * xmp : "dc", "exif", "photoshop", ... |
---|
51 | * => not yet defined for Iptc.... |
---|
52 | * 'tagValues.special' => used on some tags for implementation |
---|
53 | * |
---|
54 | * Exif like tags |
---|
55 | * 'combiTag' => Integer : use on some specific tags |
---|
56 | * |
---|
57 | * Xmp specific properties (==> see XmpTags.class.php for more information) |
---|
58 | * 'iptcTag' => if the Xmp tag exist in Iptc, the Iptc tag Id |
---|
59 | * 'exifTag' => if the Xmp tag exist in Exif, the Exif tag Id |
---|
60 | * 'type' => the type of Xmp data |
---|
61 | * |
---|
62 | * ----------------------------------------------------------------------------- |
---|
63 | * |
---|
64 | * .. Notes .. |
---|
65 | * |
---|
66 | * This class is not declared as an abstract class, but it's not recommanded to |
---|
67 | * create object with it. |
---|
68 | * |
---|
69 | * Derived classes : |
---|
70 | * - GpsTags (exif gps tags) |
---|
71 | * - IfdTag (exif & tiff tags) |
---|
72 | * - IptcTag (iptc tags) |
---|
73 | * - PentaxTag (pentax exif tags) |
---|
74 | * - XmpTag (xmp tags) |
---|
75 | * |
---|
76 | * |
---|
77 | * This class provides theses public functions : |
---|
78 | * - getTags |
---|
79 | * - tagIdExists |
---|
80 | * - getTagById |
---|
81 | * - getTagIdByName |
---|
82 | * - getTagByName |
---|
83 | * - getLabel |
---|
84 | * |
---|
85 | * ----------------------------------------------------------------------------- |
---|
86 | * |
---|
87 | */ |
---|
88 | |
---|
89 | define("KNOWN_TAGS_IMPLEMENTED", 0x01); |
---|
90 | define("KNOWN_TAGS_NOT_IMPLEMENTED", 0x02); |
---|
91 | define("KNOWN_TAGS_ALL", KNOWN_TAGS_NOT_IMPLEMENTED | KNOWN_TAGS_IMPLEMENTED); |
---|
92 | |
---|
93 | class KnownTags |
---|
94 | { |
---|
95 | protected $label = ""; |
---|
96 | protected $tags = Array(); |
---|
97 | |
---|
98 | function __construct() |
---|
99 | { |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | function __destruct() |
---|
104 | { |
---|
105 | unset($this->label); |
---|
106 | unset($this->tags); |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * this function return the $tags array |
---|
111 | * |
---|
112 | * an optional parameter $filter can be given. |
---|
113 | * its an array with the keys : |
---|
114 | * 'implemented' => Integer = KNOWN_TAGS_ALL, KNOWN_TAGS_IMPLEMENTED, KNOWN_TAGS_NOT_IMPLEMENTED |
---|
115 | * filter tags with the property 'implemented' and 'known' |
---|
116 | * 'schema' => String = name of the schema |
---|
117 | * filter tags with the schema property |
---|
118 | * |
---|
119 | * @param Array $filter (optional) |
---|
120 | * @return Array : an array of tags properties (see this file header to know |
---|
121 | * more about the tag properties) |
---|
122 | */ |
---|
123 | public function getTags($filter = Array('implemented' => KNOWN_TAGS_ALL, 'schema' => NULL)) |
---|
124 | { |
---|
125 | if(!array_key_exists('implemented', $filter)) |
---|
126 | { |
---|
127 | $filter['implemented'] = KNOWN_TAGS_ALL; |
---|
128 | } |
---|
129 | |
---|
130 | if(!array_key_exists('schema', $filter)) |
---|
131 | { |
---|
132 | $filter['schema'] = NULL; |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | $returned=Array(); |
---|
137 | foreach($this->tags as $key => $val) |
---|
138 | { |
---|
139 | if(( ($val['implemented'] and ($filter['implemented'] & KNOWN_TAGS_IMPLEMENTED)) or |
---|
140 | (!$val['implemented'] and ($filter['implemented'] & KNOWN_TAGS_NOT_IMPLEMENTED)) ) and |
---|
141 | |
---|
142 | (is_null($filter['schema']) or |
---|
143 | (!is_null($filter['schema']) and $val['schema']==$filter['schema']) ) |
---|
144 | ) |
---|
145 | { |
---|
146 | $returned[$key]=$val; |
---|
147 | } |
---|
148 | } |
---|
149 | return($returned); |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * this function returns true if the given ID exists |
---|
154 | * |
---|
155 | * @return Boolean |
---|
156 | */ |
---|
157 | public function tagIdExists($id) |
---|
158 | { |
---|
159 | return(array_key_exists($id, $this->tags)); |
---|
160 | } |
---|
161 | |
---|
162 | /** |
---|
163 | * returns a tag, searched by its ID |
---|
164 | * return false if the tag is not found |
---|
165 | * |
---|
166 | * @return Array : see this file header to know more about the tag properties |
---|
167 | */ |
---|
168 | public function getTagById($id) |
---|
169 | { |
---|
170 | if(array_key_exists($id, $this->tags)) |
---|
171 | { |
---|
172 | return($this->tags[$id]); |
---|
173 | } |
---|
174 | return(false); |
---|
175 | } |
---|
176 | |
---|
177 | /** |
---|
178 | * returns the tag ID, searched by its name property |
---|
179 | * return false if the tag is not found |
---|
180 | * |
---|
181 | * @return String or UShort |
---|
182 | */ |
---|
183 | public function getTagIdByName($name) |
---|
184 | { |
---|
185 | foreach($this->tags as $key => $val) |
---|
186 | { |
---|
187 | if($val['tagName']==$name) |
---|
188 | return($key); |
---|
189 | } |
---|
190 | return(false); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * returns a Tag, searched by its name property |
---|
195 | * return false if the tag is not found |
---|
196 | * |
---|
197 | * @return Array : see this file header to know more about the tag properties |
---|
198 | */ |
---|
199 | public function getTagByName($name) |
---|
200 | { |
---|
201 | $index=$this->getTagIdByName($name); |
---|
202 | if($index!==false) |
---|
203 | return($this->tags[$index]); |
---|
204 | return(false); |
---|
205 | } |
---|
206 | |
---|
207 | /** |
---|
208 | * return the label associated with the tag defininition |
---|
209 | * (something like "Exif & Tiff tags" or "Pentax specific tags") |
---|
210 | * |
---|
211 | * @return String |
---|
212 | */ |
---|
213 | public function getLabel() |
---|
214 | { |
---|
215 | return($this->label); |
---|
216 | } |
---|
217 | |
---|
218 | } |
---|
219 | |
---|
220 | ?> |
---|