Completed
Push — use-asset-tools-package-everyw... ( c90c8b...56f281 )
by
unknown
25:14 queued 17:28
created

Jetpack_Settings_Page::page_admin_scripts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Automattic\Jetpack\Tracking;
4
use Automattic\Jetpack\Assets;
5
6
include_once( 'class.jetpack-admin-page.php' );
7
include_once( JETPACK__PLUGIN_DIR . 'class.jetpack-modules-list-table.php' );
8
9
// Builds the settings page and its menu
10
class Jetpack_Settings_Page extends Jetpack_Admin_Page {
11
12
	/**
13
	 * @var Assets
14
	 */
15
	protected $assets;
16
17
	public function __construct( Assets $assets ) {
18
		parent::__construct();
19
20
		$this->assets = $assets;
21
	}
22
23
	// Show the settings page only when Jetpack is connected or in dev mode
24
	protected $dont_show_if_not_active = true;
25
26
	function add_page_actions( $hook ) {}
27
28
	// Adds the Settings sub menu
29
	function get_page_hook() {
30
		return add_submenu_page(
31
			null,
32
			__( 'Jetpack Settings', 'jetpack' ),
33
			__( 'Settings', 'jetpack' ),
34
			'jetpack_manage_modules',
35
			'jetpack_modules',
36
			array( $this, 'render' )
37
		);
38
	}
39
40
	// Renders the module list table where you can use bulk action or row
41
	// actions to activate/deactivate and configure modules
42
	function page_render() {
43
		$list_table = new Jetpack_Modules_List_Table( Assets::get_instance() );
44
45
		// We have static.html so let's continue trying to fetch the others
46
		$noscript_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-noscript-notice.html' );
47
		$rest_api_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-version-notice.html' );
48
49
		$noscript_notice = str_replace(
50
			'#HEADER_TEXT#',
51
			esc_html__( 'You have JavaScript disabled', 'jetpack' ),
52
			$noscript_notice
53
		);
54
		$noscript_notice = str_replace(
55
			'#TEXT#',
56
			esc_html__( "Turn on JavaScript to unlock Jetpack's full potential!", 'jetpack' ),
57
			$noscript_notice
58
		);
59
60
		$rest_api_notice = str_replace(
61
			'#HEADER_TEXT#',
62
			esc_html( __( 'WordPress REST API is disabled', 'jetpack' ) ),
63
			$rest_api_notice
64
		);
65
		$rest_api_notice = str_replace(
66
			'#TEXT#',
67
			esc_html( __( "Enable WordPress REST API to unlock Jetpack's full potential!", 'jetpack' ) ),
68
			$rest_api_notice
69
		);
70
71
		if ( ! $this->is_rest_api_enabled() ) {
72
			echo $rest_api_notice;
73
		}
74
		echo $noscript_notice;
75
		?>
76
77
		<div class="page-content configure">
78
			<div class="frame top hide-if-no-js">
79
				<div class="wrap">
80
					<div class="manage-left">
81
						<table class="table table-bordered fixed-top">
82
							<thead>
83
								<tr>
84
									<th class="check-column"><input type="checkbox" class="checkall"></th>
85
									<th colspan="2">
86
										<?php $list_table->unprotected_display_tablenav( 'top' ); ?>
87
										<span class="filter-search">
88
											<button type="button" class="button">Filter</button>
89
										</span>
90
									</th>
91
								</tr>
92
							</thead>
93
						</table>
94
					</div>
95
				</div><!-- /.wrap -->
96
			</div><!-- /.frame -->
97
			<div class="frame bottom">
98
				<div class="wrap">
99
					<div class="manage-right" style="display: none;">
100
						<div class="bumper">
101
							<form class="navbar-form" role="search">
102
								<input type="hidden" name="page" value="jetpack_modules" />
103
								<?php $list_table->search_box( __( 'Search', 'jetpack' ), 'srch-term' ); ?>
104
								<p><?php esc_html_e( 'View:', 'jetpack' ); ?></p>
105
								<div class="button-group filter-active">
106
									<button type="button" class="button <?php if ( empty( $_GET['activated'] ) ) echo 'active'; ?>"><?php esc_html_e( 'All', 'jetpack' ); ?></button>
107
									<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>
108
									<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>
109
								</div>
110
								<p><?php esc_html_e( 'Sort by:', 'jetpack' ); ?></p>
111
								<div class="button-group sort">
112
									<button type="button" class="button <?php if ( empty( $_GET['sort_by'] ) ) echo 'active'; ?>" data-sort-by="name"><?php esc_html_e( 'Alphabetical', 'jetpack' ); ?></button>
113
									<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>
114
									<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>
115
								</div>
116
								<p><?php esc_html_e( 'Show:', 'jetpack' ); ?></p>
117
								<?php $list_table->views(); ?>
118
							</form>
119
						</div>
120
					</div>
121
					<div class="manage-left" style="width: 100%;">
122
						<form class="jetpack-modules-list-table-form" onsubmit="return false;">
123
						<table class="<?php echo implode( ' ', $list_table->get_table_classes() ); ?>">
124
							<tbody id="the-list">
125
								<?php $list_table->display_rows_or_placeholder(); ?>
126
							</tbody>
127
						</table>
128
						</form>
129
					</div>
130
				</div><!-- /.wrap -->
131
			</div><!-- /.frame -->
132
		</div><!-- /.content -->
133
		<?php
134
135
		$tracking = new Tracking();
136
		$tracking->record_user_event( 'wpa_page_view', array( 'path' => 'old_settings' ) );
137
	}
138
139
	/**
140
	 * Load styles for static page.
141
	 *
142
	 * @since 4.3.0
143
	 */
144
	function additional_styles() {
145
		Jetpack_Admin_Page::load_wrapper_styles();
146
	}
147
148
	// Javascript logic specific to the list table
149
	function page_admin_scripts() {
150
		wp_enqueue_script(
151
			'jetpack-admin-js',
152
			$this->assets->get_file_url_for_environment( '_inc/build/jetpack-admin.min.js', '_inc/jetpack-admin.js' ),
153
			array( 'jquery' ),
154
			JETPACK__VERSION
155
		);
156
	}
157
}
158