[4905] | 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'); |
---|
[5935] | 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'); |
---|
[4905] | 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 | */ |
---|
[5183] | 41 | public function __construct($prefixeTable, $filelocation) |
---|
[4905] | 42 | { |
---|
| 43 | parent::__construct($prefixeTable, $filelocation); |
---|
| 44 | |
---|
[5935] | 45 | $this->loadConfig(); |
---|
[6729] | 46 | $this->configForTemplate(); |
---|
[5935] | 47 | $this->initEvents(); |
---|
[4905] | 48 | |
---|
| 49 | $this->tabsheet = new tabsheet(); |
---|
[6919] | 50 | |
---|
[6950] | 51 | if($this->config['amd_InterfaceMode']=='basic') |
---|
[6919] | 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'); |
---|
[6950] | 71 | $this->tabsheet->add('tags', |
---|
| 72 | l10n('g003_tags'), |
---|
| 73 | $this->getAdminLink().'&fAMD_tabsheet=tags'); |
---|
[6919] | 74 | $this->tabsheet->add('help', |
---|
| 75 | l10n('g003_help'), |
---|
| 76 | $this->getAdminLink().'&fAMD_tabsheet=help'); |
---|
| 77 | } |
---|
[4905] | 78 | } |
---|
| 79 | |
---|
[5183] | 80 | public function __destruct() |
---|
[4905] | 81 | { |
---|
| 82 | unset($this->tabsheet); |
---|
| 83 | unset($this->ajax); |
---|
[5183] | 84 | parent::__destruct(); |
---|
[4905] | 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 | |
---|
[6722] | 104 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/amd_admin.tpl"); |
---|
[4905] | 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 | |
---|
[6722] | 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 | ); |
---|
[4905] | 116 | |
---|
[6722] | 117 | $template->assign('plugin', $pluginInfo); |
---|
[4905] | 118 | |
---|
[6722] | 119 | switch($_REQUEST['fAMD_tabsheet']) |
---|
[4905] | 120 | { |
---|
[6722] | 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': |
---|
[6891] | 131 | $this->displaySearch($_REQUEST['fAMD_page']); |
---|
[6722] | 132 | break; |
---|
[6950] | 133 | case 'tags': |
---|
| 134 | $this->displayTags(); |
---|
| 135 | break; |
---|
[4905] | 136 | } |
---|
| 137 | |
---|
| 138 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | /** |
---|
| 142 | * initialize events call for the plugin |
---|
[5935] | 143 | * |
---|
| 144 | * don't inherits from its parent => it's normal |
---|
[4905] | 145 | */ |
---|
[5935] | 146 | public function initEvents() |
---|
[4905] | 147 | { |
---|
[6891] | 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 | |
---|
[5935] | 154 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
[5959] | 155 | GPCCss::applyGpcCss(); |
---|
[4905] | 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 | { |
---|
[6950] | 176 | if($this->getNumOfPictures()==0 and $this->config['amd_InterfaceMode']=='advanced') |
---|
[6722] | 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 | } |
---|
[4905] | 186 | } |
---|
| 187 | |
---|
[6722] | 188 | if(!($_REQUEST['fAMD_tabsheet']=="metadata" or |
---|
[6919] | 189 | $_REQUEST['fAMD_tabsheet']=="help" or |
---|
| 190 | $_REQUEST['fAMD_tabsheet']=="database" or |
---|
[6950] | 191 | $_REQUEST['fAMD_tabsheet']=="search" or |
---|
| 192 | $_REQUEST['fAMD_tabsheet']=="tags") |
---|
[6919] | 193 | or |
---|
[6950] | 194 | $this->config['amd_InterfaceMode']=='basic' and |
---|
[6919] | 195 | ( |
---|
| 196 | $_REQUEST['fAMD_tabsheet']=="database" or |
---|
[6950] | 197 | $_REQUEST['fAMD_tabsheet']=="search" or |
---|
| 198 | $_REQUEST['fAMD_tabsheet']=="tags" |
---|
[6919] | 199 | ) |
---|
| 200 | ) |
---|
[4905] | 201 | { |
---|
[5080] | 202 | $_REQUEST['fAMD_tabsheet']="metadata"; |
---|
[4905] | 203 | } |
---|
| 204 | |
---|
[6722] | 205 | /* |
---|
| 206 | * metadata tabsheet |
---|
| 207 | */ |
---|
| 208 | if($_REQUEST['fAMD_tabsheet']=="metadata") |
---|
[4905] | 209 | { |
---|
[6919] | 210 | if(!isset($_REQUEST['fAMD_page'])) |
---|
| 211 | { |
---|
[6950] | 212 | if($this->config['amd_InterfaceMode']=='basic') |
---|
[6919] | 213 | { |
---|
| 214 | $_REQUEST['fAMD_page']="display"; |
---|
| 215 | } |
---|
| 216 | else |
---|
| 217 | { |
---|
| 218 | $_REQUEST['fAMD_page']="select"; |
---|
| 219 | } |
---|
| 220 | } |
---|
[6722] | 221 | |
---|
| 222 | if(!($_REQUEST['fAMD_page']=="personnal" or |
---|
| 223 | $_REQUEST['fAMD_page']=="select" or |
---|
[6919] | 224 | $_REQUEST['fAMD_page']=="display") |
---|
| 225 | or |
---|
[6950] | 226 | $this->config['amd_InterfaceMode']=='basic' and |
---|
[6919] | 227 | ( |
---|
| 228 | $_REQUEST['fAMD_page']=="select" |
---|
| 229 | ) |
---|
| 230 | ) |
---|
| 231 | { |
---|
[6950] | 232 | if($this->config['amd_InterfaceMode']=='basic') |
---|
[6919] | 233 | { |
---|
| 234 | $_REQUEST['fAMD_page']="display"; |
---|
| 235 | } |
---|
| 236 | else |
---|
| 237 | { |
---|
| 238 | $_REQUEST['fAMD_page']="select"; |
---|
| 239 | } |
---|
| 240 | } |
---|
[4905] | 241 | } |
---|
| 242 | |
---|
[6722] | 243 | /* |
---|
| 244 | * help tabsheet |
---|
| 245 | */ |
---|
| 246 | if($_REQUEST['fAMD_tabsheet']=="help") |
---|
[4905] | 247 | { |
---|
[6722] | 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"; |
---|
[4905] | 254 | } |
---|
| 255 | |
---|
[6722] | 256 | /* |
---|
| 257 | * search tabsheet |
---|
| 258 | */ |
---|
| 259 | if($_REQUEST['fAMD_tabsheet']=="search") |
---|
[5191] | 260 | { |
---|
[6722] | 261 | if(!isset($_REQUEST['fAMD_page'])) $_REQUEST['fAMD_page']="search"; |
---|
[5191] | 262 | |
---|
[6722] | 263 | if(!($_REQUEST['fAMD_page']=="config" or |
---|
| 264 | $_REQUEST['fAMD_page']=="search")) $_REQUEST['fAMD_page']="search"; |
---|
[5191] | 265 | } |
---|
| 266 | |
---|
[4905] | 267 | /* |
---|
[6722] | 268 | * database tabsheet |
---|
[4905] | 269 | */ |
---|
[6722] | 270 | if($_REQUEST['fAMD_tabsheet']=="database") |
---|
[4905] | 271 | { |
---|
[6722] | 272 | if(!isset($_REQUEST['fAMD_page'])) $_REQUEST['fAMD_page']="state"; |
---|
[4905] | 273 | |
---|
[6722] | 274 | if(!($_REQUEST['fAMD_page']=="state" or |
---|
| 275 | $_REQUEST['fAMD_page']=="update")) $_REQUEST['fAMD_page']="state"; |
---|
| 276 | } |
---|
[4905] | 277 | |
---|
[6950] | 278 | |
---|
[4905] | 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 | |
---|
[6891] | 299 | |
---|
| 300 | |
---|
[4905] | 301 | /** |
---|
[6891] | 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 | |
---|
[7564] | 311 | $template->assign('amd_search_page', GPCRequestBuilder::displaySearchPage('AMetaData')); |
---|
[6891] | 312 | |
---|
| 313 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | |
---|
| 318 | |
---|
| 319 | /** |
---|
[4905] | 320 | * display and manage the metadata page |
---|
[5191] | 321 | * the page have three tabsheet : |
---|
[6722] | 322 | * - personnal tag management, to build personnal tags |
---|
[4905] | 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 | |
---|
[5935] | 333 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
[4905] | 334 | $statTabsheet->select($tab); |
---|
[6722] | 335 | $statTabsheet->add('personnal', |
---|
| 336 | l10n('g003_personnal'), |
---|
| 337 | $this->getAdminLink().'&fAMD_tabsheet=metadata&fAMD_page=personnal'); |
---|
[6950] | 338 | if($this->config['amd_InterfaceMode']=='advanced') |
---|
[6919] | 339 | { |
---|
| 340 | $statTabsheet->add('select', |
---|
| 341 | l10n('g003_select'), |
---|
| 342 | $this->getAdminLink().'&fAMD_tabsheet=metadata&fAMD_page=select'); |
---|
| 343 | } |
---|
[4905] | 344 | $statTabsheet->add('display', |
---|
| 345 | l10n('g003_display'), |
---|
[5935] | 346 | $this->getAdminLink().'&fAMD_tabsheet=metadata&fAMD_page=display'); |
---|
[4905] | 347 | $statTabsheet->assign(); |
---|
| 348 | |
---|
[6722] | 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 | } |
---|
[4905] | 361 | |
---|
[6722] | 362 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
| 363 | } |
---|
[4905] | 364 | |
---|
[6722] | 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 | { |
---|
[6950] | 373 | global $template, $theme, $themes, $themeconf, $lang; |
---|
[6722] | 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) |
---|
[4905] | 392 | { |
---|
[6722] | 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 | } |
---|
[4905] | 401 | } |
---|
| 402 | |
---|
[6950] | 403 | $lang['g003_personnal_page_help']=GPCCore::BBtoHTML($lang['g003_personnal_page_help']); |
---|
| 404 | |
---|
[6722] | 405 | $template->assign('datas', $datas); |
---|
| 406 | return($template->parse('sheet_page', true)); |
---|
[4905] | 407 | } |
---|
| 408 | |
---|
[6722] | 409 | |
---|
[4905] | 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 | { |
---|
[6950] | 417 | global $template, $theme, $themes, $themeconf, $lang; |
---|
[4905] | 418 | |
---|
| 419 | $template->set_filename('sheet_page', |
---|
[5935] | 420 | dirname($this->getFileLocation()).'/admin/amd_metadata_select.tpl'); |
---|
[4905] | 421 | |
---|
| 422 | $datas=array( |
---|
[6722] | 423 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
[5935] | 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'] |
---|
[4905] | 429 | ); |
---|
| 430 | |
---|
[6950] | 431 | $lang['g003_select_page_help']=GPCCore::BBtoHTML($lang['g003_select_page_help']); |
---|
| 432 | |
---|
[4905] | 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 | { |
---|
[6950] | 445 | global $user, $template, $lang; |
---|
[4905] | 446 | |
---|
| 447 | //$local_tpl = new Template(AMD_PATH."admin/", ""); |
---|
| 448 | $template->set_filename('sheet_page', |
---|
[5935] | 449 | dirname($this->getFileLocation()).'/admin/amd_metadata_display.tpl'); |
---|
[4905] | 450 | |
---|
| 451 | $datas=array( |
---|
[6722] | 452 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
[4905] | 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 | { |
---|
[5959] | 466 | while($row=pwg_db_fetch_assoc($result)) |
---|
[4905] | 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 | { |
---|
[5959] | 496 | while($row=pwg_db_fetch_assoc($result)) |
---|
[4905] | 497 | { |
---|
| 498 | $datas['groups'][]=Array( |
---|
| 499 | 'id' => $row['groupId'], |
---|
| 500 | 'name' => $row['name'] |
---|
| 501 | ); |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
[6950] | 505 | $lang['g003_display_page_help']=GPCCore::BBtoHTML($lang['g003_display_page_help']); |
---|
[4905] | 506 | $template->assign('datas', $datas); |
---|
| 507 | return($template->parse('sheet_page', true)); |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | |
---|
[5080] | 511 | /** |
---|
| 512 | * display and manage the database page |
---|
[6722] | 513 | * the page have two tabsheet : |
---|
| 514 | * - state, to have general information about the database |
---|
| 515 | * - update, to manage database fill-in |
---|
[5080] | 516 | * |
---|
[6722] | 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': |
---|
[6729] | 537 | $template->assign('sheetContent', $this->displayDatabaseStatus()); |
---|
[6722] | 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 | |
---|
[6729] | 548 | |
---|
[6722] | 549 | /** |
---|
[6729] | 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 | |
---|
[7519] | 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 | |
---|
[6729] | 595 | $datas=array( |
---|
| 596 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
[7519] | 597 | 'warning2' => $warning2, |
---|
[6729] | 598 | 'warning1' => GPCCore::BBtoHTML(l10n('g003_databaseWarning1')), |
---|
| 599 | 'nfoMetadata' => Array( |
---|
| 600 | 'exif' => 0, |
---|
| 601 | 'iptc' => 0, |
---|
| 602 | 'magic' => 0, |
---|
| 603 | 'xmp' => 0, |
---|
[7519] | 604 | 'com' => 0, |
---|
[6729] | 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 |
---|
[7519] | 631 | SELECT SUM(numOfImg), 'com' |
---|
| 632 | FROM ".$this->tables['used_tags']." |
---|
| 633 | WHERE tagId LIKE 'com.%' |
---|
| 634 | UNION |
---|
[6729] | 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 |
---|
[7519] | 662 | $row['type']=='com' or |
---|
[6729] | 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 | /** |
---|
[6722] | 700 | * display and manage the database page |
---|
| 701 | * |
---|
[5080] | 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 | */ |
---|
[6722] | 709 | private function displayDatabaseDatabase() |
---|
[5080] | 710 | { |
---|
[7447] | 711 | global $template, $page, $user; |
---|
[4905] | 712 | |
---|
[5080] | 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 | /* |
---|
[6729] | 734 | * delete metadata for images that are not in the AMD image table |
---|
[5080] | 735 | */ |
---|
[6729] | 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.") "; |
---|
[5080] | 741 | pwg_query($sql); |
---|
| 742 | |
---|
| 743 | |
---|
[7447] | 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 | } |
---|
[5080] | 756 | |
---|
[6729] | 757 | |
---|
| 758 | $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_database.tpl'); |
---|
| 759 | |
---|
[5080] | 760 | $datas=array( |
---|
[6722] | 761 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
[5935] | 762 | 'NumberOfItemsPerRequest' => $this->config['amd_NumberOfItemsPerRequest'], |
---|
[7447] | 763 | 'caddieNbPictures' => ($caddieNbPictures==1)?l10n('g003_1_picture_in_caddie'):sprintf(l10n('g003_n_pictures_in_caddie'), $caddieNbPictures) |
---|
[5080] | 764 | ); |
---|
| 765 | |
---|
| 766 | $template->assign("datas", $datas); |
---|
| 767 | |
---|
| 768 | return($template->parse('sheet_page', true)); |
---|
| 769 | } // displayDatabase |
---|
| 770 | |
---|
| 771 | |
---|
| 772 | |
---|
| 773 | |
---|
[4905] | 774 | |
---|
[5191] | 775 | /** |
---|
| 776 | * display and manage the help page |
---|
| 777 | * |
---|
| 778 | * @param String $tab : the selected tab on the help page |
---|
| 779 | */ |
---|
[6173] | 780 | protected function displayHelp() |
---|
[5191] | 781 | { |
---|
| 782 | global $template, $user, $lang; |
---|
| 783 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_help.tpl'); |
---|
[4905] | 784 | |
---|
[5935] | 785 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
[5191] | 786 | $statTabsheet->add('exif', |
---|
| 787 | l10n('g003_help_tab_exif'), |
---|
[6173] | 788 | '', true, "displayHelp('exif');"); |
---|
[5191] | 789 | $statTabsheet->add('iptc', |
---|
| 790 | l10n('g003_help_tab_iptc'), |
---|
[6173] | 791 | '', false, "displayHelp('iptc');"); |
---|
[5191] | 792 | $statTabsheet->add('xmp', |
---|
| 793 | l10n('g003_help_tab_xmp'), |
---|
[6173] | 794 | '', false, "displayHelp('xmp');"); |
---|
[5191] | 795 | $statTabsheet->add('magic', |
---|
| 796 | l10n('g003_help_tab_magic'), |
---|
[6173] | 797 | '', false, "displayHelp('magic');"); |
---|
[5191] | 798 | $statTabsheet->assign(); |
---|
| 799 | |
---|
| 800 | $data=Array( |
---|
[6173] | 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') |
---|
[5191] | 809 | ); |
---|
| 810 | |
---|
| 811 | $template->assign('data', $data); |
---|
| 812 | |
---|
| 813 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
| 814 | } |
---|
| 815 | |
---|
[6950] | 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 | |
---|
[4905] | 838 | } // AMD_AIP class |
---|
| 839 | |
---|
| 840 | |
---|
| 841 | ?> |
---|