> * * ----------------------------------------------------------------------------- * * See main.inc.php for release information * * AIP classe => manage integration in administration interface * * ----------------------------------------------------------------------------- */ if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } include_once('amd_root.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/genericjs.class.inc.php'); class AMD_AIP extends AMD_root { protected $tabsheet; /** * * constructor needs the prefix of piwigo's tables and the location of plugin * * @param String $prefixeTable * @param String $filelocation */ public function __construct($prefixeTable, $filelocation) { parent::__construct($prefixeTable, $filelocation); $this->loadConfig(); $this->configForTemplate(); $this->initEvents(); $this->tabsheet = new tabsheet(); if($this->config['amd_InterfaceMode']=='basic') { $this->tabsheet->add('metadata', l10n('g003_metadata'), $this->getAdminLink().'-metadata'); $this->tabsheet->add('help', l10n('g003_help'), $this->getAdminLink().'-help'); } else { $this->tabsheet->add('database', l10n('g003_database'), $this->getAdminLink().'-database'); $this->tabsheet->add('metadata', l10n('g003_metadata'), $this->getAdminLink().'-metadata'); $this->tabsheet->add('search', l10n('g003_search'), $this->getAdminLink().'-search'); $this->tabsheet->add('tags', l10n('g003_tags'), $this->getAdminLink().'-tags'); $this->tabsheet->add('help', l10n('g003_help'), $this->getAdminLink().'-help'); } } public function __destruct() { unset($this->tabsheet); parent::__destruct(); } /* * --------------------------------------------------------------------------- * Public classe functions * --------------------------------------------------------------------------- */ /** * manage the plugin integration into piwigo's admin interface */ public function manage() { global $template, $page; $this->initRequest(); $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/amd_admin.tpl"); $this->tabsheet->select($_GET['tab']); $this->tabsheet->assign(); $selected_tab=$this->tabsheet->get_selected(); $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); $pluginInfo=array( 'AMD_VERSION' => "".$this->getPluginName()." ".l10n('g003_version').AMD_VERSION, 'AMD_PAGE' => $_GET['tab'], 'PATH' => AMD_PATH ); $template->assign('plugin', $pluginInfo); GPCCore::setTemplateToken(); switch($_GET['tab']) { case 'help': $this->displayHelp(); break; case 'database': $this->displayDatabase($_REQUEST['t']); break; case 'metadata': $this->displayMetaData($_REQUEST['t']); break; case 'search': $this->displaySearch($_REQUEST['t']); break; case 'tags': $this->displayTags(); break; } $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); } /** * initialize events call for the plugin * * don't inherits from its parent => it's normal */ public function initEvents() { parent::initEvents(); if(isset($_GET['tab']) and $_GET['tab']=='search') { // load request builder JS only on the search page GPCRequestBuilder::loadJSandCSS(); } } /** * --------------------------------------------------------------------------- * Private & protected functions * --------------------------------------------------------------------------- */ /** * if empty, initialize the $_REQUEST var * * if not empty, check validity for the request values * */ private function initRequest() { //initialise $REQUEST values if not defined if(!isset($_GET['tab'])) { if($this->getNumOfPictures()==0 and $this->config['amd_InterfaceMode']=='advanced') { $_GET['tab']="database"; $_REQUEST['t']="state"; } else { $_GET['tab']="metadata"; $_REQUEST['t']="select"; } } $tmp=explode('/', $_GET['tab'].'/'); $_GET['tab']=$tmp[0]; $_REQUEST['t']=$tmp[1]; if(!($_GET['tab']=="metadata" or $_GET['tab']=="help" or $_GET['tab']=="database" or $_GET['tab']=="search" or $_GET['tab']=="tags") or $this->config['amd_InterfaceMode']=='basic' and ( $_GET['tab']=="database" or $_GET['tab']=="search" or $_GET['tab']=="tags" ) ) { $_GET['tab']="metadata"; } /* * metadata tabsheet */ if($_GET['tab']=="metadata") { if(!isset($_REQUEST['t'])) { if($this->config['amd_InterfaceMode']=='basic') { $_REQUEST['t']="display"; } else { $_REQUEST['t']="select"; } } if(!($_REQUEST['t']=="personnal" or $_REQUEST['t']=="select" or $_REQUEST['t']=="display") or $this->config['amd_InterfaceMode']=='basic' and ( $_REQUEST['t']=="select" ) ) { if($this->config['amd_InterfaceMode']=='basic') { $_REQUEST['t']="display"; } else { $_REQUEST['t']="select"; } } } /* * help tabsheet */ if($_GET['tab']=="help") { if(!isset($_REQUEST['t'])) $_REQUEST['t']="exif"; if(!($_REQUEST['t']=="exif" or $_REQUEST['t']=="iptc" or $_REQUEST['t']=="xmp" or $_REQUEST['t']=="magic")) $_REQUEST['t']="exif"; } /* * search tabsheet */ if($_GET['tab']=="search") { if(!isset($_REQUEST['t'])) $_REQUEST['t']="search"; if(!($_REQUEST['t']=="config" or $_REQUEST['t']=="search")) $_REQUEST['t']="search"; } /* * database tabsheet */ if($_GET['tab']=="database") { if(!isset($_REQUEST['t'])) $_REQUEST['t']="state"; if(!($_REQUEST['t']=="state" or $_REQUEST['t']=="update")) $_REQUEST['t']="state"; } } //init_request /** * manage adviser profile * * @return Boolean : true if user is adviser, otherwise false (and push a * message in the error list) */ protected function adviser_abort() { if(is_adviser()) { $this->display_result(l10n("g003_adviser_not_allowed"), false); return(true); } return(false); } /** * display and manage the search page */ protected function displaySearch() { global $template, $lang; $template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/amd_metadata_search.tpl'); $template->assign('amd_search_page', GPCRequestBuilder::displaySearchPage('AMetaData')); $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); } /** * display and manage the metadata page * the page have three tabsheet : * - personnal tag management, to build personnal tags * - select tag management, to manage tags to be selected on the galerie * - display tag management, to choose how the tags are displayed * * @param String $tab : the selected tab on the stat page */ protected function displayMetaData($tab) { global $template, $user; $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl'); $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); $statTabsheet->select($tab); $statTabsheet->add('personnal', l10n('g003_personnal'), $this->getAdminLink().'-metadata/personnal'); if($this->config['amd_InterfaceMode']=='advanced') { $statTabsheet->add('select', l10n('g003_select'), $this->getAdminLink().'-metadata/select'); } $statTabsheet->add('display', l10n('g003_display'), $this->getAdminLink().'-metadata/display'); $statTabsheet->assign(); switch($tab) { case 'select': $template->assign('sheetContent', $this->displayMetaDataSelect()); break; case 'display': $template->assign('sheetContent', $this->displayMetaDataDisplay()); break; case 'personnal': $template->assign('sheetContent', $this->displayMetaDataPersonnal()); break; } $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); } /** * display and manage the metadata page allowing to build user defined tags * * @return String : the content of the page */ protected function displayMetaDataPersonnal() { global $template, $theme, $themes, $themeconf, $lang; $template->set_filename('sheet_page', dirname($this->getFileLocation()).'/admin/amd_metadata_personnal.tpl'); $datas=array( 'urlRequest' => $this->getAdminLink('ajax'), 'tagList' => array(), ); /* * build tagList */ $sql="SELECT ut.name, ut.numId, ut.tagId FROM ".$this->tables['used_tags']." ut JOIN ".$this->tables['selected_tags']." st ON st.tagId = ut.tagId ORDER BY tagId"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $datas['tagList'][]=Array( 'tagId' => $row['tagId'], 'name' => L10n::get($row['name']), 'numId' => $row['numId'] ); } } $lang['g003_personnal_page_help']=GPCCore::BBtoHTML($lang['g003_personnal_page_help']); $template->assign('datas', $datas); return($template->parse('sheet_page', true)); } /** * display and manage the metadata page allowing to make tags selection * * @return String : the content of the page */ protected function displayMetaDataSelect() { global $template, $theme, $themes, $themeconf, $lang; $template->set_filename('sheet_page', dirname($this->getFileLocation()).'/admin/amd_metadata_select.tpl'); $datas=array( 'urlRequest' => $this->getAdminLink('ajax'), 'config_GetListTags_OrderType' => $this->config['amd_GetListTags_OrderType'], 'config_GetListTags_FilterType' => $this->config['amd_GetListTags_FilterType'], 'config_GetListTags_ExcludeUnusedTag' => $this->config['amd_GetListTags_ExcludeUnusedTag'], 'config_GetListTags_SelectedTagOnly' => $this->config['amd_GetListTags_SelectedTagOnly'], 'config_GetListImages_OrderType' => $this->config['amd_GetListImages_OrderType'] ); $lang['g003_select_page_help']=GPCCore::BBtoHTML($lang['g003_select_page_help']); $template->assign('datas', $datas); return($template->parse('sheet_page', true)); } /** * display and manage the metadata page allowing to choose tags order * * @return String : the content of the page */ protected function displayMetaDataDisplay() { global $user, $template, $lang; //$local_tpl = new Template(AMD_PATH."admin/", ""); $template->set_filename('sheet_page', dirname($this->getFileLocation()).'/admin/amd_metadata_display.tpl'); $datas=array( 'urlRequest' => $this->getAdminLink('ajax'), 'selectedTags' => Array(), 'groups' => Array(), 'tagByGroup' => Array(), ); $sql="SELECT st.tagId, st.order, st.groupId, ut.numId FROM ".$this->tables['selected_tags']." st LEFT JOIN ".$this->tables['used_tags']." ut ON ut.tagId = st.tagId ORDER BY st.groupId ASC, st.order ASC, st.tagId ASC"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { if($row['groupId']==-1) { $datas['selectedTags'][]=Array( 'numId' => $row['numId'], 'tagId' => $row['tagId'] ); } else { $datas['tagByGroup'][]=Array( 'numId' => $row['numId'], 'tagId' => $row['tagId'], 'group' => $row['groupId'], 'order' => $row['order'] ); } } } $sql="SELECT g.groupId, gn.name FROM ".$this->tables['groups']." g LEFT JOIN ".$this->tables['groups_names']." gn ON g.groupId = gn.groupId WHERE gn.lang = '".$user['language']."' ORDER BY g.order;"; $result=pwg_query($sql); if($result) { while($row=pwg_db_fetch_assoc($result)) { $datas['groups'][]=Array( 'id' => $row['groupId'], 'name' => $row['name'] ); } } $lang['g003_display_page_help']=GPCCore::BBtoHTML($lang['g003_display_page_help']); $template->assign('datas', $datas); return($template->parse('sheet_page', true)); } /** * display and manage the database page * the page have two tabsheet : * - state, to have general information about the database * - update, to manage database fill-in * * @param String $tab : the selected tab on the stat page */ protected function displayDatabase($tab) { global $template, $user; $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl'); $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); $statTabsheet->select($tab); $statTabsheet->add('state', l10n('g003_state'), $this->getAdminLink().'-database/state'); $statTabsheet->add('update', l10n('g003_update'), $this->getAdminLink().'-database/update'); $statTabsheet->assign(); switch($tab) { case 'state': $template->assign('sheetContent', $this->displayDatabaseStatus()); break; case 'update': $template->assign('sheetContent', $this->displayDatabaseDatabase()); break; } $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page'); } /** * display the database status * * @return String : the content of the page */ private function displayDatabaseStatus() { global $template, $page; $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_status.tpl'); $warning2=''; $sql="SELECT tagId FROM ".$this->tables['used_tags']." WHERE newFromLastUpdate='y'"; $result=pwg_query($sql); if($result) { $tmp=array(); $tagSchema=''; while($row=pwg_db_fetch_assoc($result)) { if(preg_match('/^([a-z0-9]*)\..*/i', $row['tagId'], $tagSchema)) { if(!in_array($tagSchema[1],$this->config['amd_FillDataBaseIgnoreSchemas'])) $tmp[]=$row['tagId']; } } if(count($tmp)>0) { $ul=''; foreach($tmp as $val) { $ul.='