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('AMetaData')); |
---|
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 | $warning2=''; |
---|
561 | $sql="SELECT tagId |
---|
562 | FROM ".$this->tables['used_tags']." |
---|
563 | WHERE newFromLastUpdate='y'"; |
---|
564 | $result=pwg_query($sql); |
---|
565 | if($result) |
---|
566 | { |
---|
567 | $tmp=array(); |
---|
568 | $tagSchema=''; |
---|
569 | while($row=pwg_db_fetch_assoc($result)) |
---|
570 | { |
---|
571 | if(preg_match('/^([a-z0-9]*)\..*/i', $row['tagId'], $tagSchema)) |
---|
572 | { |
---|
573 | if(!in_array($tagSchema[1],$this->config['amd_FillDataBaseIgnoreSchemas'])) $tmp[]=$row['tagId']; |
---|
574 | } |
---|
575 | } |
---|
576 | if(count($tmp)>0) |
---|
577 | { |
---|
578 | $ul=''; |
---|
579 | foreach($tmp as $val) |
---|
580 | { |
---|
581 | $ul.='<li>'.$val.'</li>'; |
---|
582 | } |
---|
583 | if(count($tmp)>1) |
---|
584 | { |
---|
585 | $warning2=sprintf(GPCCore::BBtoHTML(l10n('g003_databaseWarning2_n')),$ul); |
---|
586 | } |
---|
587 | else |
---|
588 | { |
---|
589 | $warning2=sprintf(GPCCore::BBtoHTML(l10n('g003_databaseWarning2_1')),$ul); |
---|
590 | } |
---|
591 | } |
---|
592 | } |
---|
593 | |
---|
594 | |
---|
595 | $datas=array( |
---|
596 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
597 | 'warning2' => $warning2, |
---|
598 | 'warning1' => GPCCore::BBtoHTML(l10n('g003_databaseWarning1')), |
---|
599 | 'nfoMetadata' => Array( |
---|
600 | 'exif' => 0, |
---|
601 | 'iptc' => 0, |
---|
602 | 'magic' => 0, |
---|
603 | 'xmp' => 0, |
---|
604 | 'com' => 0, |
---|
605 | 'userDefined' => 0, |
---|
606 | 'numOfPictures' => 0, |
---|
607 | 'numOfNotAnalyzedPictures' => 0, |
---|
608 | 'numOfPicturesWithoutTag' => 0, |
---|
609 | 'nfoSize' => 0, |
---|
610 | 'nfoRows' => 0, |
---|
611 | 'nfoSizeAndRows' => '', |
---|
612 | ) |
---|
613 | ); |
---|
614 | |
---|
615 | $sql="SELECT SUM(numOfImg) AS nb, 'exif' AS `type` |
---|
616 | FROM ".$this->tables['used_tags']." |
---|
617 | WHERE tagId LIKE 'exif.%' |
---|
618 | UNION |
---|
619 | SELECT SUM(numOfImg), 'iptc' |
---|
620 | FROM ".$this->tables['used_tags']." |
---|
621 | WHERE tagId LIKE 'iptc.%' |
---|
622 | UNION |
---|
623 | SELECT SUM(numOfImg), 'magic' |
---|
624 | FROM ".$this->tables['used_tags']." |
---|
625 | WHERE tagId LIKE 'magic.%' |
---|
626 | UNION |
---|
627 | SELECT SUM(numOfImg), 'xmp' |
---|
628 | FROM ".$this->tables['used_tags']." |
---|
629 | WHERE tagId LIKE 'xmp.%' |
---|
630 | UNION |
---|
631 | SELECT SUM(numOfImg), 'com' |
---|
632 | FROM ".$this->tables['used_tags']." |
---|
633 | WHERE tagId LIKE 'com.%' |
---|
634 | UNION |
---|
635 | SELECT SUM(numOfImg), 'userDefined' |
---|
636 | FROM ".$this->tables['used_tags']." |
---|
637 | WHERE tagId LIKE 'userDefined.%' |
---|
638 | UNION |
---|
639 | SELECT COUNT(imageId), 'numOfPictures' |
---|
640 | FROM ".$this->tables['images']." |
---|
641 | WHERE analyzed='y' |
---|
642 | UNION |
---|
643 | SELECT COUNT(imageId), 'numOfNotAnalyzedPictures' |
---|
644 | FROM ".$this->tables['images']." |
---|
645 | WHERE analyzed='n' |
---|
646 | UNION |
---|
647 | SELECT COUNT(imageId), 'numOfPicturesWithoutTag' |
---|
648 | FROM ".$this->tables['images']." |
---|
649 | WHERE nbTags=0"; |
---|
650 | $result=pwg_query($sql); |
---|
651 | if($result) |
---|
652 | { |
---|
653 | while($row=pwg_db_fetch_assoc($result)) |
---|
654 | { |
---|
655 | if(!is_null($row['nb'])) |
---|
656 | { |
---|
657 | $datas['nfoMetadata'][$row['type']]=$row['nb']; |
---|
658 | if($row['type']=='exif' or |
---|
659 | $row['type']=='iptc' or |
---|
660 | $row['type']=='magic' or |
---|
661 | $row['type']=='xmp' or |
---|
662 | $row['type']=='com' or |
---|
663 | $row['type']=='userDefined') $datas['nfoMetadata']['nfoRows']+=$row['nb']; |
---|
664 | } |
---|
665 | } |
---|
666 | } |
---|
667 | |
---|
668 | $sql="SHOW TABLE STATUS WHERE name LIKE '".$this->tables['images_tags']."'"; |
---|
669 | $result=pwg_query($sql); |
---|
670 | if($result) |
---|
671 | { |
---|
672 | while($row=pwg_db_fetch_assoc($result)) |
---|
673 | { |
---|
674 | $datas['nfoMetadata']['nfoSize']=$row['Data_length']+$row['Index_length']; |
---|
675 | } |
---|
676 | } |
---|
677 | |
---|
678 | if($datas['nfoMetadata']['nfoSize']<1048576) |
---|
679 | { |
---|
680 | $datas['nfoMetadata']['nfoSize']=sprintf('%.2fKio', $datas['nfoMetadata']['nfoSize']/1024); |
---|
681 | } |
---|
682 | else |
---|
683 | { |
---|
684 | $datas['nfoMetadata']['nfoSize']=sprintf('%.2fMio', $datas['nfoMetadata']['nfoSize']/1048576); |
---|
685 | } |
---|
686 | $datas['nfoMetadata']['nfoSizeAndRows']=sprintf(l10n('g003_sizeAndRows'), $datas['nfoMetadata']['nfoSize'], $datas['nfoMetadata']['nfoRows']); |
---|
687 | $datas['nfoMetadata']['numOfPictures']=sprintf(l10n('g003_numberOfAnalyzedPictures'), $datas['nfoMetadata']['numOfPictures']); |
---|
688 | $datas['nfoMetadata']['numOfNotAnalyzedPictures']=sprintf(l10n('g003_numberOfNotAnalyzedPictures'), $datas['nfoMetadata']['numOfNotAnalyzedPictures']); |
---|
689 | $datas['nfoMetadata']['numOfPicturesWithoutTag']=sprintf(l10n('g003_numberOfPicturesWithoutTags'), $datas['nfoMetadata']['numOfPicturesWithoutTag']); |
---|
690 | |
---|
691 | $template->assign("datas", $datas); |
---|
692 | |
---|
693 | return($template->parse('sheet_page', true)); |
---|
694 | } // displayDatabaseStatus |
---|
695 | |
---|
696 | |
---|
697 | |
---|
698 | |
---|
699 | /** |
---|
700 | * display and manage the database page |
---|
701 | * |
---|
702 | * the function automatically update the AMD tables : |
---|
703 | * - add new pictures in the AMD image table (assuming image is not analyzed |
---|
704 | * yet) |
---|
705 | * - remove deleted pictures in the AMD image & image_tags table |
---|
706 | * |
---|
707 | * @return String : the content of the page |
---|
708 | */ |
---|
709 | private function displayDatabaseDatabase() |
---|
710 | { |
---|
711 | global $template, $page, $user; |
---|
712 | |
---|
713 | /* |
---|
714 | * insert new image (from piwigo images table) in the AMD images table, with |
---|
715 | * statut 'not analyzed' |
---|
716 | */ |
---|
717 | $sql="INSERT INTO ".$this->tables['images']." |
---|
718 | SELECT id, 'n', 0 |
---|
719 | FROM ".IMAGES_TABLE." |
---|
720 | WHERE id NOT IN (SELECT imageId FROM ".$this->tables['images'].")"; |
---|
721 | pwg_query($sql); |
---|
722 | |
---|
723 | |
---|
724 | /* |
---|
725 | * delete image who are in the AMD images table and not in the piwigo image |
---|
726 | * table |
---|
727 | */ |
---|
728 | $sql="DELETE FROM ".$this->tables['images']." |
---|
729 | WHERE imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.")"; |
---|
730 | pwg_query($sql); |
---|
731 | |
---|
732 | |
---|
733 | /* |
---|
734 | * delete metadata for images that are not in the AMD image table |
---|
735 | */ |
---|
736 | $sql="DELETE ait |
---|
737 | FROM ".$this->tables['images_tags']." ait |
---|
738 | JOIN (SELECT DISTINCT imageId FROM ".$this->tables['images_tags']." ) aitd |
---|
739 | ON ait.imageId=aitd.imageId |
---|
740 | WHERE aitd.imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.") "; |
---|
741 | pwg_query($sql); |
---|
742 | |
---|
743 | |
---|
744 | $caddieNbPictures=0; |
---|
745 | $sql="SELECT COUNT(element_id) AS nbPictures |
---|
746 | FROM ".CADDIE_TABLE." |
---|
747 | WHERE user_id='".$user['id']."';"; |
---|
748 | $result=pwg_query($sql); |
---|
749 | if($result) |
---|
750 | { |
---|
751 | while($row=pwg_db_fetch_assoc($result)) |
---|
752 | { |
---|
753 | $caddieNbPictures=$row['nbPictures']; |
---|
754 | } |
---|
755 | } |
---|
756 | |
---|
757 | |
---|
758 | $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_database.tpl'); |
---|
759 | |
---|
760 | $datas=array( |
---|
761 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
762 | 'NumberOfItemsPerRequest' => $this->config['amd_NumberOfItemsPerRequest'], |
---|
763 | 'caddieNbPictures' => ($caddieNbPictures==1)?l10n('g003_1_picture_in_caddie'):sprintf(l10n('g003_n_pictures_in_caddie'), $caddieNbPictures) |
---|
764 | ); |
---|
765 | |
---|
766 | $template->assign("datas", $datas); |
---|
767 | |
---|
768 | return($template->parse('sheet_page', true)); |
---|
769 | } // displayDatabase |
---|
770 | |
---|
771 | |
---|
772 | |
---|
773 | |
---|
774 | |
---|
775 | /** |
---|
776 | * display and manage the help page |
---|
777 | * |
---|
778 | * @param String $tab : the selected tab on the help page |
---|
779 | */ |
---|
780 | protected function displayHelp() |
---|
781 | { |
---|
782 | global $template, $user, $lang; |
---|
783 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_help.tpl'); |
---|
784 | |
---|
785 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
786 | $statTabsheet->add('exif', |
---|
787 | l10n('g003_help_tab_exif'), |
---|
788 | '', true, "displayHelp('exif');"); |
---|
789 | $statTabsheet->add('iptc', |
---|
790 | l10n('g003_help_tab_iptc'), |
---|
791 | '', false, "displayHelp('iptc');"); |
---|
792 | $statTabsheet->add('xmp', |
---|
793 | l10n('g003_help_tab_xmp'), |
---|
794 | '', false, "displayHelp('xmp');"); |
---|
795 | $statTabsheet->add('magic', |
---|
796 | l10n('g003_help_tab_magic'), |
---|
797 | '', false, "displayHelp('magic');"); |
---|
798 | $statTabsheet->assign(); |
---|
799 | |
---|
800 | $data=Array( |
---|
801 | 'sheetContent_exif' => GPCCore::BBtoHTML($lang['g003_help_exif']), |
---|
802 | 'sheetContent_xmp' => GPCCore::BBtoHTML($lang['g003_help_xmp']), |
---|
803 | 'sheetContent_iptc' => GPCCore::BBtoHTML($lang['g003_help_iptc']), |
---|
804 | 'sheetContent_magic' => GPCCore::BBtoHTML($lang['g003_help_magic']), |
---|
805 | 'title_exif' => l10n('g003_help_tab_exif'), |
---|
806 | 'title_xmp' => l10n('g003_help_tab_xmp'), |
---|
807 | 'title_iptc' => l10n('g003_help_tab_iptc'), |
---|
808 | 'title_magic' => l10n('g003_help_tab_magic') |
---|
809 | ); |
---|
810 | |
---|
811 | $template->assign('data', $data); |
---|
812 | |
---|
813 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
814 | } |
---|
815 | |
---|
816 | |
---|
817 | /** |
---|
818 | * display and manage the tags page |
---|
819 | * |
---|
820 | */ |
---|
821 | protected function displayTags() |
---|
822 | { |
---|
823 | global $template, $user, $lang; |
---|
824 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata_tags.tpl'); |
---|
825 | |
---|
826 | $datas=array( |
---|
827 | 'urlRequest' => $this->getAdminLink('ajax') |
---|
828 | ); |
---|
829 | |
---|
830 | $lang['g003_tags_page_help']=GPCCore::BBtoHTML($lang['g003_tags_page_help']); |
---|
831 | |
---|
832 | $template->assign('datas', $datas); |
---|
833 | |
---|
834 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
835 | } |
---|
836 | |
---|
837 | |
---|
838 | } // AMD_AIP class |
---|
839 | |
---|
840 | |
---|
841 | ?> |
---|