paper-collapsible.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Views
  6. *
  7. * @uses string $paper_id The ID of the paper.
  8. * @uses string $paper_id_prefix The ID prefix of the paper.
  9. * @uses bool $collapsible Whether the collapsible should be rendered.
  10. * @uses array $collapsible_config Configuration for the collapsible.
  11. * @uses string $collapsible_header_class Class for the collapsible header.
  12. * @uses string $title The title.
  13. * @uses string $title_after Additional content to render after the title.
  14. * @uses string $view_file Path to the view file.
  15. * @uses WPSEO_Admin_Help_Panel $help_text The help text.
  16. */
  17. if ( ! defined( 'WPSEO_VERSION' ) ) {
  18. header( 'Status: 403 Forbidden' );
  19. header( 'HTTP/1.1 403 Forbidden' );
  20. exit();
  21. }
  22. ?>
  23. <div
  24. class="<?php echo esc_attr( 'paper tab-block ' . $class ); ?>"<?php echo ( $paper_id ) ? ' id="' . esc_attr( $paper_id_prefix . $paper_id ) . '"' : ''; ?>>
  25. <?php
  26. if ( ! empty( $title ) ) {
  27. if ( ! empty( $collapsible ) ) {
  28. $button_id_attr = '';
  29. if ( ! empty( $paper_id ) ) {
  30. $button_id_attr = sprintf( ' id="%s"', esc_attr( $paper_id_prefix . $paper_id . '-button' ) );
  31. }
  32. printf(
  33. '<h2 class="%1$s"><button%2$s type="button" class="toggleable-container-trigger" aria-expanded="%3$s">%4$s%5$s <span class="toggleable-container-icon dashicons %6$s" aria-hidden="true"></span></button></h2>',
  34. esc_attr( 'collapsible-header ' . $collapsible_header_class ),
  35. // phpcs:ignore WordPress.Security.EscapeOutput -- $button_id_attr is escaped above.
  36. $button_id_attr,
  37. esc_attr( $collapsible_config['expanded'] ),
  38. // phpcs:ignore WordPress.Security.EscapeOutput -- $help_text is and instance of WPSEO_Admin_Help_Panel, which escapes it's own output.
  39. $help_text->get_button_html(),
  40. esc_html( $title ) . wp_kses_post( $title_after ),
  41. wp_kses_post( $collapsible_config['toggle_icon'] )
  42. );
  43. }
  44. else {
  45. echo '<div class="paper-title"><h2 class="help-button-inline">',
  46. esc_html( $title ),
  47. wp_kses_post( $title_after ),
  48. // phpcs:ignore WordPress.Security.EscapeOutput -- $help_text is and instance of WPSEO_Admin_Help_Panel, which escapes it's own output.
  49. $help_text->get_button_html(),
  50. '</h2></div>';
  51. }
  52. }
  53. ?>
  54. <?php
  55. // phpcs:ignore WordPress.Security.EscapeOutput -- $help_text is and instance of WPSEO_Admin_Help_Panel, which escapes it's own output.
  56. echo $help_text->get_panel_html();
  57. $container_id_attr = '';
  58. if ( ! empty( $paper_id ) ) {
  59. $container_id_attr = sprintf( ' id="%s"', esc_attr( $paper_id_prefix . $paper_id . '-container' ) );
  60. }
  61. printf(
  62. '<div%1$s class="%2$s">%3$s</div>',
  63. // phpcs:ignore WordPress.Security.EscapeOutput -- $container_id_attr is escaped above.
  64. $container_id_attr,
  65. esc_attr( 'paper-container ' . $collapsible_config['class'] ),
  66. // phpcs:ignore WordPress.Security.EscapeOutput -- $content is escaped above.
  67. $content
  68. );
  69. ?>
  70. </div>