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