Dotclear

source: plugins/efiMetadatas/inc/class.efimetadatas.php @ 2304

Revision 2304, 5.8 KB checked in by JcDenis, 13 years ago (diff)

efiMetadatas 0.3

  • Switched to DC 2.2
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of efiMetadatas, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009-2010 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
13class efiMetadatas
14{
15     public static function imgSource($core,$subject,$size='')
16     {
17          # Path and url
18          $p_url = $core->blog->settings->system->public_url;
19          $p_site = preg_replace('#^(.+?//.+?)/(.*)$#','$1',$core->blog->url);
20          $p_root = $core->blog->public_path;
21         
22          # Image pattern
23          $pattern = '(?:'.preg_quote($p_site,'/').')?'.preg_quote($p_url,'/');
24          $pattern = sprintf('/<img.+?src="%s(.*?\.(?:jpg|gif|png))"[^>]+/msu',$pattern);
25         
26          # No image
27          if (!preg_match_all($pattern,$subject,$m)) return;
28         
29          $src = $thb = $alt = false;
30          $alt = $metas = $thumb = '';
31          $allowed_ext = array('.jpg','.JPG','.png','.PNG','.gif','.GIF');
32         
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'];
40               
41               # Not original
42               if (preg_match('/^\.(.+)_(sq|t|s|m)$/',$base,$mbase))
43               {
44                    $base = $mbase[1];
45               }
46               
47               # Full path
48               $f = $p_root.'/'.$info['dirname'].'/'.$base;
49               
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               }
59               
60               # No file
61               if (!$src) continue;
62               
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               }
72               
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     }
83     
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          );
102         
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          );
114         
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          );
125         
126          if (!$src || !file_exists($src)) return $metas;
127         
128          $m = imageMeta::readMeta($src);
129         
130          # Title
131          if (!empty($m['Title']))
132          {
133               $metas['Title'][1] = html::escapeHTML($m['Title']);
134          }
135         
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          }
144         
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          {
162               $dt_ft = $core->blog->settings->system->date_format.', '.$core->blog->settings->system->time_format;
163               $dt_tz = $core->blog->settings->system->blog_timezone;
164               $metas['DateTimeOriginal'][1] = dt::dt2str($dt_ft,$m['DateTimeOriginal'],$dt_tz);
165          }
166         
167          # Make
168          if (isset($m['Make']))
169          {
170               $metas['Make'][1] = html::escapeHTML($m['Make']);
171          }
172         
173          # Model
174          if (isset($m['Model']))
175          {
176               $metas['Model'][1] = html::escapeHTML($m['Model']);
177          }
178         
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          }
191         
192          # Exposure
193          if (!empty($m['Exposure']))
194          {
195               $metas['Exposure'][1] = $m['Exposure'].'s';
196          }
197         
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          }
204         
205          # ISOSpeedRatings
206          if (!empty($m['ISOSpeedRatings']))
207          {
208               $metas['ISOSpeedRatings'][1] = $m['ISOSpeedRatings'];
209          }
210         
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          }
217         
218          # ExposureBiasValue
219          if (isset($m['ExposureBiasValue']))
220          {
221               $metas['ExposureBiasValue'][1] = $m['ExposureBiasValue'];
222          }
223         
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          }
230         
231          return $metas;
232     }
233}
234?>
Note: See TracBrowser for help on using the repository browser.

Sites map