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; |
---|
25 | protected $modules; |
---|
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'); |
---|
141 | |
---|
142 | |
---|
143 | $template->set_filename('body_page', |
---|
144 | dirname($this->getFileLocation()).'/admin/ase_search.tpl'); |
---|
145 | |
---|
146 | $template->assign('ase_search_page', GPCRequestBuilder::displaySearchPage()); |
---|
147 | |
---|
148 | $template->assign_var_from_handle('ASE_BODY_PAGE', 'body_page'); |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | /** |
---|
153 | * display the config page |
---|
154 | * |
---|
155 | */ |
---|
156 | protected function displayConfig() |
---|
157 | { |
---|
158 | global $template; |
---|
159 | |
---|
160 | $this->modules=GPCRequestBuilder::getRegistered(); |
---|
161 | $this->updateConfig(); |
---|
162 | $this->configForTemplate(); |
---|
163 | |
---|
164 | $template->set_filename('body_page', |
---|
165 | dirname($this->getFileLocation()).'/admin/ase_config.tpl'); |
---|
166 | |
---|
167 | $cfgTabsheet = new GPCTabSheet('configTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itabcfg'); |
---|
168 | $cfgTabsheet->add('gallery', |
---|
169 | l10n('ase_gallery_integration'), |
---|
170 | '', true, "cm.displayTab('gallery');"); |
---|
171 | $cfgTabsheet->add('keyword', |
---|
172 | l10n('ase_keyword_module'), |
---|
173 | '', false, "cm.displayTab('keyword');"); |
---|
174 | $cfgTabsheet->assign(); |
---|
175 | |
---|
176 | |
---|
177 | foreach($this->modules as $key=>$val) |
---|
178 | { |
---|
179 | $this->modules[$key]=array( |
---|
180 | 'name' => l10n($val['name']), |
---|
181 | 'id' => $val['name'], |
---|
182 | 'accessible' => in_array($val['name'], $this->config['ase_publicAccess_allowedPlugins']) |
---|
183 | ); |
---|
184 | } |
---|
185 | |
---|
186 | $datas=Array( |
---|
187 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
188 | 'modules' => $this->modules |
---|
189 | ); |
---|
190 | $template->assign('datas', $datas); |
---|
191 | |
---|
192 | $template->assign_var_from_handle('ASE_BODY_PAGE', 'body_page'); |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * update config values |
---|
197 | */ |
---|
198 | protected function updateConfig() |
---|
199 | { |
---|
200 | global $infos; |
---|
201 | |
---|
202 | if(!isset($_POST) or count($_POST)==0) return(false); |
---|
203 | |
---|
204 | |
---|
205 | if(isset($_POST['fPAActive']) and $_POST['fPAActive']=='on') |
---|
206 | { |
---|
207 | $this->config['ase_publicAccess_active']=true; |
---|
208 | } |
---|
209 | else |
---|
210 | { |
---|
211 | $this->config['ase_publicAccess_active']=false; |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | if(isset($_POST['fPAApplyLimits']) and $_POST['fPAApplyLimits']=='on') |
---|
216 | { |
---|
217 | $this->config['ase_publicAccess_applyLimits']=true; |
---|
218 | } |
---|
219 | else |
---|
220 | { |
---|
221 | $this->config['ase_publicAccess_applyLimits']=false; |
---|
222 | } |
---|
223 | |
---|
224 | if(isset($_POST['fKMinLength'])) $this->config['ase_keyword_minLength']=$_POST['fKMinLength']; |
---|
225 | |
---|
226 | if(isset($_POST['fPALimits'])) $this->config['ase_publicAccess_limits']=$_POST['fPALimits']; |
---|
227 | |
---|
228 | $this->config['ase_publicAccess_allowedPlugins']=array(); |
---|
229 | foreach($this->modules as $key=>$val) |
---|
230 | { |
---|
231 | if(isset($_POST['fModule'.$val['name']]) and $_POST['fModule'.$val['name']]=='on') $this->config['ase_publicAccess_allowedPlugins'][]=$val['name']; |
---|
232 | } |
---|
233 | |
---|
234 | if($this->saveConfig()) |
---|
235 | { |
---|
236 | $this->displayResult(l10n('ase_config_saved'), true); |
---|
237 | return(true); |
---|
238 | } |
---|
239 | return(false); |
---|
240 | } |
---|
241 | |
---|
242 | |
---|
243 | } //class |
---|
244 | |
---|
245 | |
---|
246 | ?> |
---|