[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 | |
---|
| 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 | /** |
---|
[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 | |
---|
| 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 | /** |
---|
[6722] | 658 | * display and manage the database page |
---|
| 659 | * |
---|
[5080] | 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 | */ |
---|
[6722] | 667 | private function displayDatabaseDatabase() |
---|
[5080] | 668 | { |
---|
| 669 | global $template, $page; |
---|
[4905] | 670 | |
---|
[5080] | 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 | /* |
---|
[6729] | 692 | * delete metadata for images that are not in the AMD image table |
---|
[5080] | 693 | */ |
---|
[6729] | 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.") "; |
---|
[5080] | 699 | pwg_query($sql); |
---|
| 700 | |
---|
| 701 | |
---|
| 702 | |
---|
[6729] | 703 | |
---|
| 704 | $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_database.tpl'); |
---|
| 705 | |
---|
[5080] | 706 | $datas=array( |
---|
[6722] | 707 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
[5935] | 708 | 'NumberOfItemsPerRequest' => $this->config['amd_NumberOfItemsPerRequest'], |
---|
[5080] | 709 | ); |
---|
| 710 | |
---|
| 711 | $template->assign("datas", $datas); |
---|
| 712 | |
---|
| 713 | return($template->parse('sheet_page', true)); |
---|
| 714 | } // displayDatabase |
---|
| 715 | |
---|
| 716 | |
---|
| 717 | |
---|
| 718 | |
---|
[4905] | 719 | |
---|
[5191] | 720 | /** |
---|
| 721 | * display and manage the help page |
---|
| 722 | * |
---|
| 723 | * @param String $tab : the selected tab on the help page |
---|
| 724 | */ |
---|
[6173] | 725 | protected function displayHelp() |
---|
[5191] | 726 | { |
---|
| 727 | global $template, $user, $lang; |
---|
| 728 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_help.tpl'); |
---|
[4905] | 729 | |
---|
[5935] | 730 | $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
[5191] | 731 | $statTabsheet->add('exif', |
---|
| 732 | l10n('g003_help_tab_exif'), |
---|
[6173] | 733 | '', true, "displayHelp('exif');"); |
---|
[5191] | 734 | $statTabsheet->add('iptc', |
---|
| 735 | l10n('g003_help_tab_iptc'), |
---|
[6173] | 736 | '', false, "displayHelp('iptc');"); |
---|
[5191] | 737 | $statTabsheet->add('xmp', |
---|
| 738 | l10n('g003_help_tab_xmp'), |
---|
[6173] | 739 | '', false, "displayHelp('xmp');"); |
---|
[5191] | 740 | $statTabsheet->add('magic', |
---|
| 741 | l10n('g003_help_tab_magic'), |
---|
[6173] | 742 | '', false, "displayHelp('magic');"); |
---|
[5191] | 743 | $statTabsheet->assign(); |
---|
| 744 | |
---|
| 745 | $data=Array( |
---|
[6173] | 746 | 'sheetContent_exif' => GPCCore::BBtoHTML($lang['g003_help_exif']), |
---|
| 747 | 'sheetContent_xmp' => GPCCore::BBtoHTML($lang['g003_help_xmp']), |
---|
| 748 | 'sheetContent_iptc' => GPCCore::BBtoHTML($lang['g003_help_iptc']), |
---|
| 749 | 'sheetContent_magic' => GPCCore::BBtoHTML($lang['g003_help_magic']), |
---|
| 750 | 'title_exif' => l10n('g003_help_tab_exif'), |
---|
| 751 | 'title_xmp' => l10n('g003_help_tab_xmp'), |
---|
| 752 | 'title_iptc' => l10n('g003_help_tab_iptc'), |
---|
| 753 | 'title_magic' => l10n('g003_help_tab_magic') |
---|
[5191] | 754 | ); |
---|
| 755 | |
---|
| 756 | $template->assign('data', $data); |
---|
| 757 | |
---|
| 758 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
| 759 | } |
---|
| 760 | |
---|
[6950] | 761 | |
---|
| 762 | /** |
---|
| 763 | * display and manage the tags page |
---|
| 764 | * |
---|
| 765 | */ |
---|
| 766 | protected function displayTags() |
---|
| 767 | { |
---|
| 768 | global $template, $user, $lang; |
---|
| 769 | $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata_tags.tpl'); |
---|
| 770 | |
---|
| 771 | $datas=array( |
---|
| 772 | 'urlRequest' => $this->getAdminLink('ajax') |
---|
| 773 | ); |
---|
| 774 | |
---|
| 775 | $lang['g003_tags_page_help']=GPCCore::BBtoHTML($lang['g003_tags_page_help']); |
---|
| 776 | |
---|
| 777 | $template->assign('datas', $datas); |
---|
| 778 | |
---|
| 779 | $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); |
---|
| 780 | } |
---|
| 781 | |
---|
| 782 | |
---|
[4905] | 783 | } // AMD_AIP class |
---|
| 784 | |
---|
| 785 | |
---|
| 786 | ?> |
---|