Conditions | 56 |
Paths | > 20000 |
Total Lines | 266 |
Code Lines | 149 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | function index($params=null) |
||
24 | { |
||
25 | // if we have a xet file, run new et2 config |
||
26 | if (file_exists(EGW_SERVER_ROOT.'/'.$_GET['appname'].'/templates/default/config.xet')) |
||
27 | { |
||
28 | $new_config = new admin_config(); |
||
29 | return $new_config->index(); |
||
|
|||
30 | } |
||
31 | // allowing inline js |
||
32 | Api\Header\ContentSecurityPolicy::add('script-src', 'unsafe-inline'); |
||
33 | |||
34 | // for POST requests validate CSRF token (or terminate request) |
||
35 | if ($_SERVER['REQUEST_METHOD'] == 'POST') |
||
36 | { |
||
37 | Api\Csrf::validate($_POST['csrf_token'], __CLASS__); |
||
38 | } |
||
39 | |||
40 | if (empty($_GET['appname']) && isset($params['appname'])) |
||
41 | { |
||
42 | $_appname = $params['appname']; |
||
43 | } |
||
44 | else |
||
45 | { |
||
46 | //_debug_array($params); |
||
47 | $_appname = $_GET['appname']; |
||
48 | } |
||
49 | if ($GLOBALS['egw']->acl->check('site_config_acce',1,'admin')) |
||
50 | { |
||
51 | Egw::redirect_link('/index.php'); |
||
52 | } |
||
53 | |||
54 | // load the translations of the app we show too, so they dont need to be in admin! |
||
55 | if ($_appname != 'admin') |
||
56 | { |
||
57 | Api\Translation::add_app($_appname); |
||
58 | } |
||
59 | |||
60 | if(get_magic_quotes_gpc() && is_array($_POST['newsettings'])) |
||
61 | { |
||
62 | $_POST['newsettings'] = array_stripslashes($_POST['newsettings']); |
||
63 | } |
||
64 | |||
65 | switch($_appname) |
||
66 | { |
||
67 | case 'admin': |
||
68 | case 'addressbook': |
||
69 | case 'calendar': |
||
70 | case 'preferences': |
||
71 | /* |
||
72 | Other special apps can go here for now, e.g.: |
||
73 | case 'bogusappname': |
||
74 | */ |
||
75 | $appname = $_appname; |
||
76 | $config_appname = 'phpgwapi'; |
||
77 | break; |
||
78 | case 'phpgwapi': |
||
79 | case '': |
||
80 | /* This keeps the admin from getting into what is a setup-only Api\Config */ |
||
81 | Egw::redirect_link('/admin/index.php'); |
||
82 | break; |
||
83 | default: |
||
84 | $appname = $_appname; |
||
85 | $config_appname = $appname; |
||
86 | break; |
||
87 | } |
||
88 | if (ob_get_contents()) ob_end_flush(); // if there is output in buffer, flush it now. |
||
89 | $t = new Framework\Template(Framework\Template::get_dir($appname)); |
||
90 | $t->set_unknowns('keep'); |
||
91 | $t->set_file(array('config' => 'config.tpl')); |
||
92 | $t->set_block('config','header','header'); |
||
93 | |||
94 | // fix header templates missing essential parts like display of validation errors |
||
95 | $header = $t->get_var('header'); |
||
96 | if (strpos($header, '{hidden_vars}') === false) |
||
97 | { |
||
98 | if (strpos($header, '<table')) |
||
99 | { |
||
100 | list($header, $table) = explode('<table', $header); |
||
101 | $header .= "{hidden_vars}\n<table".$table; |
||
102 | } |
||
103 | else |
||
104 | { |
||
105 | $header .= "{hidden_vars}\n"; |
||
106 | } |
||
107 | } |
||
108 | $t->set_var('header', $header); |
||
109 | |||
110 | $t->set_block('config','body','body'); |
||
111 | $t->set_block('config','footer','footer'); |
||
112 | |||
113 | // fix footer submit buttons to just {submit} {cancel} |
||
114 | $t->set_var('footer', preg_replace('/<input[^>]+value="{lang_(submit|cancel)}"[^>]*>/', '{$1}', $t->get_var('footer'))); |
||
115 | |||
116 | $c = new Api\Config($config_appname); |
||
117 | $c->read_repository(); |
||
118 | if ($_POST['cancel'] || ($_POST['submit'] || $_POST['save'] || $_POST['apply']) && $GLOBALS['egw']->acl->check('site_config_acce',2,'admin')) |
||
119 | { |
||
120 | Egw::redirect_link('/admin/index.php?ajax=true'); |
||
121 | } |
||
122 | |||
123 | if ($_POST['submit'] || $_POST['save'] || $_POST['apply']) |
||
124 | { |
||
125 | /* Load hook file with functions to validate each Api\Config (one/none/all) */ |
||
126 | Api\Hooks::single('config_validate',$appname); |
||
127 | |||
128 | foreach($_POST['newsettings'] as $key => $config) |
||
129 | { |
||
130 | if ($config) |
||
131 | { |
||
132 | $c->config_data[$key] = $config; |
||
133 | if (in_array($key, (array)$GLOBALS['egw_info']['server']['found_validation_hook'], true) && function_exists($key)) |
||
134 | { |
||
135 | call_user_func($key, $config, $c); |
||
136 | if($GLOBALS['config_error']) |
||
137 | { |
||
138 | $errors .= lang($GLOBALS['config_error']) . "\n"; |
||
139 | $GLOBALS['config_error'] = False; |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 | /* don't erase passwords, since we also don't print them */ |
||
144 | elseif(strpos($key,'passwd') === false && strpos($key,'password') === false && strpos($key,'root_pw') === false) |
||
145 | { |
||
146 | unset($c->config_data[$key]); |
||
147 | } |
||
148 | } |
||
149 | if(in_array('final_validation', (array)$GLOBALS['egw_info']['server']['found_validation_hook']) && |
||
150 | function_exists('final_validation')) |
||
151 | { |
||
152 | final_validation($_POST['newsettings']); |
||
153 | if($GLOBALS['config_error']) |
||
154 | { |
||
155 | $errors .= lang($GLOBALS['config_error']) . "\n"; |
||
156 | $GLOBALS['config_error'] = False; |
||
157 | } |
||
158 | unset($GLOBALS['egw_info']['server']['found_validation_hook']); |
||
159 | } |
||
160 | |||
161 | $c->save_repository(); |
||
162 | |||
163 | if(!$errors && !$_POST['apply']) |
||
164 | { |
||
165 | Framework::message(lang('Configuration saved.'), 'success'); |
||
166 | Egw::redirect_link('/index.php', array( |
||
167 | 'menuaction' => 'admin.admin_ui.index', |
||
168 | 'ajax' => 'true' |
||
169 | ), 'admin'); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | $t->set_var('error',''); |
||
174 | if($errors) |
||
175 | { |
||
176 | Framework::message(lang('Error') . ': ' . $errors, 'error'); |
||
177 | unset($errors); |
||
178 | unset($GLOBALS['config_error']); |
||
179 | } |
||
180 | elseif ($_POST['apply']) |
||
181 | { |
||
182 | Framework::message(lang('Configuration saved.'), 'success'); |
||
183 | } |
||
184 | $t->set_var('title',lang('Site Configuration')); |
||
185 | $t->set_var('action_url',$GLOBALS['egw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname)); |
||
186 | $t->set_var('th_bg', $GLOBALS['egw_info']['theme']['th_bg']); |
||
187 | $t->set_var('th_text', $GLOBALS['egw_info']['theme']['th_text']); |
||
188 | $t->set_var('row_on', $GLOBALS['egw_info']['theme']['row_on']); |
||
189 | $t->set_var('row_off', $GLOBALS['egw_info']['theme']['row_off']); |
||
190 | $t->set_var('hidden_vars', Api\Html::input_hidden('csrf_token', Api\Csrf::token(__CLASS__))); |
||
191 | |||
192 | $vars = $t->get_undefined('body'); |
||
193 | |||
194 | if (Api\Hooks::single('config',$appname)) // reload the config-values, they might have changed |
||
195 | { |
||
196 | $c->read_repository(); |
||
197 | } |
||
198 | foreach($vars as $value) |
||
199 | { |
||
200 | $valarray = explode('_',$value); |
||
201 | $type = array_shift($valarray); |
||
202 | $newval = implode(' ',$valarray); |
||
203 | |||
204 | switch ($type) |
||
205 | { |
||
206 | case 'lang': |
||
207 | $t->set_var($value,lang($newval)); |
||
208 | break; |
||
209 | case 'value': |
||
210 | $newval = str_replace(' ','_',$newval); |
||
211 | /* Don't show passwords in the form */ |
||
212 | if(strpos($value,'passwd') !== false || strpos($value,'password') !== false || strpos($value,'root_pw') !== false) |
||
213 | { |
||
214 | $t->set_var($value,''); |
||
215 | } |
||
216 | else |
||
217 | { |
||
218 | $t->set_var($value,$c->config_data[$newval]); |
||
219 | } |
||
220 | break; |
||
221 | /* |
||
222 | case 'checked': |
||
223 | $newval = str_replace(' ','_',$newval); |
||
224 | if ($c->config_data[$newval]) |
||
225 | { |
||
226 | $t->set_var($value,' checked'); |
||
227 | } |
||
228 | else |
||
229 | { |
||
230 | $t->set_var($value,''); |
||
231 | } |
||
232 | break; |
||
233 | */ |
||
234 | case 'selected': |
||
235 | $configs = array(); |
||
236 | $newvals = explode(' ',$newval); |
||
237 | $setting = end($newvals); |
||
238 | for ($i=0;$i<(count($newvals) - 1); $i++) |
||
239 | { |
||
240 | $configs[] = $newvals[$i]; |
||
241 | } |
||
242 | $config = implode('_',$configs); |
||
243 | /* echo $config . '=' . $c->config_data[$config]; */ |
||
244 | if ($c->config_data[$config] == $setting) |
||
245 | { |
||
246 | $t->set_var($value,' selected'); |
||
247 | } |
||
248 | else |
||
249 | { |
||
250 | $t->set_var($value,''); |
||
251 | } |
||
252 | break; |
||
253 | case 'hook': |
||
254 | $newval = str_replace(' ','_',$newval); |
||
255 | if(function_exists($newval)) |
||
256 | { |
||
257 | $t->set_var($value,$newval($c->config_data)); |
||
258 | } |
||
259 | else |
||
260 | { |
||
261 | $t->set_var($value,''); |
||
262 | } |
||
263 | break; |
||
264 | case 'call': // eg. call_class::method or call_app.class.method |
||
265 | $newval = str_replace(' ','_',$newval); |
||
266 | $t->set_var($value,ExecMethod($newval,$c->config_data)); |
||
267 | break; |
||
268 | default: |
||
269 | $t->set_var($value,''); |
||
270 | break; |
||
271 | } |
||
272 | } |
||
273 | $t->set_var('submit', '<div class="dialogFooterToolbar" style="text-align: left">'. |
||
274 | ($GLOBALS['egw']->acl->check('site_config_acce',2,'admin') ? '' : |
||
275 | Api\Html::submit_button('save', 'Save')."\n". |
||
276 | Api\Html::submit_button('apply', 'Apply'))); |
||
277 | $t->set_var('cancel', Api\Html::submit_button('cancel', 'Cancel').'</div>'); |
||
278 | |||
279 | $GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration'). |
||
280 | ($appname != 'admin' ? ': '.lang($appname) : ''); |
||
281 | |||
282 | // render the page |
||
283 | $GLOBALS['egw']->framework->render( |
||
284 | '<div id="admin-config-'.$appname.'" class="admin-config">'. |
||
285 | $t->parse('out','header'). |
||
286 | $t->fp('out','body'). |
||
287 | $t->fp('out','footer').'</div>', |
||
288 | null,true |
||
289 | ); |
||
292 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.