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 | * AIP classe => manage integration in administration interface |
---|
18 | * |
---|
19 | * ----------------------------------------------------------------------------- |
---|
20 | */ |
---|
21 | |
---|
22 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
23 | |
---|
24 | include_once('amd_root.class.inc.php'); |
---|
25 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php'); |
---|
26 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
27 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/genericjs.class.inc.php'); |
---|
28 | |
---|
29 | |
---|
30 | class AMD_AIP extends AMD_root |
---|
31 | { |
---|
32 | protected $tabsheet; |
---|
33 | |
---|
34 | /** |
---|
35 | * |
---|
36 | * constructor needs the prefix of piwigo's tables and the location of plugin |
---|
37 | * |
---|
38 | * @param String $prefixeTable |
---|
39 | * @param String $filelocation |
---|
40 | */ |
---|
41 | public function __construct($prefixeTable, $filelocation) |
---|
42 | { |
---|
43 | parent::__construct($prefixeTable, $filelocation); |
---|
44 | |
---|
45 | $this->loadConfig(); |
---|
46 | $this->configForTemplate(); |
---|
47 | $this->initEvents(); |
---|
48 | |
---|
49 | $this->tabsheet = new tabsheet(); |
---|
50 | |
---|
51 | if($this->config['amd_InterfaceMode']=='basic') |
---|
52 | { |
---|
53 | $this->tabsheet->add('metadata', |
---|
54 | l10n('g003_metadata'), |
---|
55 | $this->getAdminLink().'-metadata'); |
---|
56 | $this->tabsheet->add('help', |
---|
57 | l10n('g003_help'), |
---|
58 | $this->getAdminLink().'-help'); |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | $this->tabsheet->add('database', |
---|
63 | l10n('g003_database'), |
---|
64 | $this->getAdminLink().'-database'); |
---|
65 | $this->tabsheet->add('metadata', |
---|
66 | l10n('g003_metadata'), |
---|
67 | $this->getAdminLink().'-metadata'); |
---|
68 | $this->tabsheet->add('search', |
---|
69 | l10n('g003_search'), |
---|
70 | $this->getAdminLink().'-search'); |
---|
71 | $this->tabsheet->add('tags', |
---|
72 | l10n('g003_tags'), |
---|
73 | $this->getAdminLink().'-tags'); |
---|
74 | $this->tabsheet->add('help', |
---|
75 | l10n('g003_help'), |
---|
76 | $this->getAdminLink().'-help'); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | public function __destruct() |
---|
81 | { |
---|
82 | unset($this->tabsheet); |
---|
83 | unset($this->ajax); |
---|
84 | parent::__destruct(); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | /* |
---|
89 | * --------------------------------------------------------------------------- |
---|
90 | * Public classe functions |
---|
91 | * --------------------------------------------------------------------------- |
---|
92 | */ |
---|
93 | |
---|
94 | |
---|
95 | /** |
---|
96 | * manage the plugin integration into piwigo's admin interface |
---|
97 | */ |
---|
98 | public function manage() |
---|
99 | { |
---|
100 | global $template, $page; |
---|
101 | |
---|
102 | $this->initRequest(); |
---|
103 | |
---|
104 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/amd_admin.tpl"); |
---|
105 | |
---|
106 | $this->tabsheet->select($_GET['tab']); |
---|
107 | $this->tabsheet->assign(); |
---|
108 | $selected_tab=$this->tabsheet->get_selected(); |
---|
109 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
110 | |
---|
111 | $pluginInfo=array( |
---|
112 | 'AMD_VERSION' => "<i>".$this->getPluginName()."</i> ".l10n('g003_version').AMD_VERSION, |
---|
113 | 'AMD_PAGE' => $_GET['tab'], |
---|
114 | 'PATH' => AMD_PATH |
---|
115 | ); |
---|
116 | |
---|
117 | $template->assign('plugin', $pluginInfo); |
---|
118 | |
---|
119 | switch($_GET['tab']) |
---|
120 | { |
---|
121 | case 'help': |
---|
122 | $this->displayHelp(); |
---|
123 | break; |
---|
124 | case 'database': |
---|
125 | $this->displayDatabase($_REQUEST['t']); |
---|
126 | break; |
---|
127 | case 'metadata': |
---|
128 | $this->displayMetaData($_REQUEST['t']); |
---|
129 | break; |
---|
130 | case 'search': |
---|
131 | $this->displaySearch($_REQUEST['t']); |
---|
132 | break; |
---|
133 | case 'tags': |
---|
134 | $this->displayTags(); |
---|
135 | break; |
---|
136 | } |
---|
137 | |
---|
138 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
139 | } |
---|
140 | |
---|
141 | /** |
---|
142 | * initialize events call for the plugin |
---|
143 | * |
---|
144 | * don't inherits from its parent => it's normal |
---|
145 | */ |
---|
146 | public function initEvents() |
---|
147 | { |
---|
148 | if(isset($_GET['tab']) and $_GET['tab']=='search') |
---|
149 | { |
---|
150 | // load request builder JS only on the search page |
---|
151 | GPCRequestBuilder::loadJSandCSS(); |
---|
152 | } |
---|
153 | |
---|
154 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
155 | GPCCss::applyGpcCss(); |
---|
156 | } |
---|
157 | |
---|
158 | /** |
---|
159 | * --------------------------------------------------------------------------- |
---|
160 | * Private & protected functions |
---|
161 | * --------------------------------------------------------------------------- |
---|
162 | */ |
---|
163 | |
---|
164 | /** |
---|
165 | * if empty, initialize the $_REQUEST var |
---|
166 | * |
---|
167 | * if not empty, check validity for the request values |
---|
168 | * |
---|
169 | */ |
---|
170 | private function initRequest() |
---|
171 | { |
---|
172 | //initialise $REQUEST values if not defined |
---|
173 | |
---|
174 | if(!isset($_GET['tab'])) |
---|
175 | { |
---|
176 | if($this->getNumOfPictures()==0 and $this->config['amd_InterfaceMode']=='advanced') |
---|
177 | { |
---|
178 | $_GET['tab']="database"; |
---|
179 | $_REQUEST['t']="state"; |
---|
180 | } |
---|
181 | else |
---|
182 | { |
---|
183 | $_GET['tab']="metadata"; |
---|
184 | $_REQUEST['t']="select"; |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | $tmp=explode('/', $_GET['tab'].'/'); |
---|
189 | $_GET['tab']=$tmp[0]; |
---|
190 | $_REQUEST['t']=$tmp[1]; |
---|
191 | |
---|
192 | |
---|
193 | if(!($_GET['tab']=="metadata" or |
---|
194 | $_GET['tab']=="help" or |
---|
195 | $_GET['tab']=="database" or |
---|
196 | $_GET['tab']=="search" or |
---|
197 | $_GET['tab']=="tags") |
---|
198 | or |
---|
199 | $this->config['amd_InterfaceMode']=='basic' and |
---|
200 | ( |
---|
201 | $_GET['tab']=="database" or |
---|
202 | $_GET['tab']=="search" or |
---|
203 | $_GET['tab']=="tags" |
---|
204 | ) |
---|
205 | ) |
---|
206 | { |
---|
207 | $_GET['tab']="metadata"; |
---|
208 | } |
---|
209 | |
---|
210 | /* |
---|
211 | * metadata tabsheet |
---|
212 | */ |
---|
213 | if($_GET['tab']=="metadata") |
---|
214 | { |
---|
215 | if(!isset($_REQUEST['t'])) |
---|
216 | { |
---|
217 | if($this->config['amd_InterfaceMode']=='basic') |
---|
218 | { |
---|
219 | $_REQUEST['t']="display"; |
---|
220 | } |
---|
221 | else |
---|
222 | { |
---|
223 | $_REQUEST['t']="select"; |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | if(!($_REQUEST['t']=="personnal" or |
---|
228 | $_REQUEST['t']=="select" or |
---|
229 | $_REQUEST['t']=="display") |
---|
230 | or |
---|
231 | $this->config['amd_InterfaceMode']=='basic' and |
---|
232 | ( |
---|
233 | $_REQUEST['t']=="select" |
---|
234 | ) |
---|
235 | ) |
---|
236 | { |
---|
237 | if($this->config['amd_InterfaceMode']=='basic') |
---|
238 | { |
---|
239 | $_REQUEST['t']="display"; |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | $_REQUEST['t']="select"; |
---|
244 | } |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | /* |
---|
249 | * help tabsheet |
---|
250 | */ |
---|
251 | if($_GET['tab']=="help") |
---|
252 | { |
---|
253 | if(!isset($_REQUEST['t'])) $_REQUEST['t']="exif"; |
---|
254 | |
---|
255 | if(!($_REQUEST['t']=="exif" or |
---|
256 | $_REQUEST['t']=="iptc" or |
---|
257 | $_REQUEST['t']=="xmp" or |
---|
258 | $_REQUEST['t']=="magic")) $_REQUEST['t']="exif"; |
---|
259 | } |
---|
260 | |
---|
261 | /* |
---|
262 | * search tabsheet |
---|
263 | */ |
---|
264 | if($_GET['tab']=="search") |
---|
265 | { |
---|
266 | if(!isset($_REQUEST['t'])) $_REQUEST['t']="search"; |
---|
267 | |
---|
268 | if(!($_REQUEST['t']=="config" or |
---|
269 | $_REQUEST['t']=="search")) $_REQUEST['t']="search"; |
---|
270 | } |
---|
271 | |
---|
272 | /* |
---|
273 | * database tabsheet |
---|
274 | */ |
---|
275 | if($_GET['tab']=="database") |
---|
276 | { |
---|
277 | if(!isset($_REQUEST['t'])) $_REQUEST['t']="state"; |
---|
278 | |
---|
279 | if(!($_REQUEST['t']=="state" or |
---|
280 | $_REQUEST['t']=="update")) $_REQUEST['t']="state"; |
---|
281 | } |
---|
282 | |
---|
283 | |
---|
284 | } //init_request |
---|
285 | |
---|
286 | |
---|
287 | /** |
---|
288 | * manage adviser profile |
---|
289 | * |
---|
290 | * @return Boolean : true if user is adviser, otherwise false (and push a |
---|
291 | * message in the error list) |
---|
292 | */ |
---|
293 | protected function adviser_abort() |
---|
294 | { |
---|
295 | if(is_adviser()) |
---|
296 | { |
---|
297 | $this->display_result(l10n("g003_adviser_not_allowed"), false); |
---|
298 | return(true); |
---|
299 | } |
---|
300 | return(false); |
---|
301 | } |
---|
302 | |
---|
303 | |
---|
304 | |
---|
305 | |
---|
306 | /** |
---|
307 | * display and manage the search page |
---|
308 | */ |
---|
309 | protected function displaySearch() |
---|
310 | { |
---|
311 | global $template, $lang; |
---|
312 | |
---|
313 | $template->set_filename('body_page', |
---|
314 | dirname($this->getFileLocation()).'/admin/amd_metadata_search.tpl'); |
---|
315 | |
---|
316 | $template->assign('amd_search_page', GPCRequestBuilder::displaySearchPage('AMetaData')); |
---|
317 | |
---|
318 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
319 | } |
---|
320 | |
---|
321 | |
---|
322 | |
---|
323 | |
---|
324 | /** |
---|
325 | * display and manage the metadata page |
---|
326 | * the page have three tabsheet : |
---|
327 | * - personnal tag management, to build personnal tags |
---|
328 | * - select tag management, to manage tags to be selected on the galerie |
---|
329 | * - display tag management, to choose how the tags are displayed |
---|
330 | * |
---|
331 | * @param String $tab : the selected tab on the stat page |
---|
332 | */ |
---|
333 | protected function displayMetaData($tab) |
---|
334 | { |
---|
335 | global $template, $user; |
---|
336 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl'); |
---|
337 | |
---|
338 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
339 | $statTabsheet->select($tab); |
---|
340 | $statTabsheet->add('personnal', |
---|
341 | l10n('g003_personnal'), |
---|
342 | $this->getAdminLink().'-metadata/personnal'); |
---|
343 | if($this->config['amd_InterfaceMode']=='advanced') |
---|
344 | { |
---|
345 | $statTabsheet->add('select', |
---|
346 | l10n('g003_select'), |
---|
347 | $this->getAdminLink().'-metadata/select'); |
---|
348 | } |
---|
349 | $statTabsheet->add('display', |
---|
350 | l10n('g003_display'), |
---|
351 | $this->getAdminLink().'-metadata/display'); |
---|
352 | $statTabsheet->assign(); |
---|
353 | |
---|
354 | switch($tab) |
---|
355 | { |
---|
356 | case 'select': |
---|
357 | $template->assign('sheetContent', $this->displayMetaDataSelect()); |
---|
358 | break; |
---|
359 | case 'display': |
---|
360 | $template->assign('sheetContent', $this->displayMetaDataDisplay()); |
---|
361 | break; |
---|
362 | case 'personnal': |
---|
363 | $template->assign('sheetContent', $this->displayMetaDataPersonnal()); |
---|
364 | break; |
---|
365 | } |
---|
366 | |
---|
367 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
368 | } |
---|
369 | |
---|
370 | |
---|
371 | /** |
---|
372 | * display and manage the metadata page allowing to build user defined tags |
---|
373 | * |
---|
374 | * @return String : the content of the page |
---|
375 | */ |
---|
376 | protected function displayMetaDataPersonnal() |
---|
377 | { |
---|
378 | global $template, $theme, $themes, $themeconf, $lang; |
---|
379 | |
---|
380 | $template->set_filename('sheet_page', |
---|
381 | dirname($this->getFileLocation()).'/admin/amd_metadata_personnal.tpl'); |
---|
382 | |
---|
383 | $datas=array( |
---|
384 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
385 | 'tagList' => array(), |
---|
386 | ); |
---|
387 | |
---|
388 | /* |
---|
389 | * build tagList |
---|
390 | */ |
---|
391 | $sql="SELECT ut.name, ut.numId, ut.tagId |
---|
392 | FROM ".$this->tables['used_tags']." ut |
---|
393 | JOIN ".$this->tables['selected_tags']." st ON st.tagId = ut.tagId |
---|
394 | ORDER BY tagId"; |
---|
395 | $result=pwg_query($sql); |
---|
396 | if($result) |
---|
397 | { |
---|
398 | while($row=pwg_db_fetch_assoc($result)) |
---|
399 | { |
---|
400 | $datas['tagList'][]=Array( |
---|
401 | 'tagId' => $row['tagId'], |
---|
402 | 'name' => L10n::get($row['name']), |
---|
403 | 'numId' => $row['numId'] |
---|
404 | ); |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | $lang['g003_personnal_page_help']=GPCCore::BBtoHTML($lang['g003_personnal_page_help']); |
---|
409 | |
---|
410 | $template->assign('datas', $datas); |
---|
411 | return($template->parse('sheet_page', true)); |
---|
412 | } |
---|
413 | |
---|
414 | |
---|
415 | /** |
---|
416 | * display and manage the metadata page allowing to make tags selection |
---|
417 | * |
---|
418 | * @return String : the content of the page |
---|
419 | */ |
---|
420 | protected function displayMetaDataSelect() |
---|
421 | { |
---|
422 | global $template, $theme, $themes, $themeconf, $lang; |
---|
423 | |
---|
424 | $template->set_filename('sheet_page', |
---|
425 | dirname($this->getFileLocation()).'/admin/amd_metadata_select.tpl'); |
---|
426 | |
---|
427 | $datas=array( |
---|
428 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
429 | 'config_GetListTags_OrderType' => $this->config['amd_GetListTags_OrderType'], |
---|
430 | 'config_GetListTags_FilterType' => $this->config['amd_GetListTags_FilterType'], |
---|
431 | 'config_GetListTags_ExcludeUnusedTag' => $this->config['amd_GetListTags_ExcludeUnusedTag'], |
---|
432 | 'config_GetListTags_SelectedTagOnly' => $this->config['amd_GetListTags_SelectedTagOnly'], |
---|
433 | 'config_GetListImages_OrderType' => $this->config['amd_GetListImages_OrderType'] |
---|
434 | ); |
---|
435 | |
---|
436 | $lang['g003_select_page_help']=GPCCore::BBtoHTML($lang['g003_select_page_help']); |
---|
437 | |
---|
438 | $template->assign('datas', $datas); |
---|
439 | return($template->parse('sheet_page', true)); |
---|
440 | } |
---|
441 | |
---|
442 | |
---|
443 | /** |
---|
444 | * display and manage the metadata page allowing to choose tags order |
---|
445 | * |
---|
446 | * @return String : the content of the page |
---|
447 | */ |
---|
448 | protected function displayMetaDataDisplay() |
---|
449 | { |
---|
450 | global $user, $template, $lang; |
---|
451 | |
---|
452 | //$local_tpl = new Template(AMD_PATH."admin/", ""); |
---|
453 | $template->set_filename('sheet_page', |
---|
454 | dirname($this->getFileLocation()).'/admin/amd_metadata_display.tpl'); |
---|
455 | |
---|
456 | $datas=array( |
---|
457 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
458 | 'selectedTags' => Array(), |
---|
459 | 'groups' => Array(), |
---|
460 | 'tagByGroup' => Array(), |
---|
461 | ); |
---|
462 | |
---|
463 | $sql="SELECT st.tagId, st.order, st.groupId, ut.numId |
---|
464 | FROM ".$this->tables['selected_tags']." st |
---|
465 | LEFT JOIN ".$this->tables['used_tags']." ut |
---|
466 | ON ut.tagId = st.tagId |
---|
467 | ORDER BY st.groupId ASC, st.order ASC, st.tagId ASC"; |
---|
468 | $result=pwg_query($sql); |
---|
469 | if($result) |
---|
470 | { |
---|
471 | while($row=pwg_db_fetch_assoc($result)) |
---|
472 | { |
---|
473 | if($row['groupId']==-1) |
---|
474 | { |
---|
475 | $datas['selectedTags'][]=Array( |
---|
476 | 'numId' => $row['numId'], |
---|
477 | 'tagId' => $row['tagId'] |
---|
478 | ); |
---|
479 | } |
---|
480 | else |
---|
481 | { |
---|
482 | $datas['tagByGroup'][]=Array( |
---|
483 | 'numId' => $row['numId'], |
---|
484 | 'tagId' => $row['tagId'], |
---|
485 | 'group' => $row['groupId'], |
---|
486 | 'order' => $row['order'] |
---|
487 | ); |
---|
488 | } |
---|
489 | } |
---|
490 | } |
---|
491 | |
---|
492 | $sql="SELECT g.groupId, gn.name |
---|
493 | FROM ".$this->tables['groups']." g |
---|
494 | LEFT JOIN ".$this->tables['groups_names']." gn |
---|
495 | ON g.groupId = gn.groupId |
---|
496 | WHERE gn.lang = '".$user['language']."' |
---|
497 | ORDER BY g.order;"; |
---|
498 | $result=pwg_query($sql); |
---|
499 | if($result) |
---|
500 | { |
---|
501 | while($row=pwg_db_fetch_assoc($result)) |
---|
502 | { |
---|
503 | $datas['groups'][]=Array( |
---|
504 | 'id' => $row['groupId'], |
---|
505 | 'name' => $row['name'] |
---|
506 | ); |
---|
507 | } |
---|
508 | } |
---|
509 | |
---|
510 | $lang['g003_display_page_help']=GPCCore::BBtoHTML($lang['g003_display_page_help']); |
---|
511 | $template->assign('datas', $datas); |
---|
512 | return($template->parse('sheet_page', true)); |
---|
513 | } |
---|
514 | |
---|
515 | |
---|
516 | /** |
---|
517 | * display and manage the database page |
---|
518 | * the page have two tabsheet : |
---|
519 | * - state, to have general information about the database |
---|
520 | * - update, to manage database fill-in |
---|
521 | * |
---|
522 | * @param String $tab : the selected tab on the stat page |
---|
523 | */ |
---|
524 | protected function displayDatabase($tab) |
---|
525 | { |
---|
526 | global $template, $user; |
---|
527 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl'); |
---|
528 | |
---|
529 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
530 | $statTabsheet->select($tab); |
---|
531 | $statTabsheet->add('state', |
---|
532 | l10n('g003_state'), |
---|
533 | $this->getAdminLink().'-database/state'); |
---|
534 | $statTabsheet->add('update', |
---|
535 | l10n('g003_update'), |
---|
536 | $this->getAdminLink().'-database/update'); |
---|
537 | $statTabsheet->assign(); |
---|
538 | |
---|
539 | switch($tab) |
---|
540 | { |
---|
541 | case 'state': |
---|
542 | $template->assign('sheetContent', $this->displayDatabaseStatus()); |
---|
543 | break; |
---|
544 | case 'update': |
---|
545 | $template->assign('sheetContent', $this->displayDatabaseDatabase()); |
---|
546 | break; |
---|
547 | } |
---|
548 | |
---|
549 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
550 | } |
---|
551 | |
---|
552 | |
---|
553 | |
---|
554 | /** |
---|
555 | * display the database status |
---|
556 | * |
---|
557 | * @return String : the content of the page |
---|
558 | */ |
---|
559 | private function displayDatabaseStatus() |
---|
560 | { |
---|
561 | global $template, $page; |
---|
562 | |
---|
563 | $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_status.tpl'); |
---|
564 | |
---|
565 | $warning2=''; |
---|
566 | $sql="SELECT tagId |
---|
567 | FROM ".$this->tables['used_tags']." |
---|
568 | WHERE newFromLastUpdate='y'"; |
---|
569 | $result=pwg_query($sql); |
---|
570 | if($result) |
---|
571 | { |
---|
572 | $tmp=array(); |
---|
573 | $tagSchema=''; |
---|
574 | while($row=pwg_db_fetch_assoc($result)) |
---|
575 | { |
---|
576 | if(preg_match('/^([a-z0-9]*)\..*/i', $row['tagId'], $tagSchema)) |
---|
577 | { |
---|
578 | if(!in_array($tagSchema[1],$this->config['amd_FillDataBaseIgnoreSchemas'])) $tmp[]=$row['tagId']; |
---|
579 | } |
---|
580 | } |
---|
581 | if(count($tmp)>0) |
---|
582 | { |
---|
583 | $ul=''; |
---|
584 | foreach($tmp as $val) |
---|
585 | { |
---|
586 | $ul.='<li>'.$val.'</li>'; |
---|
587 | } |
---|
588 | if(count($tmp)>1) |
---|
589 | { |
---|
590 | $warning2=sprintf(GPCCore::BBtoHTML(l10n('g003_databaseWarning2_n')),$ul); |
---|
591 | } |
---|
592 | else |
---|
593 | { |
---|
594 | $warning2=sprintf(GPCCore::BBtoHTML(l10n('g003_databaseWarning2_1')),$ul); |
---|
595 | } |
---|
596 | } |
---|
597 | } |
---|
598 | |
---|
599 | |
---|
600 | $datas=array( |
---|
601 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
602 | 'warning2' => $warning2, |
---|
603 | 'warning1' => GPCCore::BBtoHTML(l10n('g003_databaseWarning1')), |
---|
604 | 'nfoMetadata' => Array( |
---|
605 | 'exif' => 0, |
---|
606 | 'iptc' => 0, |
---|
607 | 'magic' => 0, |
---|
608 | 'xmp' => 0, |
---|
609 | 'com' => 0, |
---|
610 | 'userDefined' => 0, |
---|
611 | 'numOfPictures' => 0, |
---|
612 | 'numOfNotAnalyzedPictures' => 0, |
---|
613 | 'numOfPicturesWithoutTag' => 0, |
---|
614 | 'nfoSize' => 0, |
---|
615 | 'nfoRows' => 0, |
---|
616 | 'nfoSizeAndRows' => '', |
---|
617 | ) |
---|
618 | ); |
---|
619 | |
---|
620 | $sql="SELECT SUM(numOfImg) AS nb, 'exif' AS `type` |
---|
621 | FROM ".$this->tables['used_tags']." |
---|
622 | WHERE tagId LIKE 'exif.%' |
---|
623 | UNION |
---|
624 | SELECT SUM(numOfImg), 'iptc' |
---|
625 | FROM ".$this->tables['used_tags']." |
---|
626 | WHERE tagId LIKE 'iptc.%' |
---|
627 | UNION |
---|
628 | SELECT SUM(numOfImg), 'magic' |
---|
629 | FROM ".$this->tables['used_tags']." |
---|
630 | WHERE tagId LIKE 'magic.%' |
---|
631 | UNION |
---|
632 | SELECT SUM(numOfImg), 'xmp' |
---|
633 | FROM ".$this->tables['used_tags']." |
---|
634 | WHERE tagId LIKE 'xmp.%' |
---|
635 | UNION |
---|
636 | SELECT SUM(numOfImg), 'com' |
---|
637 | FROM ".$this->tables['used_tags']." |
---|
638 | WHERE tagId LIKE 'com.%' |
---|
639 | UNION |
---|
640 | SELECT SUM(numOfImg), 'userDefined' |
---|
641 | FROM ".$this->tables['used_tags']." |
---|
642 | WHERE tagId LIKE 'userDefined.%' |
---|
643 | UNION |
---|
644 | SELECT COUNT(imageId), 'numOfPictures' |
---|
645 | FROM ".$this->tables['images']." |
---|
646 | WHERE analyzed='y' |
---|
647 | UNION |
---|
648 | SELECT COUNT(imageId), 'numOfNotAnalyzedPictures' |
---|
649 | FROM ".$this->tables['images']." |
---|
650 | WHERE analyzed='n' |
---|
651 | UNION |
---|
652 | SELECT COUNT(imageId), 'numOfPicturesWithoutTag' |
---|
653 | FROM ".$this->tables['images']." |
---|
654 | WHERE nbTags=0"; |
---|
655 | $result=pwg_query($sql); |
---|
656 | if($result) |
---|
657 | { |
---|
658 | while($row=pwg_db_fetch_assoc($result)) |
---|
659 | { |
---|
660 | if(!is_null($row['nb'])) |
---|
661 | { |
---|
662 | $datas['nfoMetadata'][$row['type']]=$row['nb']; |
---|
663 | if($row['type']=='exif' or |
---|
664 | $row['type']=='iptc' or |
---|
665 | $row['type']=='magic' or |
---|
666 | $row['type']=='xmp' or |
---|
667 | $row['type']=='com' or |
---|
668 | $row['type']=='userDefined') $datas['nfoMetadata']['nfoRows']+=$row['nb']; |
---|
669 | } |
---|
670 | } |
---|
671 | } |
---|
672 | |
---|
673 | $sql="SHOW TABLE STATUS WHERE name LIKE '".$this->tables['images_tags']."'"; |
---|
674 | $result=pwg_query($sql); |
---|
675 | if($result) |
---|
676 | { |
---|
677 | while($row=pwg_db_fetch_assoc($result)) |
---|
678 | { |
---|
679 | $datas['nfoMetadata']['nfoSize']=$row['Data_length']+$row['Index_length']; |
---|
680 | } |
---|
681 | } |
---|
682 | |
---|
683 | if($datas['nfoMetadata']['nfoSize']<1048576) |
---|
684 | { |
---|
685 | $datas['nfoMetadata']['nfoSize']=sprintf('%.2fKio', $datas['nfoMetadata']['nfoSize']/1024); |
---|
686 | } |
---|
687 | else |
---|
688 | { |
---|
689 | $datas['nfoMetadata']['nfoSize']=sprintf('%.2fMio', $datas['nfoMetadata']['nfoSize']/1048576); |
---|
690 | } |
---|
691 | $datas['nfoMetadata']['nfoSizeAndRows']=sprintf(l10n('g003_sizeAndRows'), $datas['nfoMetadata']['nfoSize'], $datas['nfoMetadata']['nfoRows']); |
---|
692 | $datas['nfoMetadata']['numOfPictures']=sprintf(l10n('g003_numberOfAnalyzedPictures'), $datas['nfoMetadata']['numOfPictures']); |
---|
693 | $datas['nfoMetadata']['numOfNotAnalyzedPictures']=sprintf(l10n('g003_numberOfNotAnalyzedPictures'), $datas['nfoMetadata']['numOfNotAnalyzedPictures']); |
---|
694 | $datas['nfoMetadata']['numOfPicturesWithoutTag']=sprintf(l10n('g003_numberOfPicturesWithoutTags'), $datas['nfoMetadata']['numOfPicturesWithoutTag']); |
---|
695 | |
---|
696 | $template->assign("datas", $datas); |
---|
697 | |
---|
698 | return($template->parse('sheet_page', true)); |
---|
699 | } // displayDatabaseStatus |
---|
700 | |
---|
701 | |
---|
702 | |
---|
703 | |
---|
704 | /** |
---|
705 | * display and manage the database page |
---|
706 | * |
---|
707 | * the function automatically update the AMD tables : |
---|
708 | * - add new pictures in the AMD image table (assuming image is not analyzed |
---|
709 | * yet) |
---|
710 | * - remove deleted pictures in the AMD image & image_tags table |
---|
711 | * |
---|
712 | * @return String : the content of the page |
---|
713 | */ |
---|
714 | private function displayDatabaseDatabase() |
---|
715 | { |
---|
716 | global $template, $page, $user; |
---|
717 | |
---|
718 | /* |
---|
719 | * insert new image (from piwigo images table) in the AMD images table, with |
---|
720 | * statut 'not analyzed' |
---|
721 | */ |
---|
722 | $sql="INSERT INTO ".$this->tables['images']." |
---|
723 | SELECT id, 'n', 0 |
---|
724 | FROM ".IMAGES_TABLE." |
---|
725 | WHERE id NOT IN (SELECT imageId FROM ".$this->tables['images'].")"; |
---|
726 | pwg_query($sql); |
---|
727 | |
---|
728 | |
---|
729 | /* |
---|
730 | * delete image who are in the AMD images table and not in the piwigo image |
---|
731 | * table |
---|
732 | */ |
---|
733 | $sql="DELETE FROM ".$this->tables['images']." |
---|
734 | WHERE imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.")"; |
---|
735 | pwg_query($sql); |
---|
736 | |
---|
737 | |
---|
738 | /* |
---|
739 | * delete metadata for images that are not in the AMD image table |
---|
740 | */ |
---|
741 | $sql="DELETE ait |
---|
742 | FROM ".$this->tables['images_tags']." ait |
---|
743 | JOIN (SELECT DISTINCT imageId FROM ".$this->tables['images_tags']." ) aitd |
---|
744 | ON ait.imageId=aitd.imageId |
---|
745 | WHERE aitd.imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.") "; |
---|
746 | pwg_query($sql); |
---|
747 | |
---|
748 | |
---|
749 | $caddieNbPictures=0; |
---|
750 | $sql="SELECT COUNT(element_id) AS nbPictures |
---|
751 | FROM ".CADDIE_TABLE." |
---|
752 | WHERE user_id='".$user['id']."';"; |
---|
753 | $result=pwg_query($sql); |
---|
754 | if($result) |
---|
755 | { |
---|
756 | while($row=pwg_db_fetch_assoc($result)) |
---|
757 | { |
---|
758 | $caddieNbPictures=$row['nbPictures']; |
---|
759 | } |
---|
760 | } |
---|
761 | |
---|
762 | |
---|
763 | $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_database.tpl'); |
---|
764 | |
---|
765 | $datas=array( |
---|
766 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
767 | 'NumberOfItemsPerRequest' => $this->config['amd_NumberOfItemsPerRequest'], |
---|
768 | 'caddieNbPictures' => ($caddieNbPictures==1)?l10n('g003_1_picture_in_caddie'):sprintf(l10n('g003_n_pictures_in_caddie'), $caddieNbPictures) |
---|
769 | ); |
---|
770 | |
---|
771 | $template->assign("datas", $datas); |
---|
772 | |
---|
773 | return($template->parse('sheet_page', true)); |
---|
774 | } // displayDatabase |
---|
775 | |
---|
776 | |
---|
777 | |
---|
778 | |
---|
779 | |
---|
780 | /** |
---|
781 | * display and manage the help page |
---|
782 | * |
---|
783 | * @param String $tab : the selected tab on the help page |
---|
784 | */ |
---|
785 | protected function displayHelp() |
---|
786 | { |
---|
787 | global $template, $user, $lang; |
---|
788 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_help.tpl'); |
---|
789 | |
---|
790 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
791 | $statTabsheet->add('exif', |
---|
792 | l10n('g003_help_tab_exif'), |
---|
793 | '', true, "displayHelp('exif');"); |
---|
794 | $statTabsheet->add('iptc', |
---|
795 | l10n('g003_help_tab_iptc'), |
---|
796 | '', false, "displayHelp('iptc');"); |
---|
797 | $statTabsheet->add('xmp', |
---|
798 | l10n('g003_help_tab_xmp'), |
---|
799 | '', false, "displayHelp('xmp');"); |
---|
800 | $statTabsheet->add('magic', |
---|
801 | l10n('g003_help_tab_magic'), |
---|
802 | '', false, "displayHelp('magic');"); |
---|
803 | $statTabsheet->assign(); |
---|
804 | |
---|
805 | $data=Array( |
---|
806 | 'sheetContent_exif' => GPCCore::BBtoHTML($lang['g003_help_exif']), |
---|
807 | 'sheetContent_xmp' => GPCCore::BBtoHTML($lang['g003_help_xmp']), |
---|
808 | 'sheetContent_iptc' => GPCCore::BBtoHTML($lang['g003_help_iptc']), |
---|
809 | 'sheetContent_magic' => GPCCore::BBtoHTML($lang['g003_help_magic']), |
---|
810 | 'title_exif' => l10n('g003_help_tab_exif'), |
---|
811 | 'title_xmp' => l10n('g003_help_tab_xmp'), |
---|
812 | 'title_iptc' => l10n('g003_help_tab_iptc'), |
---|
813 | 'title_magic' => l10n('g003_help_tab_magic') |
---|
814 | ); |
---|
815 | |
---|
816 | $template->assign('data', $data); |
---|
817 | |
---|
818 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
819 | } |
---|
820 | |
---|
821 | |
---|
822 | /** |
---|
823 | * display and manage the tags page |
---|
824 | * |
---|
825 | */ |
---|
826 | protected function displayTags() |
---|
827 | { |
---|
828 | global $template, $user, $lang; |
---|
829 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata_tags.tpl'); |
---|
830 | |
---|
831 | $datas=array( |
---|
832 | 'urlRequest' => $this->getAdminLink('ajax') |
---|
833 | ); |
---|
834 | |
---|
835 | $lang['g003_tags_page_help']=GPCCore::BBtoHTML($lang['g003_tags_page_help']); |
---|
836 | |
---|
837 | $template->assign('datas', $datas); |
---|
838 | |
---|
839 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
840 | } |
---|
841 | |
---|
842 | |
---|
843 | } // AMD_AIP class |
---|
844 | |
---|
845 | |
---|
846 | ?> |
---|