| Conditions | 32 |
| Paths | 784 |
| Total Lines | 350 |
| Lines | 17 |
| Ratio | 4.86 % |
| 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 |
||
| 203 | public function management_page() { |
||
| 204 | $sharer = new Sharing_Service(); |
||
| 205 | $enabled = $sharer->get_blog_services(); |
||
| 206 | $global = $sharer->get_global_options(); |
||
| 207 | |||
| 208 | $shows = array_values( get_post_types( array( 'public' => true ) ) ); |
||
| 209 | array_unshift( $shows, 'index' ); |
||
| 210 | |||
| 211 | if ( false == function_exists( 'mb_stripos' ) ) { |
||
|
|
|||
| 212 | echo '<div id="message" class="updated fade"><h3>' . __( 'Warning! Multibyte support missing!', 'jetpack' ) . '</h3>'; |
||
| 213 | echo '<p>' . sprintf( __( 'This plugin will work without it, but multibyte support is used <a href="%s" rel="noopener noreferrer" target="_blank">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack' ), 'http://www.php.net/manual/en/mbstring.installation.php' ) . '</p></div>'; |
||
| 214 | } |
||
| 215 | |||
| 216 | if ( isset( $_GET['update'] ) && $_GET['update'] == 'saved' ) { |
||
| 217 | echo '<div class="updated"><p>' . __( 'Settings have been saved', 'jetpack' ) . '</p></div>'; |
||
| 218 | } |
||
| 219 | |||
| 220 | if ( ! isset( $global['sharing_label'] ) ) { |
||
| 221 | $global['sharing_label'] = __( 'Share this:', 'jetpack' ); |
||
| 222 | } |
||
| 223 | ?> |
||
| 224 | |||
| 225 | <div class="wrap"> |
||
| 226 | <div class="icon32" id="icon-options-general"><br /></div> |
||
| 227 | <h1><?php _e( 'Sharing Settings', 'jetpack' ); ?></h1> |
||
| 228 | |||
| 229 | <?php |
||
| 230 | /** |
||
| 231 | * Fires at the top of the admin sharing settings screen. |
||
| 232 | * |
||
| 233 | * @module sharedaddy |
||
| 234 | * |
||
| 235 | * @since 1.6.0 |
||
| 236 | */ |
||
| 237 | do_action( 'pre_admin_screen_sharing' ); |
||
| 238 | ?> |
||
| 239 | |||
| 240 | <?php if ( current_user_can( 'manage_options' ) ) : ?> |
||
| 241 | |||
| 242 | <div class="share_manage_options"> |
||
| 243 | <h2><?php _e( 'Sharing Buttons', 'jetpack' ) ?></h2> |
||
| 244 | <p><?php _e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ) ?></p> |
||
| 245 | |||
| 246 | <div id="services-config"> |
||
| 247 | <table id="available-services"> |
||
| 248 | <tr> |
||
| 249 | <td class="description"> |
||
| 250 | <h3><?php _e( 'Available Services', 'jetpack' ); ?></h3> |
||
| 251 | <p><?php _e( "Drag and drop the services you'd like to enable into the box below.", 'jetpack' ); ?></p> |
||
| 252 | <p><a href="#TB_inline?height=395&width=600&inlineId=new-service" class="thickbox" id="add-a-new-service"><?php _e( 'Add a new service', 'jetpack' ); ?></a></p> |
||
| 253 | </td> |
||
| 254 | <td class="services"> |
||
| 255 | <ul class="services-available" style="height: 100px;"> |
||
| 256 | <?php foreach ( $sharer->get_all_services_blog() as $id => $service ) : ?> |
||
| 257 | <?php |
||
| 258 | if ( ! isset( $enabled['all'][ $id ] ) ) { |
||
| 259 | $this->output_service( $id, $service ); |
||
| 260 | } |
||
| 261 | ?> |
||
| 262 | <?php endforeach; ?> |
||
| 263 | </ul> |
||
| 264 | <?php |
||
| 265 | if ( -1 == get_option( 'blog_public' ) ) { |
||
| 266 | echo '<p><strong>' . __( 'Please note that your services have been restricted because your site is private.', 'jetpack' ) . '</strong></p>'; |
||
| 267 | } |
||
| 268 | ?> |
||
| 269 | <br class="clearing" /> |
||
| 270 | </td> |
||
| 271 | </tr> |
||
| 272 | </table> |
||
| 273 | |||
| 274 | <table id="enabled-services"> |
||
| 275 | <tr> |
||
| 276 | <td class="description"> |
||
| 277 | <h3> |
||
| 278 | <?php _e( 'Enabled Services', 'jetpack' ); ?> |
||
| 279 | <img src="<?php echo admin_url( 'images/loading.gif' ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> |
||
| 280 | </h3> |
||
| 281 | <p><?php _e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p> |
||
| 282 | </td> |
||
| 283 | <td class="services" id="share-drop-target"> |
||
| 284 | <h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) { echo ' style="display: none"';} ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2> |
||
| 285 | |||
| 286 | <ul class="services-enabled"> |
||
| 287 | <?php foreach ( $enabled['visible'] as $id => $service ) : ?> |
||
| 288 | <?php $this->output_service( $id, $service, true ); ?> |
||
| 289 | <?php endforeach; ?> |
||
| 290 | |||
| 291 | <li class="end-fix"></li> |
||
| 292 | </ul> |
||
| 293 | </td> |
||
| 294 | <td id="hidden-drop-target" class="services"> |
||
| 295 | <p><?php _e( 'Services dragged here will be hidden behind a share button.', 'jetpack' ); ?></p> |
||
| 296 | |||
| 297 | <ul class="services-hidden"> |
||
| 298 | <?php foreach ( $enabled['hidden'] as $id => $service ) : ?> |
||
| 299 | <?php $this->output_service( $id, $service, true ); ?> |
||
| 300 | <?php endforeach; ?> |
||
| 301 | <li class="end-fix"></li> |
||
| 302 | </ul> |
||
| 303 | </td> |
||
| 304 | </tr> |
||
| 305 | </table> |
||
| 306 | |||
| 307 | <table id="live-preview"> |
||
| 308 | <tr> |
||
| 309 | <td class="description"> |
||
| 310 | <h3><?php _e( 'Live Preview', 'jetpack' ); ?></h3> |
||
| 311 | </td> |
||
| 312 | <td class="services"> |
||
| 313 | <h2 <?php echo ( count( $enabled['all'] ) > 0 ) ? ' style="display: none"' : ''; ?>><?php _e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2> |
||
| 314 | <div class="sharedaddy sd-sharing-enabled"> |
||
| 315 | <?php if ( count( $enabled['all'] ) > 0 ) : ?> |
||
| 316 | <h3 class="sd-title"><?php echo esc_html( $global['sharing_label'] ); ?></h3> |
||
| 317 | <?php endif; ?> |
||
| 318 | <div class="sd-content"> |
||
| 319 | <ul class="preview"> |
||
| 320 | <?php foreach ( $enabled['visible'] as $id => $service ) : ?> |
||
| 321 | <?php $this->output_preview( $service ); ?> |
||
| 322 | <?php endforeach; ?> |
||
| 323 | |||
| 324 | <?php if ( count( $enabled['hidden'] ) > 0 ) : ?> |
||
| 325 | <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e( 'More', 'jetpack' ); ?></span></a></li> |
||
| 326 | <?php endif; ?> |
||
| 327 | </ul> |
||
| 328 | |||
| 329 | <?php if ( count( $enabled['hidden'] ) > 0 ) : ?> |
||
| 330 | <div class="sharing-hidden"> |
||
| 331 | <div class="inner" style="display: none; <?php echo count( $enabled['hidden'] ) == 1 ? 'width:150px;' : ''; ?>"> |
||
| 332 | <?php if ( count( $enabled['hidden'] ) == 1 ) : ?> |
||
| 333 | <ul style="background-image:none;"> |
||
| 334 | <?php else : ?> |
||
| 335 | <ul> |
||
| 336 | <?php endif; ?> |
||
| 337 | |||
| 338 | <?php |
||
| 339 | foreach ( $enabled['hidden'] as $id => $service ) { |
||
| 340 | $this->output_preview( $service ); |
||
| 341 | } |
||
| 342 | ?> |
||
| 343 | </ul> |
||
| 344 | </div> |
||
| 345 | </div> |
||
| 346 | <?php endif; ?> |
||
| 347 | |||
| 348 | <ul class="archive" style="display:none;"> |
||
| 349 | <?php |
||
| 350 | foreach ( $sharer->get_all_services_blog() as $id => $service ) : |
||
| 351 | if ( isset( $enabled['visible'][ $id ] ) ) { |
||
| 352 | $service = $enabled['visible'][ $id ]; |
||
| 353 | } elseif ( isset( $enabled['hidden'][ $id ] ) ) { |
||
| 354 | $service = $enabled['hidden'][ $id ]; |
||
| 355 | } |
||
| 356 | |||
| 357 | $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later |
||
| 358 | $service->smart = false; |
||
| 359 | $this->output_preview( $service ); |
||
| 360 | endforeach; ?> |
||
| 361 | <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e( 'More', 'jetpack' ); ?></span></a></li> |
||
| 362 | </ul> |
||
| 363 | </div> |
||
| 364 | </div> |
||
| 365 | <br class="clearing" /> |
||
| 366 | </td> |
||
| 367 | </tr> |
||
| 368 | </table> |
||
| 369 | |||
| 370 | <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>" id="save-enabled-shares"> |
||
| 371 | <input type="hidden" name="action" value="sharing_save_services" /> |
||
| 372 | <input type="hidden" name="visible" value="<?php echo implode( ',', array_keys( $enabled['visible'] ) ); ?>" /> |
||
| 373 | <input type="hidden" name="hidden" value="<?php echo implode( ',', array_keys( $enabled['hidden'] ) ); ?>" /> |
||
| 374 | <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" /> |
||
| 375 | </form> |
||
| 376 | </div> |
||
| 377 | |||
| 378 | <form method="post" action=""> |
||
| 379 | <table class="form-table"> |
||
| 380 | <tbody> |
||
| 381 | <tr valign="top"> |
||
| 382 | <th scope="row"><label><?php _e( 'Button style', 'jetpack' ); ?></label></th> |
||
| 383 | <td> |
||
| 384 | <select name="button_style" id="button_style"> |
||
| 385 | <option<?php echo ( $global['button_style'] == 'icon-text' ) ? ' selected="selected"' : ''; ?> value="icon-text"><?php _e( 'Icon + text', 'jetpack' ); ?></option> |
||
| 386 | <option<?php echo ( $global['button_style'] == 'icon' ) ? ' selected="selected"' : ''; ?> value="icon"><?php _e( 'Icon only', 'jetpack' ); ?></option> |
||
| 387 | <option<?php echo ( $global['button_style'] == 'text' ) ? ' selected="selected"' : ''; ?> value="text"><?php _e( 'Text only', 'jetpack' ); ?></option> |
||
| 388 | <option<?php echo ( $global['button_style'] == 'official' ) ? ' selected="selected"' : ''; ?> value="official"><?php _e( 'Official buttons', 'jetpack' ); ?></option> |
||
| 389 | </select> |
||
| 390 | </td> |
||
| 391 | </tr> |
||
| 392 | <tr valign="top"> |
||
| 393 | <th scope="row"><label><?php _e( 'Sharing label', 'jetpack' ); ?></label></th> |
||
| 394 | <td> |
||
| 395 | <input type="text" name="sharing_label" value="<?php echo esc_attr( $global['sharing_label'] ); ?>" /> |
||
| 396 | </td> |
||
| 397 | </tr> |
||
| 398 | <?php |
||
| 399 | /** |
||
| 400 | * Filters the HTML at the beginning of the "Show button on" row. |
||
| 401 | * |
||
| 402 | * @module sharedaddy |
||
| 403 | * |
||
| 404 | * @since 2.1.0 |
||
| 405 | * |
||
| 406 | * @param string $var Opening HTML tag at the beginning of the "Show button on" row. |
||
| 407 | */ |
||
| 408 | echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); |
||
| 409 | ?> |
||
| 410 | <th scope="row"><label><?php _e( 'Show buttons on', 'jetpack' ); ?></label></th> |
||
| 411 | <td> |
||
| 412 | <?php |
||
| 413 | $br = false; |
||
| 414 | View Code Duplication | foreach ( $shows as $show ) : |
|
| 415 | if ( 'index' == $show ) { |
||
| 416 | $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' ); |
||
| 417 | } else { |
||
| 418 | $post_type_object = get_post_type_object( $show ); |
||
| 419 | $label = $post_type_object->labels->name; |
||
| 420 | } |
||
| 421 | ?> |
||
| 422 | <?php |
||
| 423 | if ( $br ) { |
||
| 424 | echo '<br />'; |
||
| 425 | } |
||
| 426 | ?> |
||
| 427 | <label><input type="checkbox"<?php checked( in_array( $show, $global['show'] ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label> |
||
| 428 | <?php |
||
| 429 | $br = true; |
||
| 430 | endforeach; |
||
| 431 | ?> |
||
| 432 | </td> |
||
| 433 | <?php |
||
| 434 | /** |
||
| 435 | * Filters the HTML at the end of the "Show button on" row. |
||
| 436 | * |
||
| 437 | * @module sharedaddy |
||
| 438 | * |
||
| 439 | * @since 2.1.0 |
||
| 440 | * |
||
| 441 | * @param string $var Closing HTML tag at the end of the "Show button on" row. |
||
| 442 | */ |
||
| 443 | echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' ); |
||
| 444 | ?> |
||
| 445 | |||
| 446 | <?php |
||
| 447 | /** |
||
| 448 | * Fires at the end of the sharing global options settings table. |
||
| 449 | * |
||
| 450 | * @module sharedaddy |
||
| 451 | * |
||
| 452 | * @since 1.1.0 |
||
| 453 | */ |
||
| 454 | do_action( 'sharing_global_options' ); |
||
| 455 | ?> |
||
| 456 | </tbody> |
||
| 457 | </table> |
||
| 458 | |||
| 459 | <p class="submit"> |
||
| 460 | <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" /> |
||
| 461 | </p> |
||
| 462 | |||
| 463 | <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" /> |
||
| 464 | </form> |
||
| 465 | |||
| 466 | <div id="new-service" style="display: none"> |
||
| 467 | <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>" id="new-service-form"> |
||
| 468 | <table class="form-table"> |
||
| 469 | <tbody> |
||
| 470 | <tr valign="top"> |
||
| 471 | <th scope="row" width="100"><label><?php _e( 'Service name', 'jetpack' ); ?></label></th> |
||
| 472 | <td> |
||
| 473 | <input type="text" name="sharing_name" id="new_sharing_name" size="40" /> |
||
| 474 | </td> |
||
| 475 | </tr> |
||
| 476 | <tr valign="top"> |
||
| 477 | <th scope="row" width="100"><label><?php _e( 'Sharing URL', 'jetpack' ); ?></label></th> |
||
| 478 | <td> |
||
| 479 | <input type="text" name="sharing_url" id="new_sharing_url" size="40" /> |
||
| 480 | |||
| 481 | <p><?php _e( 'You can add the following variables to your service sharing URL:', 'jetpack' ); ?><br/> |
||
| 482 | <code>%post_id%</code>, <code>%post_title%</code>, <code>%post_slug%</code>, <code>%post_url%</code>, <code>%post_full_url%</code>, <code>%post_excerpt%</code>, <code>%post_tags%</code>, <code>%home_url%</code></p> |
||
| 483 | </td> |
||
| 484 | </tr> |
||
| 485 | <tr valign="top"> |
||
| 486 | <th scope="row" width="100"><label><?php _e( 'Icon URL', 'jetpack' ); ?></label></th> |
||
| 487 | <td> |
||
| 488 | <input type="text" name="sharing_icon" id="new_sharing_icon" size="40" /> |
||
| 489 | <p><?php _e( 'Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack' ); ?></p> |
||
| 490 | </td> |
||
| 491 | </tr> |
||
| 492 | <tr valign="top" width="100"> |
||
| 493 | <th scope="row"></th> |
||
| 494 | <td> |
||
| 495 | <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" /> |
||
| 496 | <img src="<?php echo admin_url( 'images/loading.gif' ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> |
||
| 497 | </td> |
||
| 498 | </tr> |
||
| 499 | |||
| 500 | <?php |
||
| 501 | /** |
||
| 502 | * Fires after the custom sharing service form |
||
| 503 | * |
||
| 504 | * @module sharedaddy |
||
| 505 | * |
||
| 506 | * @since 1.1.0 |
||
| 507 | */ |
||
| 508 | do_action( 'sharing_new_service_form' ); |
||
| 509 | ?> |
||
| 510 | </tbody> |
||
| 511 | </table> |
||
| 512 | |||
| 513 | <?php |
||
| 514 | /** |
||
| 515 | * Fires at the bottom of the admin sharing settings screen. |
||
| 516 | * |
||
| 517 | * @module sharedaddy |
||
| 518 | * |
||
| 519 | * @since 1.6.0 |
||
| 520 | */ |
||
| 521 | do_action( 'post_admin_screen_sharing' ); |
||
| 522 | ?> |
||
| 523 | |||
| 524 | <div class="inerror" style="display: none; margin-top: 15px"> |
||
| 525 | <p><?php _e( 'An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack' ); ?></p> |
||
| 526 | </div> |
||
| 527 | |||
| 528 | <input type="hidden" name="action" value="sharing_new_service" /> |
||
| 529 | <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-new_service' );?>" /> |
||
| 530 | </form> |
||
| 531 | </div> |
||
| 532 | </div> |
||
| 533 | |||
| 534 | <?php endif; ?> |
||
| 535 | |||
| 536 | |||
| 537 | </div> |
||
| 538 | |||
| 539 | <script type="text/javascript"> |
||
| 540 | var sharing_loading_icon = '<?php echo esc_js( admin_url( '/images/loading.gif' ) ); ?>'; |
||
| 541 | <?php if ( isset( $_GET['create_new_service'] ) && 'true' == $_GET['create_new_service'] ) : ?> |
||
| 542 | jQuery(document).ready(function() { |
||
| 543 | // Prefill new service box and then open it |
||
| 544 | jQuery( '#new_sharing_name' ).val( '<?php echo esc_js( $_GET['name'] ); ?>' ); |
||
| 545 | jQuery( '#new_sharing_url' ).val( '<?php echo esc_js( $_GET['url'] ); ?>' ); |
||
| 546 | jQuery( '#new_sharing_icon' ).val( '<?php echo esc_js( $_GET['icon'] ); ?>' ); |
||
| 547 | jQuery( '#add-a-new-service' ).click(); |
||
| 548 | }); |
||
| 549 | <?php endif; ?> |
||
| 550 | </script> |
||
| 551 | <?php |
||
| 552 | } |
||
| 553 | } |
||
| 639 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.