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