class.jetpack-settings-page.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. include_once( 'class.jetpack-admin-page.php' );
  3. include_once( JETPACK__PLUGIN_DIR . 'class.jetpack-modules-list-table.php' );
  4. // Builds the settings page and its menu
  5. class Jetpack_Settings_Page extends Jetpack_Admin_Page {
  6. // Show the settings page only when Jetpack is connected or in dev mode
  7. protected $dont_show_if_not_active = true;
  8. function add_page_actions( $hook ) {}
  9. // Adds the Settings sub menu
  10. function get_page_hook() {
  11. return add_submenu_page( null, __( 'Jetpack Settings', 'jetpack' ), __( 'Settings', 'jetpack' ), 'jetpack_manage_modules', 'jetpack_modules', array( $this, 'render' ) );
  12. }
  13. // Renders the module list table where you can use bulk action or row
  14. // actions to activate/deactivate and configure modules
  15. function page_render() {
  16. $list_table = new Jetpack_Modules_List_Table;
  17. $static_html = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static.html' );
  18. // If static.html isn't there, there's nothing else we can do.
  19. if ( false === $static_html ) {
  20. echo '<p>';
  21. esc_html_e( 'Error fetching static.html. Try running: ', 'jetpack' );
  22. echo '<code>yarn distclean && yarn build</code>';
  23. echo '</p>';
  24. return;
  25. }
  26. // We have static.html so let's continue trying to fetch the others
  27. $noscript_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-noscript-notice.html' );
  28. $version_notice = $rest_api_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-version-notice.html' );
  29. $ie_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-ie-notice.html' );
  30. $noscript_notice = str_replace(
  31. '#HEADER_TEXT#',
  32. esc_html__( 'You have JavaScript disabled', 'jetpack' ),
  33. $noscript_notice
  34. );
  35. $noscript_notice = str_replace(
  36. '#TEXT#',
  37. esc_html__( "Turn on JavaScript to unlock Jetpack's full potential!", 'jetpack' ),
  38. $noscript_notice
  39. );
  40. $version_notice = str_replace(
  41. '#HEADER_TEXT#',
  42. esc_html__( 'You are using an outdated version of WordPress', 'jetpack' ),
  43. $version_notice
  44. );
  45. $version_notice = str_replace(
  46. '#TEXT#',
  47. esc_html__( "Update WordPress to unlock Jetpack's full potential!", 'jetpack' ),
  48. $version_notice
  49. );
  50. $rest_api_notice = str_replace(
  51. '#HEADER_TEXT#',
  52. esc_html( __( 'WordPress REST API is disabled', 'jetpack' ) ),
  53. $rest_api_notice
  54. );
  55. $rest_api_notice = str_replace(
  56. '#TEXT#',
  57. esc_html( __( "Enable WordPress REST API to unlock Jetpack's full potential!", 'jetpack' ) ),
  58. $rest_api_notice
  59. );
  60. $ie_notice = str_replace(
  61. '#HEADER_TEXT#',
  62. esc_html__( 'You are using an unsupported browser version.', 'jetpack' ),
  63. $ie_notice
  64. );
  65. $ie_notice = str_replace(
  66. '#TEXT#',
  67. esc_html__( "Update your browser to unlock Jetpack's full potential!", 'jetpack' ),
  68. $ie_notice
  69. );
  70. ob_start();
  71. $this->admin_page_top();
  72. if ( $this->is_wp_version_too_old() ) {
  73. echo $version_notice;
  74. }
  75. if ( ! $this->is_rest_api_enabled() ) {
  76. echo $rest_api_notice;
  77. }
  78. echo $noscript_notice;
  79. echo $ie_notice;
  80. ?>
  81. <div class="page-content configure">
  82. <div class="frame top hide-if-no-js">
  83. <div class="wrap">
  84. <div class="manage-left">
  85. <table class="table table-bordered fixed-top">
  86. <thead>
  87. <tr>
  88. <th class="check-column"><input type="checkbox" class="checkall"></th>
  89. <th colspan="2">
  90. <?php $list_table->unprotected_display_tablenav( 'top' ); ?>
  91. <span class="filter-search">
  92. <button type="button" class="button">Filter</button>
  93. </span>
  94. </th>
  95. </tr>
  96. </thead>
  97. </table>
  98. </div>
  99. </div><!-- /.wrap -->
  100. </div><!-- /.frame -->
  101. <div class="frame bottom">
  102. <div class="wrap">
  103. <div class="manage-right" style="display: none;">
  104. <div class="bumper">
  105. <form class="navbar-form" role="search">
  106. <input type="hidden" name="page" value="jetpack_modules" />
  107. <?php $list_table->search_box( __( 'Search', 'jetpack' ), 'srch-term' ); ?>
  108. <p><?php esc_html_e( 'View:', 'jetpack' ); ?></p>
  109. <div class="button-group filter-active">
  110. <button type="button" class="button <?php if ( empty( $_GET['activated'] ) ) echo 'active'; ?>"><?php esc_html_e( 'All', 'jetpack' ); ?></button>
  111. <button type="button" class="button <?php if ( ! empty( $_GET['activated'] ) && 'true' == $_GET['activated'] ) echo 'active'; ?>" data-filter-by="activated" data-filter-value="true"><?php esc_html_e( 'Active', 'jetpack' ); ?></button>
  112. <button type="button" class="button <?php if ( ! empty( $_GET['activated'] ) && 'false' == $_GET['activated'] ) echo 'active'; ?>" data-filter-by="activated" data-filter-value="false"><?php esc_html_e( 'Inactive', 'jetpack' ); ?></button>
  113. </div>
  114. <p><?php esc_html_e( 'Sort by:', 'jetpack' ); ?></p>
  115. <div class="button-group sort">
  116. <button type="button" class="button <?php if ( empty( $_GET['sort_by'] ) ) echo 'active'; ?>" data-sort-by="name"><?php esc_html_e( 'Alphabetical', 'jetpack' ); ?></button>
  117. <button type="button" class="button <?php if ( ! empty( $_GET['sort_by'] ) && 'introduced' == $_GET['sort_by'] ) echo 'active'; ?>" data-sort-by="introduced" data-sort-order="reverse"><?php esc_html_e( 'Newest', 'jetpack' ); ?></button>
  118. <button type="button" class="button <?php if ( ! empty( $_GET['sort_by'] ) && 'sort' == $_GET['sort_by'] ) echo 'active'; ?>" data-sort-by="sort"><?php esc_html_e( 'Popular', 'jetpack' ); ?></button>
  119. </div>
  120. <p><?php esc_html_e( 'Show:', 'jetpack' ); ?></p>
  121. <?php $list_table->views(); ?>
  122. </form>
  123. </div>
  124. </div>
  125. <div class="manage-left" style="width: 100%;">
  126. <form class="jetpack-modules-list-table-form" onsubmit="return false;">
  127. <table class="<?php echo implode( ' ', $list_table->get_table_classes() ); ?>">
  128. <tbody id="the-list">
  129. <?php $list_table->display_rows_or_placeholder(); ?>
  130. </tbody>
  131. </table>
  132. </form>
  133. </div>
  134. </div><!-- /.wrap -->
  135. </div><!-- /.frame -->
  136. </div><!-- /.content -->
  137. <?php
  138. $this->admin_page_bottom();
  139. $page_content = ob_get_contents();
  140. ob_end_clean();
  141. echo str_replace(
  142. '<div class="jp-loading-placeholder"><span class="dashicons dashicons-wordpress-alt"></span></div>',
  143. $page_content,
  144. $static_html
  145. );
  146. JetpackTracking::record_user_event( 'wpa_page_view', array( 'path' => 'old_settings' ) );
  147. }
  148. /**
  149. * Load styles for static page.
  150. *
  151. * @since 4.3.0
  152. */
  153. function additional_styles() {
  154. $rtl = is_rtl() ? '.rtl' : '';
  155. wp_enqueue_style( 'dops-css', plugins_url( "_inc/build/admin.dops-style$rtl.css", JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION );
  156. wp_enqueue_style( 'components-css', plugins_url( "_inc/build/style.min$rtl.css", JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION );
  157. }
  158. // Javascript logic specific to the list table
  159. function page_admin_scripts() {
  160. wp_enqueue_script(
  161. 'jetpack-admin-js',
  162. Jetpack::get_file_url_for_environment( '_inc/build/jetpack-admin.min.js', '_inc/jetpack-admin.js' ),
  163. array( 'jquery' ),
  164. JETPACK__VERSION
  165. );
  166. }
  167. }