[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'), |
---|
| 41 | $this->getAdminLink()."&fASE_tabsheet=search"); |
---|
| 42 | $this->tabsheet->add('config', |
---|
| 43 | l10n('ase_config'), |
---|
| 44 | $this->getAdminLink()."&fASE_tabsheet=config"); |
---|
| 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 | |
---|
| 60 | if($_REQUEST['fASE_tabsheet']=='search') |
---|
| 61 | { |
---|
| 62 | // load request builder JS only on the search page |
---|
| 63 | GPCRequestBuilder::loadJSandCSS(); |
---|
| 64 | } |
---|
| 65 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
| 66 | GPCCss::applyGpcCss(); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * display the administration page |
---|
| 71 | */ |
---|
| 72 | public function manage() |
---|
| 73 | { |
---|
| 74 | global $template; |
---|
| 75 | |
---|
| 76 | $this->initRequest(); |
---|
| 77 | |
---|
| 78 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/ase_admin.tpl"); |
---|
| 79 | |
---|
| 80 | switch($_REQUEST['fASE_tabsheet']) |
---|
| 81 | { |
---|
| 82 | case 'search': |
---|
| 83 | $this->displaySearch(); |
---|
| 84 | break; |
---|
| 85 | case 'config': |
---|
| 86 | $this->displayConfig(); |
---|
| 87 | break; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | $this->tabsheet->select($_REQUEST['fASE_tabsheet']); |
---|
| 91 | $this->tabsheet->assign(); |
---|
| 92 | $selected_tab=$this->tabsheet->get_selected(); |
---|
| 93 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
| 94 | |
---|
| 95 | $template_plugin["ASE_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('ase_release').ASE_VERSION; |
---|
| 96 | $template_plugin["ASE_PAGE"] = $_REQUEST['fASE_tabsheet']; |
---|
| 97 | $template_plugin["ASE_TITLE"] = ""; |
---|
| 98 | |
---|
| 99 | $template->assign('plugin', $template_plugin); |
---|
| 100 | |
---|
| 101 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 102 | |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | /** |
---|
| 109 | * if empty, initialize the $_REQUEST var |
---|
| 110 | * |
---|
| 111 | * if not empty, check validity for the request values |
---|
| 112 | * |
---|
| 113 | */ |
---|
| 114 | private function initRequest() |
---|
| 115 | { |
---|
| 116 | //initialise $REQUEST values if not defined |
---|
| 117 | |
---|
| 118 | if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']=''; |
---|
| 119 | |
---|
| 120 | if(!isset($_REQUEST['fASE_tabsheet'])) |
---|
| 121 | { |
---|
| 122 | $_REQUEST['fASE_tabsheet']="search"; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | if(!($_REQUEST['fASE_tabsheet']!="search" or |
---|
| 126 | $_REQUEST['fASE_tabsheet']!="config" |
---|
| 127 | )) $_REQUEST['fASE_tabsheet']="search"; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | * display the search page |
---|
| 134 | * |
---|
| 135 | */ |
---|
| 136 | protected function displaySearch() |
---|
| 137 | { |
---|
| 138 | global $template; |
---|
| 139 | |
---|
| 140 | GPCCore::addHeaderCSS('categorySelector', 'plugins/GrumPluginClasses/css/categorySelector_'.$template->get_themeconf('name').'.css'); |
---|
[7374] | 141 | GPCCore::addHeaderCSS('tagSelector', 'plugins/GrumPluginClasses/css/tagSelector_'.$template->get_themeconf('name').'.css'); |
---|
[7196] | 142 | |
---|
| 143 | |
---|
| 144 | $template->set_filename('body_page', |
---|
| 145 | dirname($this->getFileLocation()).'/admin/ase_search.tpl'); |
---|
| 146 | |
---|
| 147 | $template->assign('ase_search_page', GPCRequestBuilder::displaySearchPage()); |
---|
| 148 | |
---|
| 149 | $template->assign_var_from_handle('ASE_BODY_PAGE', 'body_page'); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | /** |
---|
| 154 | * display the config page |
---|
| 155 | * |
---|
| 156 | */ |
---|
| 157 | protected function displayConfig() |
---|
| 158 | { |
---|
| 159 | global $template; |
---|
| 160 | |
---|
[7207] | 161 | $this->modules=GPCRequestBuilder::getRegistered(); |
---|
| 162 | $this->updateConfig(); |
---|
| 163 | $this->configForTemplate(); |
---|
| 164 | |
---|
| 165 | $template->set_filename('body_page', |
---|
[7196] | 166 | dirname($this->getFileLocation()).'/admin/ase_config.tpl'); |
---|
| 167 | |
---|
[7207] | 168 | $cfgTabsheet = new GPCTabSheet('configTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itabcfg'); |
---|
| 169 | $cfgTabsheet->add('gallery', |
---|
| 170 | l10n('ase_gallery_integration'), |
---|
| 171 | '', true, "cm.displayTab('gallery');"); |
---|
| 172 | $cfgTabsheet->add('keyword', |
---|
| 173 | l10n('ase_keyword_module'), |
---|
| 174 | '', false, "cm.displayTab('keyword');"); |
---|
| 175 | $cfgTabsheet->assign(); |
---|
[7196] | 176 | |
---|
[7207] | 177 | |
---|
| 178 | foreach($this->modules as $key=>$val) |
---|
| 179 | { |
---|
| 180 | $this->modules[$key]=array( |
---|
| 181 | 'name' => l10n($val['name']), |
---|
| 182 | 'id' => $val['name'], |
---|
| 183 | 'accessible' => in_array($val['name'], $this->config['ase_publicAccess_allowedPlugins']) |
---|
| 184 | ); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | $datas=Array( |
---|
| 188 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
| 189 | 'modules' => $this->modules |
---|
| 190 | ); |
---|
| 191 | $template->assign('datas', $datas); |
---|
| 192 | |
---|
| 193 | $template->assign_var_from_handle('ASE_BODY_PAGE', 'body_page'); |
---|
[7196] | 194 | } |
---|
| 195 | |
---|
[7207] | 196 | /** |
---|
| 197 | * update config values |
---|
| 198 | */ |
---|
| 199 | protected function updateConfig() |
---|
| 200 | { |
---|
| 201 | global $infos; |
---|
[7196] | 202 | |
---|
[7207] | 203 | if(!isset($_POST) or count($_POST)==0) return(false); |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | if(isset($_POST['fPAActive']) and $_POST['fPAActive']=='on') |
---|
| 207 | { |
---|
| 208 | $this->config['ase_publicAccess_active']=true; |
---|
| 209 | } |
---|
| 210 | else |
---|
| 211 | { |
---|
| 212 | $this->config['ase_publicAccess_active']=false; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | if(isset($_POST['fPAApplyLimits']) and $_POST['fPAApplyLimits']=='on') |
---|
| 217 | { |
---|
| 218 | $this->config['ase_publicAccess_applyLimits']=true; |
---|
| 219 | } |
---|
| 220 | else |
---|
| 221 | { |
---|
| 222 | $this->config['ase_publicAccess_applyLimits']=false; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | if(isset($_POST['fKMinLength'])) $this->config['ase_keyword_minLength']=$_POST['fKMinLength']; |
---|
| 226 | |
---|
| 227 | if(isset($_POST['fPALimits'])) $this->config['ase_publicAccess_limits']=$_POST['fPALimits']; |
---|
| 228 | |
---|
| 229 | $this->config['ase_publicAccess_allowedPlugins']=array(); |
---|
| 230 | foreach($this->modules as $key=>$val) |
---|
| 231 | { |
---|
| 232 | if(isset($_POST['fModule'.$val['name']]) and $_POST['fModule'.$val['name']]=='on') $this->config['ase_publicAccess_allowedPlugins'][]=$val['name']; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | if($this->saveConfig()) |
---|
| 236 | { |
---|
| 237 | $this->displayResult(l10n('ase_config_saved'), true); |
---|
| 238 | return(true); |
---|
| 239 | } |
---|
| 240 | return(false); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | |
---|
[7196] | 244 | } //class |
---|
| 245 | |
---|
| 246 | |
---|
| 247 | ?> |
---|