1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of efiMetadatas, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009 JC Denis and contributors |
---|
6 | # jcdenis@gdwd.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | |
---|
14 | class efiMetadatas |
---|
15 | { |
---|
16 | public static function imgSource($core,$subject,$size='') |
---|
17 | { |
---|
18 | # Path and url |
---|
19 | $p_url = $core->blog->settings->public_url; |
---|
20 | $p_site = preg_replace('#^(.+?//.+?)/(.*)$#','$1',$core->blog->url); |
---|
21 | $p_root = $core->blog->public_path; |
---|
22 | |
---|
23 | # Image pattern |
---|
24 | $pattern = '(?:'.preg_quote($p_site,'/').')?'.preg_quote($p_url,'/'); |
---|
25 | $pattern = sprintf('/<img.+?src="%s(.*?\.(?:jpg|gif|png))"[^>]+/msu',$pattern); |
---|
26 | |
---|
27 | # No image |
---|
28 | if (!preg_match_all($pattern,$subject,$m)) return; |
---|
29 | |
---|
30 | $src = $thb = $alt = false; |
---|
31 | $alt = $metas = $thumb = ''; |
---|
32 | $allowed_ext = array('.jpg','.JPG','.png','.PNG','.gif','.GIF'); |
---|
33 | |
---|
34 | # Loop through images |
---|
35 | foreach ($m[1] as $i => $img) |
---|
36 | { |
---|
37 | $src = false; |
---|
38 | $info = path::info($img); |
---|
39 | $base = $info['base']; |
---|
40 | $ext = $info['extension']; |
---|
41 | |
---|
42 | # Not original |
---|
43 | if (preg_match('/^\.(.+)_(sq|t|s|m)$/',$base,$mbase)) |
---|
44 | { |
---|
45 | $base = $mbase[1]; |
---|
46 | } |
---|
47 | |
---|
48 | # Full path |
---|
49 | $f = $p_root.'/'.$info['dirname'].'/'.$base; |
---|
50 | |
---|
51 | # Find extension |
---|
52 | foreach($allowed_ext as $end) |
---|
53 | { |
---|
54 | if (file_exists($f.$end)) |
---|
55 | { |
---|
56 | $src = $f.$end; |
---|
57 | break; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | # No file |
---|
62 | if (!$src) continue; |
---|
63 | |
---|
64 | # Find thumbnail |
---|
65 | if (!empty($size)) |
---|
66 | { |
---|
67 | $t = $p_root.'/'.$info['dirname'].'/.'.$base.'_'.$size.'.jpg'; |
---|
68 | if (file_exists($t)) |
---|
69 | { |
---|
70 | $thb = $p_url.(dirname($img) != '/' ? dirname($img) : '').'/.'.$base.'_'.$size.'.jpg'; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | # Find image description |
---|
75 | if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) |
---|
76 | { |
---|
77 | $alt = $malt[1]; |
---|
78 | } |
---|
79 | break; |
---|
80 | } |
---|
81 | |
---|
82 | return array('source' => $src, 'thumb' => $thb, 'title' => $alt); |
---|
83 | } |
---|
84 | |
---|
85 | public static function imgMeta($core,$src) |
---|
86 | { |
---|
87 | $metas = array( |
---|
88 | 'Title' => array(__('Title'),''), |
---|
89 | 'Description' => array(__('Description'),''), |
---|
90 | 'Location' => array(__('Location'),''), |
---|
91 | 'DateTimeOriginal' => array(__('Date'),''), |
---|
92 | 'Make' => array(__('Manufacturer'),''), |
---|
93 | 'Model' => array(__('Model'),''), |
---|
94 | 'Lens' => array(__('Lens'),''), |
---|
95 | 'ExposureProgram' => array(__('Program'),''), |
---|
96 | 'Exposure' => array(__('Speed'),''), |
---|
97 | 'FNumber' => array(__('Aperture'),''), |
---|
98 | 'ISOSpeedRatings' => array(__('ISO'),''), |
---|
99 | 'FocalLength' => array(__('Focal'),''), |
---|
100 | 'ExposureBiasValue' => array(__('Exposure Bias'),''), |
---|
101 | 'MeteringMode' => array(__('Metering mode'),'') |
---|
102 | ); |
---|
103 | |
---|
104 | $exp_prog = array( |
---|
105 | 0 => __('Not defined'), |
---|
106 | 1 => __('Manual'), |
---|
107 | 2 => __('Normal program'), |
---|
108 | 3 => __('Aperture priority'), |
---|
109 | 4 => __('Shutter priority'), |
---|
110 | 5 => __('Creative program'), |
---|
111 | 6 => __('Action program'), |
---|
112 | 7 => __('Portait mode'), |
---|
113 | 8 => __('Landscape mode') |
---|
114 | ); |
---|
115 | |
---|
116 | $met_mod = array( |
---|
117 | 0 => __('Unknow'), |
---|
118 | 1 => __('Average'), |
---|
119 | 2 => __('Center-weighted average'), |
---|
120 | 3 => __('Spot'), |
---|
121 | 4 => __('Multi spot'), |
---|
122 | 5 => __('Pattern'), |
---|
123 | 6 => __('Partial'), |
---|
124 | 7 => __('Other') |
---|
125 | ); |
---|
126 | |
---|
127 | if (!$src || !file_exists($src)) return $metas; |
---|
128 | |
---|
129 | $m = imageMeta::readMeta($src); |
---|
130 | |
---|
131 | # Title |
---|
132 | if (!empty($m['Title'])) |
---|
133 | { |
---|
134 | $metas['Title'][1] = html::escapeHTML($m['Title']); |
---|
135 | } |
---|
136 | |
---|
137 | # Description |
---|
138 | if (!empty($m['Description'])) |
---|
139 | { |
---|
140 | if (!empty($m['Title']) && $m['Title'] != $m['Description']) |
---|
141 | { |
---|
142 | $metas['Description'][1] = html::escpeHTML($m['Description']); |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | # Location |
---|
147 | if (!empty($m['City'])) |
---|
148 | { |
---|
149 | $metas['Location'][1] .= html::escapeHTML($m['City']); |
---|
150 | } |
---|
151 | if (!empty($m['City']) && !empty($m['country'])) |
---|
152 | { |
---|
153 | $metas['Location'][1] .= ', '; |
---|
154 | } |
---|
155 | if (!empty($m['country'])) |
---|
156 | { |
---|
157 | $metas['Location'][1] .= html::escapeHTML($m['Country']); |
---|
158 | } |
---|
159 | |
---|
160 | # DateTimeOriginal |
---|
161 | if (!empty($m['DateTimeOriginal'])) |
---|
162 | { |
---|
163 | $dt_ft = $core->blog->settings->date_format.', '.$core->blog->settings->time_format; |
---|
164 | $dt_tz = $core->blog->settings->blog_timezone; |
---|
165 | $metas['DateTimeOriginal'][1] = dt::dt2str($dt_ft,$m['DateTimeOriginal'],$dt_tz); |
---|
166 | } |
---|
167 | |
---|
168 | # Make |
---|
169 | if (isset($m['Make'])) |
---|
170 | { |
---|
171 | $metas['Make'][1] = html::escapeHTML($m['Make']); |
---|
172 | } |
---|
173 | |
---|
174 | # Model |
---|
175 | if (isset($m['Model'])) |
---|
176 | { |
---|
177 | $metas['Model'][1] = html::escapeHTML($m['Model']); |
---|
178 | } |
---|
179 | |
---|
180 | # Lens |
---|
181 | if (isset($m['Lens'])) |
---|
182 | { |
---|
183 | $metas['Lens'][1] = html::escapeHTML($m['Lens']); |
---|
184 | } |
---|
185 | |
---|
186 | # ExposureProgram |
---|
187 | if (isset($m['ExposureProgram'])) |
---|
188 | { |
---|
189 | $metas['ExposureProgram'][1] = isset($exp_prog[$m['ExposureProgram']]) ? |
---|
190 | $exp_prog[$m['ExposureProgram']] : $m['ExposureProgram']; |
---|
191 | } |
---|
192 | |
---|
193 | # Exposure |
---|
194 | if (!empty($m['Exposure'])) |
---|
195 | { |
---|
196 | $metas['Exposure'][1] = $m['Exposure'].'s'; |
---|
197 | } |
---|
198 | |
---|
199 | # FNumber |
---|
200 | if (!empty($m['FNumber'])) |
---|
201 | { |
---|
202 | $ap = sscanf($m['FNumber'],'%d/%d'); |
---|
203 | $metas['FNumber'][1] = $ap ? 'f/'.( $ap[0] / $ap[1]) : $m['FNumber']; |
---|
204 | } |
---|
205 | |
---|
206 | # ISOSpeedRatings |
---|
207 | if (!empty($m['ISOSpeedRatings'])) |
---|
208 | { |
---|
209 | $metas['ISOSpeedRatings'][1] = $m['ISOSpeedRatings']; |
---|
210 | } |
---|
211 | |
---|
212 | # FocalLength |
---|
213 | if (!empty($m['FocalLength'])) |
---|
214 | { |
---|
215 | $fl = sscanf($m['FocalLength'],'%d/%d'); |
---|
216 | $metas['FocalLength'][1] = $fl ? $fl[0]/$fl[1].'mm' : $m['FocalLength']; |
---|
217 | } |
---|
218 | |
---|
219 | # ExposureBiasValue |
---|
220 | if (isset($m['ExposureBiasValue'])) |
---|
221 | { |
---|
222 | $metas['ExposureBiasValue'][1] = $m['ExposureBiasValue']; |
---|
223 | } |
---|
224 | |
---|
225 | # MeteringMode |
---|
226 | if (isset($m['MeteringMode'])) |
---|
227 | { |
---|
228 | $metas['MeteringMode'][1] = isset($met_mod[$m['MeteringMode']]) ? |
---|
229 | $exp_prog[$m['MeteringMode']] : $m['MeteringMode']; |
---|
230 | } |
---|
231 | |
---|
232 | return $metas; |
---|
233 | } |
---|
234 | } |
---|
235 | ?> |
---|