Conditions | 17 |
Paths | 49 |
Total Lines | 65 |
Code Lines | 30 |
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 |
||
154 | function elk_main() |
||
155 | { |
||
156 | global $modSettings, $user_info, $topic, $board_info, $context; |
||
157 | |||
158 | // Special case: session keep-alive, output a transparent pixel. |
||
159 | if (isset($_GET['action']) && $_GET['action'] == 'keepalive') |
||
160 | { |
||
161 | header('Content-Type: image/gif'); |
||
162 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
||
163 | } |
||
164 | |||
165 | // We should set our security headers now. |
||
166 | frameOptionsHeader(); |
||
167 | securityOptionsHeader(); |
||
168 | |||
169 | // Load the user's cookie (or set as guest) and load their settings. |
||
170 | loadUserSettings(); |
||
171 | |||
172 | // Load the current board's information. |
||
173 | loadBoard(); |
||
174 | |||
175 | // Load the current user's permissions. |
||
176 | loadPermissions(); |
||
177 | |||
178 | // Load BadBehavior before we go much further |
||
179 | loadBadBehavior(); |
||
180 | |||
181 | // Attachments don't require the entire theme to be loaded. |
||
182 | if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach' && (!empty($modSettings['allow_guestAccess']) && $user_info['is_guest'])) |
||
183 | detectBrowser(); |
||
184 | // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) |
||
185 | else |
||
186 | loadTheme(); |
||
187 | |||
188 | // Check if the user should be disallowed access. |
||
189 | is_not_banned(); |
||
190 | |||
191 | // If we are in a topic and don't have permission to approve it then duck out now. |
||
192 | if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) |
||
193 | fatal_lang_error('not_a_topic', false); |
||
194 | |||
195 | $no_stat_actions = array('dlattach', 'findmember', 'jsoption', 'requestmembers', 'jslocale', 'xmlpreview', 'suggest', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewadminfile'); |
||
196 | call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions)); |
||
197 | |||
198 | // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc. |
||
199 | if (empty($_REQUEST['action']) || !in_array($_REQUEST['action'], $no_stat_actions)) |
||
200 | { |
||
201 | // I see you! |
||
202 | writeLog(); |
||
203 | |||
204 | // Track forum statistics and hits...? |
||
205 | if (!empty($modSettings['hitStats'])) |
||
206 | trackStats(array('hits' => '+')); |
||
207 | } |
||
208 | unset($no_stat_actions); |
||
209 | |||
210 | // What shall we do? |
||
211 | require_once(SOURCEDIR . '/SiteDispatcher.class.php'); |
||
212 | $dispatcher = new Site_Dispatcher(); |
||
213 | |||
214 | // Show where we came from, and go |
||
215 | $context['site_action'] = $dispatcher->site_action(); |
||
216 | $context['site_action'] = !empty($context['site_action']) ? $context['site_action'] : (isset($_REQUEST['action']) ? $_REQUEST['action'] : ''); |
||
217 | $dispatcher->dispatch(); |
||
218 | } |
||
219 |