[7196] | 1 | <?php |
---|
| 2 | /* ----------------------------------------------------------------------------- |
---|
| 3 | Plugin : Advanced Search Engine |
---|
| 4 | Author : Grum |
---|
| 5 | email : grum@piwigo.org |
---|
| 6 | website : http://photos.grum.fr |
---|
| 7 | |
---|
| 8 | << May the Little SpaceFrog be with you ! >> |
---|
| 9 | ------------------------------------------------------------------------------ |
---|
| 10 | See main.inc.php for release information |
---|
| 11 | |
---|
| 12 | ASE_AIP : classe to manage plugin admin pages |
---|
| 13 | |
---|
| 14 | --------------------------------------------------------------------------- */ |
---|
| 15 | |
---|
| 16 | include_once('ase_root.class.inc.php'); |
---|
| 17 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); |
---|
| 18 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php'); |
---|
| 19 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); |
---|
| 20 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
| 21 | |
---|
| 22 | class ASE_AIP extends ASE_root |
---|
| 23 | { |
---|
| 24 | protected $tabsheet; |
---|
[7207] | 25 | protected $modules; |
---|
[7196] | 26 | |
---|
| 27 | public function __construct($prefixeTable, $filelocation) |
---|
| 28 | { |
---|
| 29 | parent::__construct($prefixeTable, $filelocation); |
---|
| 30 | |
---|
| 31 | $this->loadConfig(); |
---|
| 32 | $this->configForTemplate(); |
---|
| 33 | |
---|
| 34 | $this->initRequest(); |
---|
| 35 | $this->initEvents(); |
---|
| 36 | |
---|
| 37 | $this->tabsheet = new tabsheet(); |
---|
| 38 | |
---|
| 39 | $this->tabsheet->add('search', |
---|
| 40 | l10n('ase_search'), |
---|
[15360] | 41 | $this->getAdminLink()."-search"); |
---|
[7196] | 42 | $this->tabsheet->add('config', |
---|
| 43 | l10n('ase_config'), |
---|
[15360] | 44 | $this->getAdminLink()."-config"); |
---|
[7196] | 45 | } |
---|
| 46 | |
---|
| 47 | public function __destruct() |
---|
| 48 | { |
---|
| 49 | unset($this->tabsheet); |
---|
| 50 | parent::__destruct(); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * initialize events call for the plugin |
---|
| 55 | */ |
---|
| 56 | public function initEvents() |
---|
| 57 | { |
---|
| 58 | parent::initEvents(); |
---|
| 59 | |
---|
[15360] | 60 | if($_GET['tab']=='search') |
---|
[7196] | 61 | { |
---|
| 62 | // load request builder JS only on the search page |
---|
| 63 | GPCRequestBuilder::loadJSandCSS(); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
[16008] | 67 | public function loadCSS() |
---|
| 68 | { |
---|
| 69 | global $template; |
---|
| 70 | |
---|
| 71 | parent::loadCSS(); |
---|
| 72 | GPCCore::addUI('gpcCSS'); |
---|
| 73 | GPCCore::addHeaderCSS('ase.css', 'plugins/'.$this->getDirectory().'/'.$this->getPluginNameFiles().".css"); |
---|
| 74 | } |
---|
| 75 | |
---|
[7196] | 76 | /** |
---|
| 77 | * display the administration page |
---|
| 78 | */ |
---|
| 79 | public function manage() |
---|
| 80 | { |
---|
| 81 | global $template; |
---|
| 82 | |
---|
| 83 | $this->initRequest(); |
---|
| 84 | |
---|
| 85 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/ase_admin.tpl"); |
---|
| 86 | |
---|
[15360] | 87 | switch($_GET['tab']) |
---|
[7196] | 88 | { |
---|
| 89 | case 'search': |
---|
| 90 | $this->displaySearch(); |
---|
| 91 | break; |
---|
| 92 | case 'config': |
---|
| 93 | $this->displayConfig(); |
---|
| 94 | break; |
---|
| 95 | } |
---|
| 96 | |
---|
[15360] | 97 | $this->tabsheet->select($_GET['tab']); |
---|
[7196] | 98 | $this->tabsheet->assign(); |
---|
| 99 | $selected_tab=$this->tabsheet->get_selected(); |
---|
| 100 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
| 101 | |
---|
| 102 | $template_plugin["ASE_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('ase_release').ASE_VERSION; |
---|
[15360] | 103 | $template_plugin["ASE_PAGE"] = $_GET['tab']; |
---|
[7196] | 104 | $template_plugin["ASE_TITLE"] = ""; |
---|
| 105 | |
---|
| 106 | $template->assign('plugin', $template_plugin); |
---|
| 107 | |
---|
| 108 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 109 | |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * if empty, initialize the $_REQUEST var |
---|
| 117 | * |
---|
| 118 | * if not empty, check validity for the request values |
---|
| 119 | * |
---|
| 120 | */ |
---|
| 121 | private function initRequest() |
---|
| 122 | { |
---|
| 123 | //initialise $REQUEST values if not defined |
---|
| 124 | |
---|
| 125 | if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']=''; |
---|
| 126 | |
---|
[15360] | 127 | if(!isset($_GET['tab'])) |
---|
[7196] | 128 | { |
---|
[15360] | 129 | $_GET['tab']="search"; |
---|
[7196] | 130 | } |
---|
| 131 | |
---|
[15360] | 132 | if(!($_GET['tab']!="search" or |
---|
| 133 | $_GET['tab']!="config" |
---|
| 134 | )) $_GET['tab']="search"; |
---|
[7196] | 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | * display the search page |
---|
| 141 | * |
---|
| 142 | */ |
---|
| 143 | protected function displaySearch() |
---|
| 144 | { |
---|
| 145 | global $template; |
---|
| 146 | |
---|
[16008] | 147 | GPCCore::addUI('inputTag,categorySelector'); |
---|
[7196] | 148 | |
---|
| 149 | $template->set_filename('body_page', |
---|
| 150 | dirname($this->getFileLocation()).'/admin/ase_search.tpl'); |
---|
| 151 | |
---|
| 152 | $template->assign('ase_search_page', GPCRequestBuilder::displaySearchPage()); |
---|
| 153 | |
---|
| 154 | $template->assign_var_from_handle('ASE_BODY_PAGE', 'body_page'); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | /** |
---|
| 159 | * display the config page |
---|
| 160 | * |
---|
| 161 | */ |
---|
| 162 | protected function displayConfig() |
---|
| 163 | { |
---|
| 164 | global $template; |
---|
| 165 | |
---|
[7207] | 166 | $this->modules=GPCRequestBuilder::getRegistered(); |
---|
| 167 | $this->updateConfig(); |
---|
| 168 | $this->configForTemplate(); |
---|
| 169 | |
---|
| 170 | $template->set_filename('body_page', |
---|
[7196] | 171 | dirname($this->getFileLocation()).'/admin/ase_config.tpl'); |
---|
| 172 | |
---|
[7207] | 173 | $cfgTabsheet = new GPCTabSheet('configTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itabcfg'); |
---|
| 174 | $cfgTabsheet->add('gallery', |
---|
| 175 | l10n('ase_gallery_integration'), |
---|
| 176 | '', true, "cm.displayTab('gallery');"); |
---|
| 177 | $cfgTabsheet->add('keyword', |
---|
| 178 | l10n('ase_keyword_module'), |
---|
| 179 | '', false, "cm.displayTab('keyword');"); |
---|
| 180 | $cfgTabsheet->assign(); |
---|
[7196] | 181 | |
---|
[7207] | 182 | |
---|
| 183 | foreach($this->modules as $key=>$val) |
---|
| 184 | { |
---|
| 185 | $this->modules[$key]=array( |
---|
| 186 | 'name' => l10n($val['name']), |
---|
| 187 | 'id' => $val['name'], |
---|
| 188 | 'accessible' => in_array($val['name'], $this->config['ase_publicAccess_allowedPlugins']) |
---|
| 189 | ); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | $datas=Array( |
---|
| 193 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
| 194 | 'modules' => $this->modules |
---|
| 195 | ); |
---|
| 196 | $template->assign('datas', $datas); |
---|
| 197 | |
---|
| 198 | $template->assign_var_from_handle('ASE_BODY_PAGE', 'body_page'); |
---|
[7196] | 199 | } |
---|
| 200 | |
---|
[7207] | 201 | /** |
---|
| 202 | * update config values |
---|
| 203 | */ |
---|
| 204 | protected function updateConfig() |
---|
| 205 | { |
---|
| 206 | global $infos; |
---|
[7196] | 207 | |
---|
[7207] | 208 | if(!isset($_POST) or count($_POST)==0) return(false); |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | if(isset($_POST['fPAActive']) and $_POST['fPAActive']=='on') |
---|
| 212 | { |
---|
| 213 | $this->config['ase_publicAccess_active']=true; |
---|
| 214 | } |
---|
| 215 | else |
---|
| 216 | { |
---|
| 217 | $this->config['ase_publicAccess_active']=false; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | if(isset($_POST['fPAApplyLimits']) and $_POST['fPAApplyLimits']=='on') |
---|
| 222 | { |
---|
| 223 | $this->config['ase_publicAccess_applyLimits']=true; |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | $this->config['ase_publicAccess_applyLimits']=false; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | if(isset($_POST['fKMinLength'])) $this->config['ase_keyword_minLength']=$_POST['fKMinLength']; |
---|
| 231 | |
---|
| 232 | if(isset($_POST['fPALimits'])) $this->config['ase_publicAccess_limits']=$_POST['fPALimits']; |
---|
| 233 | |
---|
| 234 | $this->config['ase_publicAccess_allowedPlugins']=array(); |
---|
| 235 | foreach($this->modules as $key=>$val) |
---|
| 236 | { |
---|
| 237 | if(isset($_POST['fModule'.$val['name']]) and $_POST['fModule'.$val['name']]=='on') $this->config['ase_publicAccess_allowedPlugins'][]=$val['name']; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | if($this->saveConfig()) |
---|
| 241 | { |
---|
| 242 | $this->displayResult(l10n('ase_config_saved'), true); |
---|
| 243 | return(true); |
---|
| 244 | } |
---|
| 245 | return(false); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | |
---|
[7196] | 249 | } //class |
---|
| 250 | |
---|
| 251 | |
---|
| 252 | ?> |
---|