Conditions | 47 |
Paths | 109 |
Total Lines | 109 |
Code Lines | 76 |
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 if (!defined('BB2_CWD')) die("I said no cheating!"); |
||
127 | function bb2_screen($settings, $package) |
||
128 | { |
||
129 | // Please proceed to the security checkpoint, have your identification |
||
130 | // and boarding pass ready, and prepare to be nakedized or fondled. |
||
131 | |||
132 | // CloudFlare-specific checks not handled by reverse proxy code |
||
133 | // Thanks to butchs at Simple Machines |
||
134 | if (array_key_exists('Cf-Connecting-Ip', $package['headers_mixed'])) { |
||
135 | require_once(BB2_CORE . "/cloudflare.inc.php"); |
||
136 | $r = bb2_cloudflare($package); |
||
137 | if ($r !== false && $r != $package['ip']) return $r; |
||
138 | } |
||
139 | |||
140 | // First check the whitelist |
||
141 | require_once(BB2_CORE . "/whitelist.inc.php"); |
||
142 | if (!bb2_run_whitelist($package)) { |
||
143 | // Now check the blacklist |
||
144 | require_once(BB2_CORE . "/blacklist.inc.php"); |
||
145 | if ($r = bb2_blacklist($package)) return $r; |
||
146 | |||
147 | // Check the http:BL |
||
148 | require_once(BB2_CORE . "/blackhole.inc.php"); |
||
149 | if ($r = bb2_httpbl($settings, $package)) { |
||
150 | if ($r == 1) return false; # whitelisted |
||
151 | return $r; |
||
152 | } |
||
153 | |||
154 | // Check for common stuff |
||
155 | require_once(BB2_CORE . "/common_tests.inc.php"); |
||
156 | if ($r = bb2_protocol($settings, $package)) return $r; |
||
157 | if ($r = bb2_cookies($settings, $package)) return $r; |
||
158 | if ($r = bb2_misc_headers($settings, $package)) return $r; |
||
159 | |||
160 | // Specific checks |
||
161 | @$ua = $package['user_agent']; |
||
162 | // Search engine checks come first |
||
163 | if (stripos($ua, "bingbot") !== FALSE || stripos($ua, "msnbot") !== FALSE || stripos($ua, "MS Search") !== FALSE) { |
||
164 | require_once(BB2_CORE . "/searchengine.inc.php"); |
||
165 | if ($r = bb2_msnbot($package)) { |
||
166 | if ($r == 1) return false; # whitelisted |
||
167 | return $r; |
||
168 | } |
||
169 | return false; |
||
170 | } elseif (stripos($ua, "Googlebot") !== FALSE || stripos($ua, "Mediapartners-Google") !== FALSE || stripos($ua, "Google Web Preview") !== FALSE) { |
||
171 | require_once(BB2_CORE . "/searchengine.inc.php"); |
||
172 | if ($r = bb2_google($package)) { |
||
173 | if ($r == 1) return false; # whitelisted |
||
174 | return $r; |
||
175 | } |
||
176 | return false; |
||
177 | } elseif (stripos($ua, "Yahoo! Slurp") !== FALSE || stripos($ua, "Yahoo! SearchMonkey") !== FALSE) { |
||
178 | require_once(BB2_CORE . "/searchengine.inc.php"); |
||
179 | if ($r = bb2_yahoo($package)) { |
||
180 | if ($r == 1) return false; # whitelisted |
||
181 | return $r; |
||
182 | } |
||
183 | return false; |
||
184 | } elseif (stripos($ua, "Baidu") !== FALSE) { |
||
185 | require_once(BB2_CORE . "/searchengine.inc.php"); |
||
186 | if ($r = bb2_baidu($package)) { |
||
187 | if ($r == 1) return false; # whitelisted |
||
188 | return $r; |
||
189 | } |
||
190 | return false; |
||
191 | } |
||
192 | // MSIE checks |
||
193 | if (stripos($ua, "; MSIE") !== FALSE) { |
||
194 | $package['is_browser'] = true; |
||
195 | require_once(BB2_CORE . "/browser.inc.php"); |
||
196 | if (stripos($ua, "Opera") !== FALSE) { |
||
197 | if ($r = bb2_opera($package)) return $r; |
||
198 | } else { |
||
199 | if ($r = bb2_msie($package)) return $r; |
||
200 | } |
||
201 | } elseif (stripos($ua, "Konqueror") !== FALSE) { |
||
202 | $package['is_browser'] = true; |
||
203 | require_once(BB2_CORE . "/browser.inc.php"); |
||
204 | if ($r = bb2_konqueror($package)) return $r; |
||
205 | } elseif (stripos($ua, "Opera") !== FALSE) { |
||
206 | $package['is_browser'] = true; |
||
207 | require_once(BB2_CORE . "/browser.inc.php"); |
||
208 | if ($r = bb2_opera($package)) return $r; |
||
209 | } elseif (stripos($ua, "Safari") !== FALSE) { |
||
210 | $package['is_browser'] = true; |
||
211 | require_once(BB2_CORE . "/browser.inc.php"); |
||
212 | if ($r = bb2_safari($package)) return $r; |
||
213 | } elseif (stripos($ua, "Lynx") !== FALSE) { |
||
214 | $package['is_browser'] = true; |
||
215 | require_once(BB2_CORE . "/browser.inc.php"); |
||
216 | if ($r = bb2_lynx($package)) return $r; |
||
217 | } elseif (stripos($ua, "MovableType") !== FALSE) { |
||
218 | require_once(BB2_CORE . "/movabletype.inc.php"); |
||
219 | if ($r = bb2_movabletype($package)) return $r; |
||
220 | } elseif (stripos($ua, "Mozilla") !== FALSE && stripos($ua, "Mozilla") == 0) { |
||
221 | $package['is_browser'] = true; |
||
222 | require_once(BB2_CORE . "/browser.inc.php"); |
||
223 | if ($r = bb2_mozilla($package)) return $r; |
||
224 | } |
||
225 | |||
226 | // More intensive screening applies to POST requests |
||
227 | if (!strcasecmp('POST', $package['request_method'])) { |
||
228 | require_once(BB2_CORE . "/post.inc.php"); |
||
229 | if ($r = bb2_post($settings, $package)) return $r; |
||
230 | } |
||
231 | } |
||
232 | |||
233 | // And that's about it. |
||
234 | bb2_approved($settings, $package); |
||
235 | return false; |
||
236 | } |
||
237 |