| Conditions | 24 |
| Paths | 3252 |
| Total Lines | 161 |
| Code Lines | 95 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 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 |
||
| 245 | public function action_edit() |
||
| 246 | { |
||
| 247 | global $txt, $context, $modSettings, $editortxt; |
||
| 248 | |||
| 249 | $context['SPortal']['is_new'] = empty($_REQUEST['shoutbox_id']); |
||
| 250 | |||
| 251 | if (!empty($_POST['submit'])) |
||
| 252 | { |
||
| 253 | checkSession(); |
||
| 254 | |||
| 255 | if (!isset($_POST['name']) || Util::htmltrim(Util::htmlspecialchars($_POST['name'], ENT_QUOTES)) === '') |
||
| 256 | { |
||
| 257 | throw new Elk_Exception('sp_error_shoutbox_name_empty', false); |
||
| 258 | } |
||
| 259 | |||
| 260 | // No two the same |
||
| 261 | $has_duplicate = sp_check_duplicate_shoutbox($_POST['name'], $_POST['shoutbox_id']); |
||
| 262 | if (!empty($has_duplicate)) |
||
| 263 | { |
||
| 264 | throw new Elk_Exception('sp_error_shoutbox_name_duplicate', false); |
||
| 265 | } |
||
| 266 | |||
| 267 | if (isset($_POST['moderator_groups']) && is_array($_POST['moderator_groups']) && count($_POST['moderator_groups']) > 0) |
||
| 268 | { |
||
| 269 | foreach ($_POST['moderator_groups'] as $id => $group) |
||
| 270 | { |
||
| 271 | $_POST['moderator_groups'][$id] = (int) $group; |
||
| 272 | } |
||
| 273 | |||
| 274 | $_POST['moderator_groups'] = implode(',', $_POST['moderator_groups']); |
||
| 275 | } |
||
| 276 | else |
||
| 277 | { |
||
| 278 | $_POST['moderator_groups'] = ''; |
||
| 279 | } |
||
| 280 | |||
| 281 | if (!empty($_POST['allowed_bbc']) && is_array($_POST['allowed_bbc'])) |
||
| 282 | { |
||
| 283 | foreach ($_POST['allowed_bbc'] as $id => $tag) |
||
| 284 | { |
||
| 285 | $_POST['allowed_bbc'][$id] = Util::htmlspecialchars($tag, ENT_QUOTES); |
||
| 286 | } |
||
| 287 | |||
| 288 | $_POST['allowed_bbc'] = implode(',', $_POST['allowed_bbc']); |
||
| 289 | } |
||
| 290 | else |
||
| 291 | { |
||
| 292 | $_POST['allowed_bbc'] = ''; |
||
| 293 | } |
||
| 294 | |||
| 295 | $shoutbox_info = array( |
||
| 296 | 'id' => (int) $_POST['shoutbox_id'], |
||
| 297 | 'name' => Util::htmlspecialchars($_POST['name'], ENT_QUOTES), |
||
| 298 | 'permissions' => (int) $_POST['permissions'], |
||
| 299 | 'moderator_groups' => $_POST['moderator_groups'], |
||
| 300 | 'warning' => Util::htmlspecialchars($_POST['warning'], ENT_QUOTES), |
||
| 301 | 'allowed_bbc' => $_POST['allowed_bbc'], |
||
| 302 | 'height' => (int) $_POST['height'], |
||
| 303 | 'num_show' => (int) $_POST['num_show'], |
||
| 304 | 'num_max' => (int) $_POST['num_max'], |
||
| 305 | 'reverse' => !empty($_POST['reverse']) ? 1 : 0, |
||
| 306 | 'caching' => !empty($_POST['caching']) ? 1 : 0, |
||
| 307 | 'refresh' => (int) $_POST['refresh'], |
||
| 308 | 'status' => !empty($_POST['status']) ? 1 : 0, |
||
| 309 | ); |
||
| 310 | |||
| 311 | // Update existing or add a new shoutbox |
||
| 312 | $shoutbox_info['id'] = sp_edit_shoutbox($shoutbox_info, $context['SPortal']['is_new']); |
||
| 313 | |||
| 314 | sportal_update_shoutbox($shoutbox_info['id']); |
||
| 315 | |||
| 316 | if ($context['SPortal']['is_new'] && (allowedTo(array('sp_admin', 'sp_manage_blocks')))) |
||
| 317 | { |
||
| 318 | redirectexit('action=admin;area=portalshoutbox;sa=blockredirect;shoutbox=' . $shoutbox_info['id']); |
||
| 319 | } |
||
| 320 | else |
||
| 321 | { |
||
| 322 | redirectexit('action=admin;area=portalshoutbox'); |
||
| 323 | } |
||
| 324 | } |
||
| 325 | |||
| 326 | if ($context['SPortal']['is_new']) |
||
| 327 | { |
||
| 328 | $context['SPortal']['shoutbox'] = array( |
||
| 329 | 'id' => 0, |
||
| 330 | 'name' => $txt['sp_shoutbox_default_name'], |
||
| 331 | 'permissions' => 3, |
||
| 332 | 'moderator_groups' => array(), |
||
| 333 | 'warning' => '', |
||
| 334 | 'allowed_bbc' => array('b', 'i', 'u', 's', 'url', 'code', 'quote', 'me'), |
||
| 335 | 'height' => 200, |
||
| 336 | 'num_show' => 20, |
||
| 337 | 'num_max' => 1000, |
||
| 338 | 'reverse' => 0, |
||
| 339 | 'caching' => 1, |
||
| 340 | 'refresh' => 0, |
||
| 341 | 'status' => 1, |
||
| 342 | ); |
||
| 343 | } |
||
| 344 | else |
||
| 345 | { |
||
| 346 | $_REQUEST['shoutbox_id'] = (int) $_REQUEST['shoutbox_id']; |
||
| 347 | $context['SPortal']['shoutbox'] = sportal_get_shoutbox($_REQUEST['shoutbox_id']); |
||
| 348 | } |
||
| 349 | |||
| 350 | loadLanguage('Editor'); |
||
| 351 | |||
| 352 | $context['SPortal']['shoutbox']['permission_profiles'] = sportal_get_profiles(null, 1, 'name'); |
||
| 353 | sp_loadMemberGroups($context['SPortal']['shoutbox']['moderator_groups'], 'moderator', 'moderator_groups'); |
||
| 354 | |||
| 355 | if (empty($context['SPortal']['shoutbox']['permission_profiles'])) |
||
| 356 | { |
||
| 357 | throw new Elk_Exception('error_sp_no_permission_profiles', false); |
||
| 358 | } |
||
| 359 | |||
| 360 | // We only allow some BBC in the shoutbox |
||
| 361 | $context['allowed_bbc'] = array( |
||
| 362 | 'b' => $editortxt['Bold'], |
||
| 363 | 'i' => $editortxt['Italic'], |
||
| 364 | 'u' => $editortxt['Underline'], |
||
| 365 | 's' => $editortxt['Strikethrough'], |
||
| 366 | 'pre' => $editortxt['Preformatted Text'], |
||
| 367 | 'img' => $editortxt['Insert an image'], |
||
| 368 | 'url' => $editortxt['Insert a link'], |
||
| 369 | 'email' => $editortxt['Insert an email'], |
||
| 370 | 'sup' => $editortxt['Superscript'], |
||
| 371 | 'sub' => $editortxt['Subscript'], |
||
| 372 | 'tt' => $editortxt['Teletype'], |
||
| 373 | 'code' => $editortxt['Code'], |
||
| 374 | 'quote' => $editortxt['Insert a Quote'], |
||
| 375 | 'size' => $editortxt['Font Size'], |
||
| 376 | 'font' => $editortxt['Font Name'], |
||
| 377 | 'color' => $editortxt['Font Color'], |
||
| 378 | 'me' => 'me', |
||
| 379 | ); |
||
| 380 | |||
| 381 | // Remove the ones the admin does not allow |
||
| 382 | $disabled_tags = array(); |
||
| 383 | if (!empty($modSettings['disabledBBC'])) |
||
| 384 | { |
||
| 385 | $disabled_tags = explode(',', $modSettings['disabledBBC']); |
||
| 386 | } |
||
| 387 | if (empty($modSettings['enableEmbeddedFlash'])) |
||
| 388 | { |
||
| 389 | $disabled_tags[] = 'flash'; |
||
| 390 | } |
||
| 391 | |||
| 392 | foreach ($disabled_tags as $tag) |
||
| 393 | { |
||
| 394 | if ($tag == 'list') |
||
| 395 | { |
||
| 396 | $context['disabled_tags']['orderlist'] = true; |
||
| 397 | } |
||
| 398 | |||
| 399 | $context['disabled_tags'][trim($tag)] = true; |
||
| 400 | } |
||
| 401 | |||
| 402 | $context['page_title'] = $context['SPortal']['is_new'] |
||
| 403 | ? $txt['sp_admin_shoutbox_add'] |
||
| 404 | : $txt['sp_admin_shoutbox_edit']; |
||
| 405 | $context['sub_template'] = 'shoutbox_edit'; |
||
| 406 | } |
||
| 527 |