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().'&fAMD_tabsheet=metadata'); |
---|
56 | $this->tabsheet->add('help', |
---|
57 | l10n('g003_help'), |
---|
58 | $this->getAdminLink().'&fAMD_tabsheet=help'); |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | $this->tabsheet->add('database', |
---|
63 | l10n('g003_database'), |
---|
64 | $this->getAdminLink().'&fAMD_tabsheet=database'); |
---|
65 | $this->tabsheet->add('metadata', |
---|
66 | l10n('g003_metadata'), |
---|
67 | $this->getAdminLink().'&fAMD_tabsheet=metadata'); |
---|
68 | $this->tabsheet->add('search', |
---|
69 | l10n('g003_search'), |
---|
70 | $this->getAdminLink().'&fAMD_tabsheet=search'); |
---|
71 | $this->tabsheet->add('tags', |
---|
72 | l10n('g003_tags'), |
---|
73 | $this->getAdminLink().'&fAMD_tabsheet=tags'); |
---|
74 | $this->tabsheet->add('help', |
---|
75 | l10n('g003_help'), |
---|
76 | $this->getAdminLink().'&fAMD_tabsheet=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($_REQUEST['fAMD_tabsheet']); |
---|
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' => $_REQUEST['fAMD_tabsheet'], |
---|
114 | 'PATH' => AMD_PATH |
---|
115 | ); |
---|
116 | |
---|
117 | $template->assign('plugin', $pluginInfo); |
---|
118 | |
---|
119 | switch($_REQUEST['fAMD_tabsheet']) |
---|
120 | { |
---|
121 | case 'help': |
---|
122 | $this->displayHelp(); |
---|
123 | break; |
---|
124 | case 'database': |
---|
125 | $this->displayDatabase($_REQUEST['fAMD_page']); |
---|
126 | break; |
---|
127 | case 'metadata': |
---|
128 | $this->displayMetaData($_REQUEST['fAMD_page']); |
---|
129 | break; |
---|
130 | case 'search': |
---|
131 | $this->displaySearch($_REQUEST['fAMD_page']); |
---|
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($_REQUEST['fAMD_tabsheet']) and $_REQUEST['fAMD_tabsheet']=='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($_REQUEST['fAMD_tabsheet'])) |
---|
175 | { |
---|
176 | if($this->getNumOfPictures()==0 and $this->config['amd_InterfaceMode']=='advanced') |
---|
177 | { |
---|
178 | $_REQUEST['fAMD_tabsheet']="database"; |
---|
179 | $_REQUEST['fAMD_page']="state"; |
---|
180 | } |
---|
181 | else |
---|
182 | { |
---|
183 | $_REQUEST['fAMD_tabsheet']="metadata"; |
---|
184 | $_REQUEST['fAMD_page']="select"; |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | if(!($_REQUEST['fAMD_tabsheet']=="metadata" or |
---|
189 | $_REQUEST['fAMD_tabsheet']=="help" or |
---|
190 | $_REQUEST['fAMD_tabsheet']=="database" or |
---|
191 | $_REQUEST['fAMD_tabsheet']=="search" or |
---|
192 | $_REQUEST['fAMD_tabsheet']=="tags") |
---|
193 | or |
---|
194 | $this->config['amd_InterfaceMode']=='basic' and |
---|
195 | ( |
---|
196 | $_REQUEST['fAMD_tabsheet']=="database" or |
---|
197 | $_REQUEST['fAMD_tabsheet']=="search" or |
---|
198 | $_REQUEST['fAMD_tabsheet']=="tags" |
---|
199 | ) |
---|
200 | ) |
---|
201 | { |
---|
202 | $_REQUEST['fAMD_tabsheet']="metadata"; |
---|
203 | } |
---|
204 | |
---|
205 | /* |
---|
206 | * metadata tabsheet |
---|
207 | */ |
---|
208 | if($_REQUEST['fAMD_tabsheet']=="metadata") |
---|
209 | { |
---|
210 | if(!isset($_REQUEST['fAMD_page'])) |
---|
211 | { |
---|
212 | if($this->config['amd_InterfaceMode']=='basic') |
---|
213 | { |
---|
214 | $_REQUEST['fAMD_page']="display"; |
---|
215 | } |
---|
216 | else |
---|
217 | { |
---|
218 | $_REQUEST['fAMD_page']="select"; |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | if(!($_REQUEST['fAMD_page']=="personnal" or |
---|
223 | $_REQUEST['fAMD_page']=="select" or |
---|
224 | $_REQUEST['fAMD_page']=="display") |
---|
225 | or |
---|
226 | $this->config['amd_InterfaceMode']=='basic' and |
---|
227 | ( |
---|
228 | $_REQUEST['fAMD_page']=="select" |
---|
229 | ) |
---|
230 | ) |
---|
231 | { |
---|
232 | if($this->config['amd_InterfaceMode']=='basic') |
---|
233 | { |
---|
234 | $_REQUEST['fAMD_page']="display"; |
---|
235 | } |
---|
236 | else |
---|
237 | { |
---|
238 | $_REQUEST['fAMD_page']="select"; |
---|
239 | } |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | /* |
---|
244 | * help tabsheet |
---|
245 | */ |
---|
246 | if($_REQUEST['fAMD_tabsheet']=="help") |
---|
247 | { |
---|
248 | if(!isset($_REQUEST['fAMD_page'])) $_REQUEST['fAMD_page']="exif"; |
---|
249 | |
---|
250 | if(!($_REQUEST['fAMD_page']=="exif" or |
---|
251 | $_REQUEST['fAMD_page']=="iptc" or |
---|
252 | $_REQUEST['fAMD_page']=="xmp" or |
---|
253 | $_REQUEST['fAMD_page']=="magic")) $_REQUEST['fAMD_page']="exif"; |
---|
254 | } |
---|
255 | |
---|
256 | /* |
---|
257 | * search tabsheet |
---|
258 | */ |
---|
259 | if($_REQUEST['fAMD_tabsheet']=="search") |
---|
260 | { |
---|
261 | if(!isset($_REQUEST['fAMD_page'])) $_REQUEST['fAMD_page']="search"; |
---|
262 | |
---|
263 | if(!($_REQUEST['fAMD_page']=="config" or |
---|
264 | $_REQUEST['fAMD_page']=="search")) $_REQUEST['fAMD_page']="search"; |
---|
265 | } |
---|
266 | |
---|
267 | /* |
---|
268 | * database tabsheet |
---|
269 | */ |
---|
270 | if($_REQUEST['fAMD_tabsheet']=="database") |
---|
271 | { |
---|
272 | if(!isset($_REQUEST['fAMD_page'])) $_REQUEST['fAMD_page']="state"; |
---|
273 | |
---|
274 | if(!($_REQUEST['fAMD_page']=="state" or |
---|
275 | $_REQUEST['fAMD_page']=="update")) $_REQUEST['fAMD_page']="state"; |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | } //init_request |
---|
280 | |
---|
281 | |
---|
282 | /** |
---|
283 | * manage adviser profile |
---|
284 | * |
---|
285 | * @return Boolean : true if user is adviser, otherwise false (and push a |
---|
286 | * message in the error list) |
---|
287 | */ |
---|
288 | protected function adviser_abort() |
---|
289 | { |
---|
290 | if(is_adviser()) |
---|
291 | { |
---|
292 | $this->display_result(l10n("g003_adviser_not_allowed"), false); |
---|
293 | return(true); |
---|
294 | } |
---|
295 | return(false); |
---|
296 | } |
---|
297 | |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | /** |
---|
302 | * display and manage the search page |
---|
303 | */ |
---|
304 | protected function displaySearch() |
---|
305 | { |
---|
306 | global $template, $lang; |
---|
307 | |
---|
308 | $template->set_filename('body_page', |
---|
309 | dirname($this->getFileLocation()).'/admin/amd_metadata_search.tpl'); |
---|
310 | |
---|
311 | $template->assign('amd_search_page', GPCRequestBuilder::displaySearchPage($this->getPluginName())); |
---|
312 | |
---|
313 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
314 | } |
---|
315 | |
---|
316 | |
---|
317 | |
---|
318 | |
---|
319 | /** |
---|
320 | * display and manage the metadata page |
---|
321 | * the page have three tabsheet : |
---|
322 | * - personnal tag management, to build personnal tags |
---|
323 | * - select tag management, to manage tags to be selected on the galerie |
---|
324 | * - display tag management, to choose how the tags are displayed |
---|
325 | * |
---|
326 | * @param String $tab : the selected tab on the stat page |
---|
327 | */ |
---|
328 | protected function displayMetaData($tab) |
---|
329 | { |
---|
330 | global $template, $user; |
---|
331 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl'); |
---|
332 | |
---|
333 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
334 | $statTabsheet->select($tab); |
---|
335 | $statTabsheet->add('personnal', |
---|
336 | l10n('g003_personnal'), |
---|
337 | $this->getAdminLink().'&fAMD_tabsheet=metadata&fAMD_page=personnal'); |
---|
338 | if($this->config['amd_InterfaceMode']=='advanced') |
---|
339 | { |
---|
340 | $statTabsheet->add('select', |
---|
341 | l10n('g003_select'), |
---|
342 | $this->getAdminLink().'&fAMD_tabsheet=metadata&fAMD_page=select'); |
---|
343 | } |
---|
344 | $statTabsheet->add('display', |
---|
345 | l10n('g003_display'), |
---|
346 | $this->getAdminLink().'&fAMD_tabsheet=metadata&fAMD_page=display'); |
---|
347 | $statTabsheet->assign(); |
---|
348 | |
---|
349 | switch($tab) |
---|
350 | { |
---|
351 | case 'select': |
---|
352 | $template->assign('sheetContent', $this->displayMetaDataSelect()); |
---|
353 | break; |
---|
354 | case 'display': |
---|
355 | $template->assign('sheetContent', $this->displayMetaDataDisplay()); |
---|
356 | break; |
---|
357 | case 'personnal': |
---|
358 | $template->assign('sheetContent', $this->displayMetaDataPersonnal()); |
---|
359 | break; |
---|
360 | } |
---|
361 | |
---|
362 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
363 | } |
---|
364 | |
---|
365 | |
---|
366 | /** |
---|
367 | * display and manage the metadata page allowing to build user defined tags |
---|
368 | * |
---|
369 | * @return String : the content of the page |
---|
370 | */ |
---|
371 | protected function displayMetaDataPersonnal() |
---|
372 | { |
---|
373 | global $template, $theme, $themes, $themeconf, $lang; |
---|
374 | |
---|
375 | $template->set_filename('sheet_page', |
---|
376 | dirname($this->getFileLocation()).'/admin/amd_metadata_personnal.tpl'); |
---|
377 | |
---|
378 | $datas=array( |
---|
379 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
380 | 'tagList' => array(), |
---|
381 | ); |
---|
382 | |
---|
383 | /* |
---|
384 | * build tagList |
---|
385 | */ |
---|
386 | $sql="SELECT ut.name, ut.numId, ut.tagId |
---|
387 | FROM ".$this->tables['used_tags']." ut |
---|
388 | JOIN ".$this->tables['selected_tags']." st ON st.tagId = ut.tagId |
---|
389 | ORDER BY tagId"; |
---|
390 | $result=pwg_query($sql); |
---|
391 | if($result) |
---|
392 | { |
---|
393 | while($row=pwg_db_fetch_assoc($result)) |
---|
394 | { |
---|
395 | $datas['tagList'][]=Array( |
---|
396 | 'tagId' => $row['tagId'], |
---|
397 | 'name' => L10n::get($row['name']), |
---|
398 | 'numId' => $row['numId'] |
---|
399 | ); |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | $lang['g003_personnal_page_help']=GPCCore::BBtoHTML($lang['g003_personnal_page_help']); |
---|
404 | |
---|
405 | $template->assign('datas', $datas); |
---|
406 | return($template->parse('sheet_page', true)); |
---|
407 | } |
---|
408 | |
---|
409 | |
---|
410 | /** |
---|
411 | * display and manage the metadata page allowing to make tags selection |
---|
412 | * |
---|
413 | * @return String : the content of the page |
---|
414 | */ |
---|
415 | protected function displayMetaDataSelect() |
---|
416 | { |
---|
417 | global $template, $theme, $themes, $themeconf, $lang; |
---|
418 | |
---|
419 | $template->set_filename('sheet_page', |
---|
420 | dirname($this->getFileLocation()).'/admin/amd_metadata_select.tpl'); |
---|
421 | |
---|
422 | $datas=array( |
---|
423 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
424 | 'config_GetListTags_OrderType' => $this->config['amd_GetListTags_OrderType'], |
---|
425 | 'config_GetListTags_FilterType' => $this->config['amd_GetListTags_FilterType'], |
---|
426 | 'config_GetListTags_ExcludeUnusedTag' => $this->config['amd_GetListTags_ExcludeUnusedTag'], |
---|
427 | 'config_GetListTags_SelectedTagOnly' => $this->config['amd_GetListTags_SelectedTagOnly'], |
---|
428 | 'config_GetListImages_OrderType' => $this->config['amd_GetListImages_OrderType'] |
---|
429 | ); |
---|
430 | |
---|
431 | $lang['g003_select_page_help']=GPCCore::BBtoHTML($lang['g003_select_page_help']); |
---|
432 | |
---|
433 | $template->assign('datas', $datas); |
---|
434 | return($template->parse('sheet_page', true)); |
---|
435 | } |
---|
436 | |
---|
437 | |
---|
438 | /** |
---|
439 | * display and manage the metadata page allowing to choose tags order |
---|
440 | * |
---|
441 | * @return String : the content of the page |
---|
442 | */ |
---|
443 | protected function displayMetaDataDisplay() |
---|
444 | { |
---|
445 | global $user, $template, $lang; |
---|
446 | |
---|
447 | //$local_tpl = new Template(AMD_PATH."admin/", ""); |
---|
448 | $template->set_filename('sheet_page', |
---|
449 | dirname($this->getFileLocation()).'/admin/amd_metadata_display.tpl'); |
---|
450 | |
---|
451 | $datas=array( |
---|
452 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
453 | 'selectedTags' => Array(), |
---|
454 | 'groups' => Array(), |
---|
455 | 'tagByGroup' => Array(), |
---|
456 | ); |
---|
457 | |
---|
458 | $sql="SELECT st.tagId, st.order, st.groupId, ut.numId |
---|
459 | FROM ".$this->tables['selected_tags']." st |
---|
460 | LEFT JOIN ".$this->tables['used_tags']." ut |
---|
461 | ON ut.tagId = st.tagId |
---|
462 | ORDER BY st.groupId ASC, st.order ASC, st.tagId ASC"; |
---|
463 | $result=pwg_query($sql); |
---|
464 | if($result) |
---|
465 | { |
---|
466 | while($row=pwg_db_fetch_assoc($result)) |
---|
467 | { |
---|
468 | if($row['groupId']==-1) |
---|
469 | { |
---|
470 | $datas['selectedTags'][]=Array( |
---|
471 | 'numId' => $row['numId'], |
---|
472 | 'tagId' => $row['tagId'] |
---|
473 | ); |
---|
474 | } |
---|
475 | else |
---|
476 | { |
---|
477 | $datas['tagByGroup'][]=Array( |
---|
478 | 'numId' => $row['numId'], |
---|
479 | 'tagId' => $row['tagId'], |
---|
480 | 'group' => $row['groupId'], |
---|
481 | 'order' => $row['order'] |
---|
482 | ); |
---|
483 | } |
---|
484 | } |
---|
485 | } |
---|
486 | |
---|
487 | $sql="SELECT g.groupId, gn.name |
---|
488 | FROM ".$this->tables['groups']." g |
---|
489 | LEFT JOIN ".$this->tables['groups_names']." gn |
---|
490 | ON g.groupId = gn.groupId |
---|
491 | WHERE gn.lang = '".$user['language']."' |
---|
492 | ORDER BY g.order;"; |
---|
493 | $result=pwg_query($sql); |
---|
494 | if($result) |
---|
495 | { |
---|
496 | while($row=pwg_db_fetch_assoc($result)) |
---|
497 | { |
---|
498 | $datas['groups'][]=Array( |
---|
499 | 'id' => $row['groupId'], |
---|
500 | 'name' => $row['name'] |
---|
501 | ); |
---|
502 | } |
---|
503 | } |
---|
504 | |
---|
505 | $lang['g003_display_page_help']=GPCCore::BBtoHTML($lang['g003_display_page_help']); |
---|
506 | $template->assign('datas', $datas); |
---|
507 | return($template->parse('sheet_page', true)); |
---|
508 | } |
---|
509 | |
---|
510 | |
---|
511 | /** |
---|
512 | * display and manage the database page |
---|
513 | * the page have two tabsheet : |
---|
514 | * - state, to have general information about the database |
---|
515 | * - update, to manage database fill-in |
---|
516 | * |
---|
517 | * @param String $tab : the selected tab on the stat page |
---|
518 | */ |
---|
519 | protected function displayDatabase($tab) |
---|
520 | { |
---|
521 | global $template, $user; |
---|
522 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl'); |
---|
523 | |
---|
524 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
525 | $statTabsheet->select($tab); |
---|
526 | $statTabsheet->add('state', |
---|
527 | l10n('g003_state'), |
---|
528 | $this->getAdminLink().'&fAMD_tabsheet=database&fAMD_page=state'); |
---|
529 | $statTabsheet->add('update', |
---|
530 | l10n('g003_update'), |
---|
531 | $this->getAdminLink().'&fAMD_tabsheet=database&fAMD_page=update'); |
---|
532 | $statTabsheet->assign(); |
---|
533 | |
---|
534 | switch($tab) |
---|
535 | { |
---|
536 | case 'state': |
---|
537 | $template->assign('sheetContent', $this->displayDatabaseStatus()); |
---|
538 | break; |
---|
539 | case 'update': |
---|
540 | $template->assign('sheetContent', $this->displayDatabaseDatabase()); |
---|
541 | break; |
---|
542 | } |
---|
543 | |
---|
544 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
545 | } |
---|
546 | |
---|
547 | |
---|
548 | |
---|
549 | /** |
---|
550 | * display the database status |
---|
551 | * |
---|
552 | * @return String : the content of the page |
---|
553 | */ |
---|
554 | private function displayDatabaseStatus() |
---|
555 | { |
---|
556 | global $template, $page; |
---|
557 | |
---|
558 | $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_status.tpl'); |
---|
559 | |
---|
560 | $datas=array( |
---|
561 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
562 | 'warning1' => GPCCore::BBtoHTML(l10n('g003_databaseWarning1')), |
---|
563 | 'nfoMetadata' => Array( |
---|
564 | 'exif' => 0, |
---|
565 | 'iptc' => 0, |
---|
566 | 'magic' => 0, |
---|
567 | 'xmp' => 0, |
---|
568 | 'userDefined' => 0, |
---|
569 | 'numOfPictures' => 0, |
---|
570 | 'numOfNotAnalyzedPictures' => 0, |
---|
571 | 'numOfPicturesWithoutTag' => 0, |
---|
572 | 'nfoSize' => 0, |
---|
573 | 'nfoRows' => 0, |
---|
574 | 'nfoSizeAndRows' => '', |
---|
575 | ) |
---|
576 | ); |
---|
577 | |
---|
578 | $sql="SELECT SUM(numOfImg) AS nb, 'exif' AS `type` |
---|
579 | FROM ".$this->tables['used_tags']." |
---|
580 | WHERE tagId LIKE 'exif.%' |
---|
581 | UNION |
---|
582 | SELECT SUM(numOfImg), 'iptc' |
---|
583 | FROM ".$this->tables['used_tags']." |
---|
584 | WHERE tagId LIKE 'iptc.%' |
---|
585 | UNION |
---|
586 | SELECT SUM(numOfImg), 'magic' |
---|
587 | FROM ".$this->tables['used_tags']." |
---|
588 | WHERE tagId LIKE 'magic.%' |
---|
589 | UNION |
---|
590 | SELECT SUM(numOfImg), 'xmp' |
---|
591 | FROM ".$this->tables['used_tags']." |
---|
592 | WHERE tagId LIKE 'xmp.%' |
---|
593 | UNION |
---|
594 | SELECT SUM(numOfImg), 'userDefined' |
---|
595 | FROM ".$this->tables['used_tags']." |
---|
596 | WHERE tagId LIKE 'userDefined.%' |
---|
597 | UNION |
---|
598 | SELECT COUNT(imageId), 'numOfPictures' |
---|
599 | FROM ".$this->tables['images']." |
---|
600 | WHERE analyzed='y' |
---|
601 | UNION |
---|
602 | SELECT COUNT(imageId), 'numOfNotAnalyzedPictures' |
---|
603 | FROM ".$this->tables['images']." |
---|
604 | WHERE analyzed='n' |
---|
605 | UNION |
---|
606 | SELECT COUNT(imageId), 'numOfPicturesWithoutTag' |
---|
607 | FROM ".$this->tables['images']." |
---|
608 | WHERE nbTags=0"; |
---|
609 | $result=pwg_query($sql); |
---|
610 | if($result) |
---|
611 | { |
---|
612 | while($row=pwg_db_fetch_assoc($result)) |
---|
613 | { |
---|
614 | if(!is_null($row['nb'])) |
---|
615 | { |
---|
616 | $datas['nfoMetadata'][$row['type']]=$row['nb']; |
---|
617 | if($row['type']=='exif' or |
---|
618 | $row['type']=='iptc' or |
---|
619 | $row['type']=='magic' or |
---|
620 | $row['type']=='xmp' or |
---|
621 | $row['type']=='userDefined') $datas['nfoMetadata']['nfoRows']+=$row['nb']; |
---|
622 | } |
---|
623 | } |
---|
624 | } |
---|
625 | |
---|
626 | $sql="SHOW TABLE STATUS WHERE name LIKE '".$this->tables['images_tags']."'"; |
---|
627 | $result=pwg_query($sql); |
---|
628 | if($result) |
---|
629 | { |
---|
630 | while($row=pwg_db_fetch_assoc($result)) |
---|
631 | { |
---|
632 | $datas['nfoMetadata']['nfoSize']=$row['Data_length']+$row['Index_length']; |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | if($datas['nfoMetadata']['nfoSize']<1048576) |
---|
637 | { |
---|
638 | $datas['nfoMetadata']['nfoSize']=sprintf('%.2fKio', $datas['nfoMetadata']['nfoSize']/1024); |
---|
639 | } |
---|
640 | else |
---|
641 | { |
---|
642 | $datas['nfoMetadata']['nfoSize']=sprintf('%.2fMio', $datas['nfoMetadata']['nfoSize']/1048576); |
---|
643 | } |
---|
644 | $datas['nfoMetadata']['nfoSizeAndRows']=sprintf(l10n('g003_sizeAndRows'), $datas['nfoMetadata']['nfoSize'], $datas['nfoMetadata']['nfoRows']); |
---|
645 | $datas['nfoMetadata']['numOfPictures']=sprintf(l10n('g003_numberOfAnalyzedPictures'), $datas['nfoMetadata']['numOfPictures']); |
---|
646 | $datas['nfoMetadata']['numOfNotAnalyzedPictures']=sprintf(l10n('g003_numberOfNotAnalyzedPictures'), $datas['nfoMetadata']['numOfNotAnalyzedPictures']); |
---|
647 | $datas['nfoMetadata']['numOfPicturesWithoutTag']=sprintf(l10n('g003_numberOfPicturesWithoutTags'), $datas['nfoMetadata']['numOfPicturesWithoutTag']); |
---|
648 | |
---|
649 | $template->assign("datas", $datas); |
---|
650 | |
---|
651 | return($template->parse('sheet_page', true)); |
---|
652 | } // displayDatabaseStatus |
---|
653 | |
---|
654 | |
---|
655 | |
---|
656 | |
---|
657 | /** |
---|
658 | * display and manage the database page |
---|
659 | * |
---|
660 | * the function automatically update the AMD tables : |
---|
661 | * - add new pictures in the AMD image table (assuming image is not analyzed |
---|
662 | * yet) |
---|
663 | * - remove deleted pictures in the AMD image & image_tags table |
---|
664 | * |
---|
665 | * @return String : the content of the page |
---|
666 | */ |
---|
667 | private function displayDatabaseDatabase() |
---|
668 | { |
---|
669 | global $template, $page, $user; |
---|
670 | |
---|
671 | /* |
---|
672 | * insert new image (from piwigo images table) in the AMD images table, with |
---|
673 | * statut 'not analyzed' |
---|
674 | */ |
---|
675 | $sql="INSERT INTO ".$this->tables['images']." |
---|
676 | SELECT id, 'n', 0 |
---|
677 | FROM ".IMAGES_TABLE." |
---|
678 | WHERE id NOT IN (SELECT imageId FROM ".$this->tables['images'].")"; |
---|
679 | pwg_query($sql); |
---|
680 | |
---|
681 | |
---|
682 | /* |
---|
683 | * delete image who are in the AMD images table and not in the piwigo image |
---|
684 | * table |
---|
685 | */ |
---|
686 | $sql="DELETE FROM ".$this->tables['images']." |
---|
687 | WHERE imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.")"; |
---|
688 | pwg_query($sql); |
---|
689 | |
---|
690 | |
---|
691 | /* |
---|
692 | * delete metadata for images that are not in the AMD image table |
---|
693 | */ |
---|
694 | $sql="DELETE ait |
---|
695 | FROM ".$this->tables['images_tags']." ait |
---|
696 | JOIN (SELECT DISTINCT imageId FROM ".$this->tables['images_tags']." ) aitd |
---|
697 | ON ait.imageId=aitd.imageId |
---|
698 | WHERE aitd.imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.") "; |
---|
699 | pwg_query($sql); |
---|
700 | |
---|
701 | |
---|
702 | $caddieNbPictures=0; |
---|
703 | $sql="SELECT COUNT(element_id) AS nbPictures |
---|
704 | FROM ".CADDIE_TABLE." |
---|
705 | WHERE user_id='".$user['id']."';"; |
---|
706 | $result=pwg_query($sql); |
---|
707 | if($result) |
---|
708 | { |
---|
709 | while($row=pwg_db_fetch_assoc($result)) |
---|
710 | { |
---|
711 | $caddieNbPictures=$row['nbPictures']; |
---|
712 | } |
---|
713 | } |
---|
714 | |
---|
715 | |
---|
716 | $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_database.tpl'); |
---|
717 | |
---|
718 | $datas=array( |
---|
719 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
720 | 'NumberOfItemsPerRequest' => $this->config['amd_NumberOfItemsPerRequest'], |
---|
721 | 'caddieNbPictures' => ($caddieNbPictures==1)?l10n('g003_1_picture_in_caddie'):sprintf(l10n('g003_n_pictures_in_caddie'), $caddieNbPictures) |
---|
722 | ); |
---|
723 | |
---|
724 | $template->assign("datas", $datas); |
---|
725 | |
---|
726 | return($template->parse('sheet_page', true)); |
---|
727 | } // displayDatabase |
---|
728 | |
---|
729 | |
---|
730 | |
---|
731 | |
---|
732 | |
---|
733 | /** |
---|
734 | * display and manage the help page |
---|
735 | * |
---|
736 | * @param String $tab : the selected tab on the help page |
---|
737 | */ |
---|
738 | protected function displayHelp() |
---|
739 | { |
---|
740 | global $template, $user, $lang; |
---|
741 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_help.tpl'); |
---|
742 | |
---|
743 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
744 | $statTabsheet->add('exif', |
---|
745 | l10n('g003_help_tab_exif'), |
---|
746 | '', true, "displayHelp('exif');"); |
---|
747 | $statTabsheet->add('iptc', |
---|
748 | l10n('g003_help_tab_iptc'), |
---|
749 | '', false, "displayHelp('iptc');"); |
---|
750 | $statTabsheet->add('xmp', |
---|
751 | l10n('g003_help_tab_xmp'), |
---|
752 | '', false, "displayHelp('xmp');"); |
---|
753 | $statTabsheet->add('magic', |
---|
754 | l10n('g003_help_tab_magic'), |
---|
755 | '', false, "displayHelp('magic');"); |
---|
756 | $statTabsheet->assign(); |
---|
757 | |
---|
758 | $data=Array( |
---|
759 | 'sheetContent_exif' => GPCCore::BBtoHTML($lang['g003_help_exif']), |
---|
760 | 'sheetContent_xmp' => GPCCore::BBtoHTML($lang['g003_help_xmp']), |
---|
761 | 'sheetContent_iptc' => GPCCore::BBtoHTML($lang['g003_help_iptc']), |
---|
762 | 'sheetContent_magic' => GPCCore::BBtoHTML($lang['g003_help_magic']), |
---|
763 | 'title_exif' => l10n('g003_help_tab_exif'), |
---|
764 | 'title_xmp' => l10n('g003_help_tab_xmp'), |
---|
765 | 'title_iptc' => l10n('g003_help_tab_iptc'), |
---|
766 | 'title_magic' => l10n('g003_help_tab_magic') |
---|
767 | ); |
---|
768 | |
---|
769 | $template->assign('data', $data); |
---|
770 | |
---|
771 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
772 | } |
---|
773 | |
---|
774 | |
---|
775 | /** |
---|
776 | * display and manage the tags page |
---|
777 | * |
---|
778 | */ |
---|
779 | protected function displayTags() |
---|
780 | { |
---|
781 | global $template, $user, $lang; |
---|
782 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata_tags.tpl'); |
---|
783 | |
---|
784 | $datas=array( |
---|
785 | 'urlRequest' => $this->getAdminLink('ajax') |
---|
786 | ); |
---|
787 | |
---|
788 | $lang['g003_tags_page_help']=GPCCore::BBtoHTML($lang['g003_tags_page_help']); |
---|
789 | |
---|
790 | $template->assign('datas', $datas); |
---|
791 | |
---|
792 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
793 | } |
---|
794 | |
---|
795 | |
---|
796 | } // AMD_AIP class |
---|
797 | |
---|
798 | |
---|
799 | ?> |
---|