1 | <?php |
---|
2 | /* |
---|
3 | * ----------------------------------------------------------------------------- |
---|
4 | * Plugin Name: Advanced MetaData |
---|
5 | * ----------------------------------------------------------------------------- |
---|
6 | * Author : Grum |
---|
7 | * email : grum@piwigo.org |
---|
8 | * website : http://photos.grum.fr |
---|
9 | * PWG user : http://forum.piwigo.org/profile.php?id=3706 |
---|
10 | * |
---|
11 | * << May the Little SpaceFrog be with you ! >> |
---|
12 | * |
---|
13 | * ----------------------------------------------------------------------------- |
---|
14 | * |
---|
15 | * See main.inc.php for release information |
---|
16 | * |
---|
17 | * AIPInstall class => install process page when the plugin is used for the |
---|
18 | * first time |
---|
19 | * |
---|
20 | * ----------------------------------------------------------------------------- |
---|
21 | */ |
---|
22 | |
---|
23 | |
---|
24 | if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
25 | |
---|
26 | include_once('amd_root.class.inc.php'); |
---|
27 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); |
---|
28 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
29 | |
---|
30 | class AMD_AIPInstall extends AMD_root |
---|
31 | { |
---|
32 | protected $tabsheet; |
---|
33 | |
---|
34 | public function __construct($prefixeTable, $filelocation) |
---|
35 | { |
---|
36 | parent::__construct($prefixeTable, $filelocation); |
---|
37 | $this->loadConfig(); |
---|
38 | $this->initEvents(); |
---|
39 | |
---|
40 | $this->tabsheet = new tabsheet(); |
---|
41 | $this->tabsheet->add('install', |
---|
42 | l10n('g003_install'), |
---|
43 | $this->getAdminLink()."&f_tabsheet=install"); |
---|
44 | } |
---|
45 | |
---|
46 | public function __destruct() |
---|
47 | { |
---|
48 | unset($this->tabsheet); |
---|
49 | parent::__destruct(); |
---|
50 | } |
---|
51 | |
---|
52 | /* |
---|
53 | initialize events call for the plugin |
---|
54 | */ |
---|
55 | public function initEvents() |
---|
56 | { |
---|
57 | parent::initEvents(); |
---|
58 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
59 | } |
---|
60 | |
---|
61 | /* |
---|
62 | display administration page |
---|
63 | */ |
---|
64 | public function manage() |
---|
65 | { |
---|
66 | global $template; |
---|
67 | |
---|
68 | $this->checkRequest(); |
---|
69 | $this->returnAjaxContent(); |
---|
70 | |
---|
71 | $template->set_filename('plugin_admin_content', dirname($this->getFileLocation())."/admin/amd_admin.tpl"); |
---|
72 | |
---|
73 | $this->tabsheet->select($_REQUEST['f_tabsheet']); |
---|
74 | $this->tabsheet->assign(); |
---|
75 | $selected_tab=$this->tabsheet->get_selected(); |
---|
76 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
77 | |
---|
78 | $this->displayInstallPage(); |
---|
79 | |
---|
80 | $pluginInfo=array( |
---|
81 | 'AMD_VERSION' => "<i>".$this->getPluginName()."</i> ".l10n('g003_version').AMD_VERSION, |
---|
82 | 'AMD_PAGE' => $_REQUEST['f_tabsheet'], |
---|
83 | 'PATH' => AMD_PATH |
---|
84 | ); |
---|
85 | |
---|
86 | $template->assign('plugin', $pluginInfo); |
---|
87 | |
---|
88 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | * check the $_REQUEST values and set default values |
---|
95 | * |
---|
96 | */ |
---|
97 | protected function checkRequest() |
---|
98 | { |
---|
99 | $_REQUEST['f_tabsheet']='install'; |
---|
100 | |
---|
101 | if(!isset($_REQUEST['ajaxfct'])) return(false); |
---|
102 | |
---|
103 | /* |
---|
104 | * check admin.install.chooseInterface values |
---|
105 | */ |
---|
106 | if($_REQUEST['ajaxfct']=="admin.install.chooseInterface") |
---|
107 | { |
---|
108 | if(!isset($_REQUEST['interfaceMode'])) $_REQUEST['interfaceMode']=''; |
---|
109 | |
---|
110 | if(!($_REQUEST['interfaceMode']=="basic" or |
---|
111 | $_REQUEST['interfaceMode']=="advanced")) $_REQUEST['ajaxfct']=''; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | /** |
---|
118 | * return ajax content |
---|
119 | */ |
---|
120 | protected function returnAjaxContent() |
---|
121 | { |
---|
122 | global $ajax, $template; |
---|
123 | |
---|
124 | if(isset($_REQUEST['ajaxfct'])) |
---|
125 | { |
---|
126 | //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']); |
---|
127 | $result="<p class='errors'>An error has occured</p>"; |
---|
128 | switch($_REQUEST['ajaxfct']) |
---|
129 | { |
---|
130 | case 'admin.install.chooseInterface': |
---|
131 | $result=$this->ajax_amd_admin_installChooseInterface($_REQUEST['interfaceMode']); |
---|
132 | break; |
---|
133 | } |
---|
134 | GPCAjax::returnResult($result); |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | /** |
---|
141 | * display config page |
---|
142 | */ |
---|
143 | protected function displayInstallPage() |
---|
144 | { |
---|
145 | global $template, $lang; |
---|
146 | |
---|
147 | |
---|
148 | $template->set_filename('body_page', |
---|
149 | dirname($this->getFileLocation()).'/admin/amd_install_page.tpl'); |
---|
150 | |
---|
151 | |
---|
152 | $help=Array( |
---|
153 | 'g003_basic_mode_help' => GPCCore::BBtoHTML($lang['g003_basic_mode_help']), |
---|
154 | 'g003_advanced_mode_help' => GPCCore::BBtoHTML($lang['g003_advanced_mode_help']) |
---|
155 | ); |
---|
156 | |
---|
157 | |
---|
158 | $template->assign('help', $help); |
---|
159 | $template->assign('urlRequest', $this->getAdminLink()); |
---|
160 | |
---|
161 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
162 | } //displayInstallPage |
---|
163 | |
---|
164 | |
---|
165 | |
---|
166 | /** |
---|
167 | * prepare the tables for the basic interface mode |
---|
168 | */ |
---|
169 | protected function initializeDatabaseForBasicInterface() |
---|
170 | { |
---|
171 | $basicMeta=array( |
---|
172 | 'magic.Author.Artist', |
---|
173 | 'magic.Author.Comment', |
---|
174 | 'magic.Author.Copyright', |
---|
175 | 'magic.Author.ImageTitle', |
---|
176 | 'magic.Author.Keywords', |
---|
177 | 'magic.GPS.Altitude', |
---|
178 | 'magic.GPS.Latitude', |
---|
179 | 'magic.GPS.LatitudeNum', |
---|
180 | 'magic.GPS.Localization', |
---|
181 | 'magic.GPS.Longitude', |
---|
182 | 'magic.GPS.LongitudeNum', |
---|
183 | 'magic.Image.Dimension', |
---|
184 | 'magic.Image.Height', |
---|
185 | 'magic.Image.Width', |
---|
186 | 'magic.Processing.OriginalFileName', |
---|
187 | 'magic.Processing.PostProcessingDateTime', |
---|
188 | 'magic.Processing.PostProcessingSoftware', |
---|
189 | 'magic.Processing.Software', |
---|
190 | 'magic.ShotInfo.DateTime', |
---|
191 | 'magic.ShotInfo.Flash.RedEyeMode', |
---|
192 | 'iptc.By-line', |
---|
193 | 'iptc.By-line Title', |
---|
194 | 'iptc.Caption/Abstract', |
---|
195 | 'iptc.Category', |
---|
196 | 'iptc.City', |
---|
197 | 'iptc.Contact', |
---|
198 | 'iptc.Content Location Code', |
---|
199 | 'iptc.Content Location Name', |
---|
200 | 'iptc.Copyright Notice', |
---|
201 | 'iptc.Country/Primary Location Code', |
---|
202 | 'iptc.Country/Primary Location Name', |
---|
203 | 'iptc.Credit', |
---|
204 | 'iptc.Date Created', |
---|
205 | 'iptc.Date Sent', |
---|
206 | 'iptc.Destination', |
---|
207 | 'iptc.Digital Creation Date', |
---|
208 | 'iptc.Digital Creation Time', |
---|
209 | 'iptc.Edit Status', |
---|
210 | 'iptc.Envelope Number', |
---|
211 | 'iptc.Envelope Priority', |
---|
212 | 'iptc.Expiration Date', |
---|
213 | 'iptc.Expiration Time', |
---|
214 | 'iptc.Fixture Identifier', |
---|
215 | 'iptc.Headline', |
---|
216 | 'iptc.Image Orientation', |
---|
217 | 'iptc.Keywords', |
---|
218 | 'iptc.Language Identifier', |
---|
219 | 'iptc.Object Attribute Reference', |
---|
220 | 'iptc.Object Cycle', |
---|
221 | 'iptc.Object Name', |
---|
222 | 'iptc.Object Type Reference', |
---|
223 | 'iptc.Original Transmission Reference', |
---|
224 | 'iptc.Originating Program', |
---|
225 | 'iptc.Product I.D.', |
---|
226 | 'iptc.Program Version', |
---|
227 | 'iptc.Province/State', |
---|
228 | 'iptc.Release Date', |
---|
229 | 'iptc.Release Time', |
---|
230 | 'iptc.Service Identifier', |
---|
231 | 'iptc.Source', |
---|
232 | 'iptc.Special Instructions', |
---|
233 | 'iptc.Subject Reference', |
---|
234 | 'iptc.Subject Reference[Detail Name]', |
---|
235 | 'iptc.Subject Reference[IPR]', |
---|
236 | 'iptc.Subject Reference[Matter Name]', |
---|
237 | 'iptc.Subject Reference[Name]', |
---|
238 | 'iptc.Subject Reference[Number]', |
---|
239 | 'iptc.Sublocation', |
---|
240 | 'iptc.Supplemental Category', |
---|
241 | 'iptc.Time Created', |
---|
242 | 'iptc.Time Sent', |
---|
243 | 'iptc.Urgency', |
---|
244 | 'iptc.Writer/Editor', |
---|
245 | 'xmp.Iptc4xmpCore:CiAdrCity', |
---|
246 | 'xmp.Iptc4xmpCore:CiAdrCtry', |
---|
247 | 'xmp.Iptc4xmpCore:CiAdrExtadr', |
---|
248 | 'xmp.Iptc4xmpCore:CiAdrPcode', |
---|
249 | 'xmp.Iptc4xmpCore:CiEmailWork', |
---|
250 | 'xmp.Iptc4xmpCore:CiTelWork', |
---|
251 | 'xmp.Iptc4xmpCore:CiUrlWork', |
---|
252 | 'xmp.Iptc4xmpCore:CountryCode', |
---|
253 | 'xmp.Iptc4xmpCore:IntellectualGenre', |
---|
254 | 'xmp.Iptc4xmpCore:Location', |
---|
255 | 'xmp.Iptc4xmpCore:Scene', |
---|
256 | 'xmp.aux:Firmware', |
---|
257 | 'xmp.aux:Lens', |
---|
258 | 'xmp.crs:Balance', |
---|
259 | 'xmp.crs:CameraProfile', |
---|
260 | 'xmp.crs:ColorNoiseReduction', |
---|
261 | 'xmp.crs:Exposure', |
---|
262 | 'xmp.crs:HasCrop', |
---|
263 | 'xmp.crs:HasSettings', |
---|
264 | 'xmp.crs:RawFileName', |
---|
265 | 'xmp.crs:WhiteBalance', |
---|
266 | 'xmp.dc:CreatorTool', |
---|
267 | 'xmp.dc:Type', |
---|
268 | 'xmp.dc:contributor', |
---|
269 | 'xmp.dc:coverage', |
---|
270 | 'xmp.dc:creator', |
---|
271 | 'xmp.dc:description', |
---|
272 | 'xmp.dc:format', |
---|
273 | 'xmp.dc:identifier', |
---|
274 | 'xmp.dc:language', |
---|
275 | 'xmp.dc:publisher', |
---|
276 | 'xmp.dc:relation', |
---|
277 | 'xmp.dc:rights', |
---|
278 | 'xmp.dc:source', |
---|
279 | 'xmp.dc:subject', |
---|
280 | 'xmp.dc:title', |
---|
281 | 'xmp.photoshop:AuthorsPosition', |
---|
282 | 'xmp.photoshop:CaptionWriter', |
---|
283 | 'xmp.photoshop:Category', |
---|
284 | 'xmp.photoshop:City', |
---|
285 | 'xmp.photoshop:Country', |
---|
286 | 'xmp.photoshop:Credit', |
---|
287 | 'xmp.photoshop:DateCreated', |
---|
288 | 'xmp.photoshop:Headline', |
---|
289 | 'xmp.photoshop:ICCProfile', |
---|
290 | 'xmp.photoshop:Instructions', |
---|
291 | 'xmp.photoshop:Source', |
---|
292 | 'xmp.photoshop:State', |
---|
293 | 'xmp.photoshop:SupplementalCategories', |
---|
294 | 'xmp.photoshop:TransmissionReference', |
---|
295 | 'xmp.photoshop:Urgency', |
---|
296 | 'xmp.tiff:Artist', |
---|
297 | 'xmp.tiff:Copyright', |
---|
298 | 'xmp.tiff:DateTime', |
---|
299 | 'xmp.tiff:ImageDescription', |
---|
300 | 'xmp.tiff:Software', |
---|
301 | 'xmp.xmp:Advisory', |
---|
302 | 'xmp.xmp:BaseURL', |
---|
303 | 'xmp.xmp:CreateDate', |
---|
304 | 'xmp.xmp:CreatorTool', |
---|
305 | 'xmp.xmp:Identifier', |
---|
306 | 'xmp.xmp:Label', |
---|
307 | 'xmp.xmp:MetadataDate', |
---|
308 | 'xmp.xmp:ModifyDate', |
---|
309 | 'xmp.xmp:Nickname', |
---|
310 | 'xmp.xmp:Rating', |
---|
311 | 'xmp.xmpRights:Certificate', |
---|
312 | 'xmp.xmpRights:Marked', |
---|
313 | 'xmp.xmpRights:Owner', |
---|
314 | 'xmp.xmpRights:UsageTerms', |
---|
315 | 'xmp.xmpRights:WebStatement' |
---|
316 | ); |
---|
317 | |
---|
318 | $sql=""; |
---|
319 | foreach($basicMeta as $key=>$val) |
---|
320 | { |
---|
321 | $basicMeta[$key]="('$val', 0, -1)"; |
---|
322 | } |
---|
323 | $sql="INSERT INTO `".$this->tables['selected_tags']."` VALUES ".implode(',', $basicMeta); |
---|
324 | pwg_query($sql); |
---|
325 | } |
---|
326 | |
---|
327 | /** |
---|
328 | * prepare the tables for the advanced interface mode |
---|
329 | */ |
---|
330 | protected function initializeDatabaseForAdvancedInterface() |
---|
331 | { |
---|
332 | global $user; |
---|
333 | |
---|
334 | $listToAnalyze=Array(Array(), Array()); |
---|
335 | /* |
---|
336 | * select 25 pictures into the caddie |
---|
337 | */ |
---|
338 | $sql="SELECT ti.id, ti.path, ti.has_high |
---|
339 | FROM ".CADDIE_TABLE." tc |
---|
340 | LEFT JOIN ".IMAGES_TABLE." ti ON ti.id = tc.element_id |
---|
341 | WHERE tc.user_id = ".$user['id']." |
---|
342 | AND ti.id IS NOT NULL |
---|
343 | ORDER BY RAND() LIMIT 25;"; |
---|
344 | $result=pwg_query($sql); |
---|
345 | if($result) |
---|
346 | { |
---|
347 | while($row=pwg_db_fetch_assoc($result)) |
---|
348 | { |
---|
349 | $listToAnalyze[0][]=$row; |
---|
350 | $listToAnalyze[1][]=$row['id']; |
---|
351 | } |
---|
352 | } |
---|
353 | /* |
---|
354 | * if caddie is empty, of is have less than 25 pictures, select other |
---|
355 | * pictures from the gallery |
---|
356 | */ |
---|
357 | if(count($listToAnalyze[0])<25) |
---|
358 | { |
---|
359 | if(count($listToAnalyze[0])>0) |
---|
360 | { |
---|
361 | $excludeList="WHERE ti.id NOT IN(".implode(",", $listToAnalyze[1]).") "; |
---|
362 | } |
---|
363 | else |
---|
364 | { |
---|
365 | $excludeList=""; |
---|
366 | } |
---|
367 | $sql="SELECT ti.id, ti.path, ti.has_high |
---|
368 | FROM ".IMAGES_TABLE." ti ".$excludeList." |
---|
369 | ORDER BY RAND() LIMIT ".(25-count($listToAnalyze[0])).";"; |
---|
370 | $result=pwg_query($sql); |
---|
371 | if($result) |
---|
372 | { |
---|
373 | while($row=pwg_db_fetch_assoc($result)) |
---|
374 | { |
---|
375 | $listToAnalyze[0][]=$row; |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | /* |
---|
381 | * analyze the 25 selected pictures |
---|
382 | */ |
---|
383 | if(count($listToAnalyze[0])>0) |
---|
384 | { |
---|
385 | // $path = path of piwigo's on the server filesystem |
---|
386 | $path=dirname(dirname(dirname(__FILE__))); |
---|
387 | |
---|
388 | foreach($listToAnalyze[0] as $val) |
---|
389 | { |
---|
390 | if($val['has_high']==='true' and $this->config['amd_UseMetaFromHD']=='y') |
---|
391 | { |
---|
392 | $this->analyzeImageFile($path."/".dirname($val['path'])."/pwg_high/".basename($val['path']), $val['id']); |
---|
393 | } |
---|
394 | else |
---|
395 | { |
---|
396 | $this->analyzeImageFile($path."/".$val['path'], $val['id']); |
---|
397 | } |
---|
398 | } |
---|
399 | $this->makeStatsConsolidation(); |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | |
---|
404 | |
---|
405 | /* |
---|
406 | * --------------------------------------------------------------------------- |
---|
407 | * AJAX FUNCTIONS |
---|
408 | * --------------------------------------------------------------------------- |
---|
409 | */ |
---|
410 | |
---|
411 | /** |
---|
412 | * set choice for plugin interface mode (basic/advanced) |
---|
413 | * @param String $interfaceMode : mode for the interface 'basic' or 'advanced' |
---|
414 | * @return String : ok or ko |
---|
415 | */ |
---|
416 | protected function ajax_amd_admin_installChooseInterface($interfaceMode) |
---|
417 | { |
---|
418 | switch($interfaceMode) |
---|
419 | { |
---|
420 | case 'basic': |
---|
421 | $this->config['amd_FillDataBaseContinuously']='n'; |
---|
422 | $this->initializeDatabaseForBasicInterface(); |
---|
423 | break; |
---|
424 | case 'advanced': |
---|
425 | $this->initializeDatabaseForAdvancedInterface(); |
---|
426 | break; |
---|
427 | } |
---|
428 | |
---|
429 | $this->config['newInstall']='n'; |
---|
430 | $this->config['amd_InterfaceMode']=$interfaceMode; |
---|
431 | $this->saveConfig(); |
---|
432 | |
---|
433 | return('ok'); |
---|
434 | } |
---|
435 | |
---|
436 | } //class |
---|
437 | |
---|
438 | |
---|
439 | ?> |
---|