|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class Jetpack_Beta_Admin |
|
5
|
|
|
*/ |
|
6
|
|
|
class Jetpack_Beta_Admin { |
|
7
|
|
|
|
|
8
|
|
|
static function init() { |
|
9
|
|
|
add_action( 'admin_menu', array( __CLASS__, 'add_actions' ), 998 ); |
|
10
|
|
|
add_action( 'network_admin_menu', array( __CLASS__, 'add_actions' ), 998 ); |
|
11
|
|
|
add_action( 'admin_notices', array( __CLASS__, 'render_banner' ) ); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
static function add_actions() { |
|
15
|
|
|
$hook = self::get_page_hook(); |
|
16
|
|
|
// Attach hooks common to all Jetpack admin pages based on the created |
|
17
|
|
|
add_action( "load-$hook", array( __CLASS__, 'admin_page_load' ) ); |
|
18
|
|
|
add_action( "admin_print_styles-$hook", array( __CLASS__, 'admin_styles' ) ); |
|
19
|
|
|
add_action( "admin_print_scripts-$hook", array( __CLASS__, 'admin_scripts' ) ); |
|
20
|
|
|
add_filter( 'plugin_action_links_' . JPBETA__PLUGIN_FOLDER . '/jetpack-beta.php', array( __CLASS__, 'admin_plugin_settings_link' ) ); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
static function get_page_hook() { |
|
24
|
|
|
if ( Jetpack_Beta::is_network_active() && ! is_network_admin() ) { |
|
25
|
|
|
return; |
|
26
|
|
|
} |
|
27
|
|
|
if ( class_exists( 'Jetpack' ) ) { |
|
28
|
|
|
return add_submenu_page( |
|
29
|
|
|
'jetpack', |
|
30
|
|
|
'Jetpack Beta', |
|
31
|
|
|
'Jetpack Beta', |
|
32
|
|
|
'update_plugins', |
|
33
|
|
|
'jetpack-beta', |
|
34
|
|
|
array( __CLASS__, 'render' ) |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return add_menu_page( |
|
39
|
|
|
'Jetpack Beta', |
|
40
|
|
|
'Jetpack Beta', |
|
41
|
|
|
'update_plugins', |
|
42
|
|
|
'jetpack-beta', |
|
43
|
|
|
array( __CLASS__, 'render' ) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
static function render() { |
|
48
|
|
|
// Always grab the latest version |
|
49
|
|
|
Jetpack_Beta::get_beta_manifest( true ); |
|
50
|
|
|
require_once JPBETA__PLUGIN_DIR . 'admin/main.php'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
static function settings_link() { |
|
54
|
|
|
return admin_url( 'admin.php?page=jetpack-beta' ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
static function admin_plugin_settings_link( $links ) { |
|
58
|
|
|
$settings_link = '<a href="'. esc_url( self::settings_link() ) . '">' . __( 'Settings', 'jetpack-beta' ) . '</a>'; |
|
59
|
|
|
array_unshift( $links, $settings_link ); |
|
60
|
|
|
return $links; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
static function admin_page_load() { |
|
64
|
|
|
if ( ! isset( $_GET['_nonce'] ) ) { |
|
65
|
|
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
// Install and activate Jetpack Version |
|
68
|
|
View Code Duplication |
if ( wp_verify_nonce( $_GET['_nonce'], 'activate_branch' ) && isset( $_GET['activate-branch'] ) && isset( $_GET['section'] ) ) { |
|
69
|
|
|
$branch = esc_html( $_GET['activate-branch'] ); |
|
70
|
|
|
$section = esc_html( $_GET['section'] ); |
|
71
|
|
|
|
|
72
|
|
|
Jetpack_Beta::install_and_activate( $branch, $section ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// Update to the latest version |
|
76
|
|
View Code Duplication |
if ( wp_verify_nonce( $_GET['_nonce'], 'update_branch' ) && isset( $_GET['update-branch'] ) && isset( $_GET['section'] ) ) { |
|
77
|
|
|
$branch = esc_html( $_GET['update-branch'] ); |
|
78
|
|
|
$section = esc_html( $_GET['section'] ); |
|
79
|
|
|
|
|
80
|
|
|
Jetpack_Beta::update_plugin( $branch, $section ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
// Toggle autoupdates |
|
84
|
|
|
if ( self::is_toggle_action( 'autoupdates' ) ) { |
|
85
|
|
|
$autoupdate = (bool) Jetpack_Beta::is_set_to_autoupdate(); |
|
86
|
|
|
update_option( 'jp_beta_autoupdate', (int) ! $autoupdate ); |
|
87
|
|
|
|
|
88
|
|
|
if ( Jetpack_Beta::is_set_to_autoupdate() ) { |
|
89
|
|
|
Jetpack_Beta::maybe_schedule_autoupdate(); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
// Toggle email notifications |
|
94
|
|
|
if ( self::is_toggle_action( 'email_notifications' ) ) { |
|
95
|
|
|
$enable_email_notifications = (bool) Jetpack_Beta::is_set_to_email_notifications(); |
|
96
|
|
|
update_option( 'jp_beta_email_notifications', (int) ! $enable_email_notifications ); |
|
97
|
|
|
} |
|
98
|
|
|
wp_safe_redirect( Jetpack_Beta::admin_url() ); |
|
99
|
|
|
|
|
100
|
|
|
exit(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
static function is_toggle_action( $option ) { |
|
104
|
|
|
return ( |
|
105
|
|
|
isset( $_GET['_nonce'] ) && |
|
106
|
|
|
wp_verify_nonce( $_GET['_nonce'], 'enable_' . $option ) && |
|
107
|
|
|
isset( $_GET['_action'] ) && |
|
108
|
|
|
'toggle_enable_' . $option === $_GET['_action'] |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
static function render_banner() { |
|
113
|
|
|
global $current_screen; |
|
114
|
|
|
|
|
115
|
|
|
if ( 'plugins' !== $current_screen->base ) { |
|
116
|
|
|
return; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
if ( Jetpack_Beta::get_option() ) { |
|
120
|
|
|
return; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
self::start_notice(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
static function admin_styles() { |
|
127
|
|
|
wp_enqueue_style( 'jetpack-beta-admin', plugins_url( "admin/admin.css", JPBETA__PLUGIN_FILE ), array(), JPBETA_VERSION ); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
static function admin_scripts() { |
|
131
|
|
|
wp_enqueue_script( 'jetpack-admin-js', plugins_url( 'admin/admin.js', JPBETA__PLUGIN_FILE ), array( ), JPBETA_VERSION, true ); |
|
132
|
|
|
wp_localize_script( 'jetpack-admin-js', 'JetpackBeta', |
|
133
|
|
|
array( |
|
134
|
|
|
'activate' => __( 'Activate', 'jetpack-beta' ), |
|
135
|
|
|
'activating' => __( 'Activating...', 'jetpack-beta' ), |
|
136
|
|
|
'updating' => __( 'Updating...', 'jetpack-beta' ), |
|
137
|
|
|
'leaving' => __( 'Don\'t go Plugin is still installing!', 'jetpack-beta' ), |
|
138
|
|
|
) |
|
139
|
|
|
); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
static function to_test_content() { |
|
143
|
|
|
list( $branch, $section ) = Jetpack_Beta::get_branch_and_section(); |
|
144
|
|
|
switch ( $section ) { |
|
145
|
|
|
case 'pr': |
|
146
|
|
|
return self::to_test_pr_content( $branch ); |
|
147
|
|
|
break; |
|
|
|
|
|
|
148
|
|
|
case 'master': |
|
149
|
|
|
case 'rc': |
|
150
|
|
|
return self::to_test_file_content(); |
|
151
|
|
|
break; |
|
|
|
|
|
|
152
|
|
|
} |
|
153
|
|
|
return null; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
static function to_test_file_content() { |
|
157
|
|
|
$test_file = WP_PLUGIN_DIR . '/' . Jetpack_Beta::get_plugin_slug() . '/to-test.md'; |
|
158
|
|
|
if ( ! file_exists( $test_file ) ) { |
|
159
|
|
|
return; |
|
160
|
|
|
} |
|
161
|
|
|
$content = file_get_contents( $test_file ); |
|
162
|
|
|
return self::render_markdown( $content ); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
static function to_test_pr_content( $branch_key ) { |
|
166
|
|
|
$manifest = Jetpack_Beta::get_beta_manifest(); |
|
167
|
|
|
$pr = isset( $manifest->pr->{$branch_key}->pr ) ? $manifest->pr->{$branch_key}->pr : null; |
|
168
|
|
|
|
|
169
|
|
|
if ( ! $pr ) { |
|
170
|
|
|
return null; |
|
171
|
|
|
} |
|
172
|
|
|
$github_info = Jetpack_Beta::get_remote_data( JETPACK_GITHUB_API_URL . 'pulls/' . $pr, 'github_' . $pr ); |
|
173
|
|
|
|
|
174
|
|
|
return self::render_markdown( $github_info->body ); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
static function render_markdown( $content ) { |
|
178
|
|
|
|
|
179
|
|
|
add_filter( 'jetpack_beta_test_content', 'wptexturize' ); |
|
180
|
|
|
add_filter( 'jetpack_beta_test_content', 'convert_smilies' ); |
|
181
|
|
|
add_filter( 'jetpack_beta_test_content', 'convert_chars' ); |
|
182
|
|
|
add_filter( 'jetpack_beta_test_content', 'wpautop' ); |
|
183
|
|
|
add_filter( 'jetpack_beta_test_content', 'shortcode_unautop' ); |
|
184
|
|
|
add_filter( 'jetpack_beta_test_content', 'prepend_attachment' ); |
|
185
|
|
|
|
|
186
|
|
|
if ( ! function_exists( 'jetpack_require_lib' ) ) { |
|
187
|
|
|
return apply_filters( 'jetpack_beta_test_content', $content ); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
jetpack_require_lib( 'markdown' ); |
|
191
|
|
|
if ( ! class_exists( 'WPCom_Markdown' ) ) { |
|
192
|
|
|
require_once( WP_PLUGIN_DIR . '/' . Jetpack_Beta::get_plugin_slug() . '/modules/markdown/easy-markdown.php' ); |
|
193
|
|
|
} |
|
194
|
|
|
$rendered_html = WPCom_Markdown::get_instance()->transform( $content, array( |
|
195
|
|
|
'id' => false, |
|
196
|
|
|
'unslash' => false |
|
197
|
|
|
) ); |
|
198
|
|
|
|
|
199
|
|
|
// Lets convert #hash numbers into links to issues. |
|
200
|
|
|
$rendered_html = preg_replace('/\#([0-9]+)/', '<a href="https://github.com/Automattic/jetpack/issues/$1">#$1</a>', $rendered_html ); |
|
201
|
|
|
|
|
202
|
|
|
$rendered_html = apply_filters( 'jetpack_beta_test_content', $rendered_html ); |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
return $rendered_html; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
static function start_notice() { |
|
209
|
|
|
global $current_screen; |
|
210
|
|
|
|
|
211
|
|
|
$is_notice = ( 'plugins' === $current_screen->base ? true : false ); |
|
212
|
|
|
?> |
|
213
|
|
|
<style type="text/css"> |
|
214
|
|
|
#jetpack-beta-tester__start { |
|
215
|
|
|
background: #FFF; |
|
216
|
|
|
padding: 20px; |
|
217
|
|
|
margin-top:20px; |
|
218
|
|
|
box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #e9eff3; |
|
219
|
|
|
position: relative; |
|
220
|
|
|
} |
|
221
|
|
|
#jetpack-beta-tester__start.updated { |
|
222
|
|
|
border-left: 3px solid #8CC258; |
|
223
|
|
|
} |
|
224
|
|
|
#jetpack-beta-tester__start h1 { |
|
225
|
|
|
font-weight: 400; |
|
226
|
|
|
margin: 0; |
|
227
|
|
|
font-size: 20px; |
|
228
|
|
|
} |
|
229
|
|
|
#jetpack-beta-tester__start p { |
|
230
|
|
|
margin-bottom:1em; |
|
231
|
|
|
} |
|
232
|
|
|
</style> |
|
233
|
|
|
<div id="jetpack-beta-tester__start" class="dops-card <?php echo ( $is_notice ? 'updated' : '' ); ?> "> |
|
234
|
|
|
<h1><?php _e( 'Welcome to Jetpack Beta Tester', 'jetpack-beta' ); ?></h1> |
|
235
|
|
|
<p><?php _e( 'Thank you for helping to test Jetpack! We appreciate your time and effort.', 'jetpack-beta' ); ?></p> |
|
236
|
|
|
<p><?php _e( 'When you select a Jetpack branch to test, Jetpack Beta Tester will install and activate it on your behalf and keep it up to date. |
|
237
|
|
|
When you are finished testing, you can switch back to the current version of Jetpack by selecting <em>Latest Stable</em>.', 'jetpack-beta' ); ?></p> |
|
238
|
|
|
<p><?php printf( |
|
239
|
|
|
__( 'Not sure where to start? If you select <em>Bleeding Edge</em>, you\'ll get <a href="%1$s">all the cool new features</a> we\'re planning to ship in our next release.', 'jetpack-beta' ), |
|
240
|
|
|
esc_url( 'https://github.com/Automattic/jetpack/blob/master/to-test.md' ) |
|
241
|
|
|
); ?></p> |
|
242
|
|
|
<?php if ( $is_notice ) { ?> |
|
243
|
|
|
<a href="<?php echo esc_url( Jetpack_Beta::admin_url() ); ?>"><?php _e( 'Let\'s get testing!', 'jetpack-beta' ); ?></a> |
|
244
|
|
|
<?php } ?> |
|
245
|
|
|
|
|
246
|
|
|
</div> |
|
247
|
|
|
<?php |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
static function show_branch( $header, $branch_key, $branch = null, $section = null, $is_last = false ) { |
|
251
|
|
|
if ( ! is_object( $branch ) ) { |
|
252
|
|
|
$manifest = Jetpack_Beta::get_beta_manifest(); |
|
253
|
|
|
if ( empty( $manifest->{$section} ) ) { |
|
254
|
|
|
return; |
|
255
|
|
|
} |
|
256
|
|
|
$branch = $manifest->{$section}; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
$is_compact = $is_last ? '' : 'is-compact'; |
|
260
|
|
|
$more_info = ''; |
|
261
|
|
|
$pr = ''; |
|
262
|
|
|
if ( isset( $branch->pr ) && is_int( $branch->pr ) ) { |
|
263
|
|
|
$pr = sprintf( 'data-pr="%s"', esc_attr( $branch->pr ) ); |
|
264
|
|
|
$more_info = sprintf( __( '<a target="_blank" rel="external noopener noreferrer" href="%s">more info #%s</a> - ', 'jetpack-beta' ), Jetpack_Beta::get_url( $branch_key, $section ), $branch->pr ); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
$update_time = ( isset( $branch->update_date ) |
|
268
|
|
|
? sprintf( __( 'last updated %s ago', 'jetpack-beta' ), human_time_diff( strtotime( $branch->update_date ) ) ) |
|
269
|
|
|
: '' |
|
270
|
|
|
); |
|
271
|
|
|
|
|
272
|
|
|
$branch_class = 'branch-card'; |
|
273
|
|
|
list( $current_branch, $current_section ) = Jetpack_Beta::get_branch_and_section(); |
|
274
|
|
View Code Duplication |
if ( $current_branch === $branch_key && $current_section === $section ) { |
|
275
|
|
|
$action = __( 'Active', 'jetpack-beta' ); |
|
276
|
|
|
$branch_class = 'branch-card-active'; |
|
277
|
|
|
} else { |
|
278
|
|
|
$action = self::activate_button( $branch_key, $section ); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
$header = str_replace( '-', ' ', $header ); |
|
282
|
|
|
$header = str_replace( '_', ' / ', $header ); |
|
283
|
|
|
?> |
|
284
|
|
|
<div <?php echo $pr; ?> " class="dops-foldable-card <?php echo esc_attr( $branch_class ); ?> has-expanded-summary dops-card <?php echo $is_compact; ?>"> |
|
285
|
|
|
<div class="dops-foldable-card__header has-border" > |
|
286
|
|
|
<span class="dops-foldable-card__main"> |
|
287
|
|
|
<div class="dops-foldable-card__header-text"> |
|
288
|
|
|
<div class="dops-foldable-card__header-text branch-card-header"><?php echo esc_html( $header ); ?></div> |
|
289
|
|
|
<div class="dops-foldable-card__subheader"> |
|
290
|
|
|
<?php |
|
291
|
|
|
echo $more_info; |
|
292
|
|
|
echo $update_time; |
|
293
|
|
|
?> |
|
294
|
|
|
</div> |
|
295
|
|
|
</div> |
|
296
|
|
|
</span> |
|
297
|
|
|
<span class="dops-foldable-card__secondary"> |
|
298
|
|
|
<span class="dops-foldable-card__summary"> |
|
299
|
|
|
<?php echo $action; ?> |
|
300
|
|
|
</span> |
|
301
|
|
|
</span> |
|
302
|
|
|
</div> |
|
303
|
|
|
</div> |
|
304
|
|
|
<?php |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
static function show_tag( $header, $tag, $url = null, $section = null, $is_last = false ) { |
|
308
|
|
|
$is_compact = $is_last ? '' : 'is-compact'; |
|
309
|
|
|
if ( isset( $url ) ) { |
|
310
|
|
|
$data_tag = sprintf( 'data-tag="%s"', $tag ); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
$className = 'tag-card'; |
|
314
|
|
|
list( $current_branch, $current_section ) = Jetpack_Beta::get_branch_and_section(); |
|
315
|
|
View Code Duplication |
if ( $current_branch === $tag && $current_section === $section ) { |
|
316
|
|
|
$action = __( 'Active', 'jetpack-beta' ); |
|
317
|
|
|
$className = 'tag-card-active'; |
|
318
|
|
|
} else { |
|
319
|
|
|
$action = self::activate_button( $tag, $section ); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
$header = str_replace( '-', ' ', $header ); |
|
323
|
|
|
$header = str_replace( '_', ' / ', $header ); |
|
324
|
|
|
?> |
|
325
|
|
|
<div <?php echo $data_tag; ?> " class="dops-foldable-card <?php echo esc_attr( $className ); ?> has-expanded-summary dops-card <?php echo $is_compact; ?>"> |
|
|
|
|
|
|
326
|
|
|
<div class="dops-foldable-card__header has-border"> |
|
327
|
|
|
<span class="dops-foldable-card__main"> |
|
328
|
|
|
<div class="dops-foldable-card__header-text"> |
|
329
|
|
|
<div class="dops-foldable-card__header-text tag-card-header">Jetpack <?php echo esc_html( $header ); ?></div> |
|
330
|
|
|
<div class="dops-foldable-card__subheader"> |
|
331
|
|
|
<?php |
|
332
|
|
|
sprintf( |
|
333
|
|
|
__( 'Public release (%1$s) <a href="https://plugins.trac.wordpress.org/browser/jetpack/tags/%2$s" target="_blank" rel="">available on WordPress.org</a>', 'jetpack-beta' ), |
|
334
|
|
|
esc_html( $tag ), |
|
335
|
|
|
esc_attr( $tag ) |
|
336
|
|
|
); |
|
337
|
|
|
?> |
|
338
|
|
|
</div> |
|
339
|
|
|
</div> |
|
340
|
|
|
</span> |
|
341
|
|
|
<span class="dops-foldable-card__secondary"> |
|
342
|
|
|
<span class="dops-foldable-card__summary"> |
|
343
|
|
|
<?php echo $action; ?> |
|
344
|
|
|
</span> |
|
345
|
|
|
</span> |
|
346
|
|
|
</div> |
|
347
|
|
|
</div> |
|
348
|
|
|
<?php |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
static function activate_button( $branch, $section ) { |
|
352
|
|
|
if ( is_object( $section ) && $branch === 'master' ) { |
|
353
|
|
|
$section = 'master'; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
if ( is_object( $section ) && $branch === 'rc' ) { |
|
357
|
|
|
$section = 'rc'; |
|
358
|
|
|
} |
|
359
|
|
|
$query = array( |
|
360
|
|
|
'page' => 'jetpack-beta', |
|
361
|
|
|
'activate-branch' => $branch, |
|
362
|
|
|
'section' => $section, |
|
363
|
|
|
'_nonce' => wp_create_nonce( 'activate_branch' ), |
|
364
|
|
|
); |
|
365
|
|
|
$url = Jetpack_Beta::admin_url( '?' . build_query( $query ) ); |
|
366
|
|
|
|
|
367
|
|
|
return sprintf( |
|
368
|
|
|
'<a href="%1$s" class="is-primary jp-form-button activate-branch dops-button is-compact jptracks" data-jptracks-name="%2$s" data-jptracks-prop="%3$s">%4$s</a>', |
|
369
|
|
|
esc_url( $url ), |
|
370
|
|
|
'jetpack_beta_activate_branch', |
|
371
|
|
|
esc_attr( $branch ), |
|
372
|
|
|
esc_html__( 'Activate', 'jetpack-beta' ) |
|
373
|
|
|
); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
static function header( $title ) { |
|
377
|
|
|
echo '<header><h2 class="jp-jetpack-connect__container-subtitle">' . esc_html( $title ) . '</h2></header>'; |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
View Code Duplication |
static function show_branches( $section, $title = null ) { |
|
381
|
|
|
if ( $title ) { |
|
382
|
|
|
$title .= ': '; |
|
383
|
|
|
} |
|
384
|
|
|
echo '<div id="section-' . esc_attr( $section ) . '">'; |
|
385
|
|
|
|
|
386
|
|
|
$manifest = Jetpack_Beta::get_beta_manifest(); |
|
387
|
|
|
$count = 0; |
|
388
|
|
|
if ( empty( $manifest->{$section} ) ) { |
|
389
|
|
|
return; |
|
390
|
|
|
} |
|
391
|
|
|
$branches = (array) $manifest->{$section}; |
|
392
|
|
|
$count_all = count( $branches ); |
|
393
|
|
|
|
|
394
|
|
|
foreach ( $branches as $branch_name => $branch ) { |
|
395
|
|
|
$count ++; |
|
396
|
|
|
$is_last = $count_all === $count ? true : false; |
|
397
|
|
|
self::show_branch( $title . $branch_name, $branch_name, $branch, $section, $is_last ); |
|
398
|
|
|
} |
|
399
|
|
|
echo '</div>'; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
View Code Duplication |
static function show_tags( $section, $title = null ) { |
|
403
|
|
|
if ( $title ) { |
|
404
|
|
|
$title .= ': '; |
|
405
|
|
|
} |
|
406
|
|
|
echo '<div id="section-' . esc_attr( $section ) . '">'; |
|
407
|
|
|
|
|
408
|
|
|
$manifest = Jetpack_Beta::get_org_data(); |
|
409
|
|
|
$count = 0; |
|
410
|
|
|
if ( empty( $manifest->versions ) ) { |
|
411
|
|
|
return; |
|
412
|
|
|
} |
|
413
|
|
|
$tags = array_reverse( (array) $manifest->versions ); |
|
414
|
|
|
$count_all = count( $tags ); |
|
415
|
|
|
|
|
416
|
|
|
foreach ( $tags as $tag => $url ) { |
|
417
|
|
|
$count ++; |
|
418
|
|
|
$is_last = $count_all === $count ? true : false; |
|
419
|
|
|
self::show_tag( $title . $tag, $tag, $url, $section, $is_last ); |
|
420
|
|
|
} |
|
421
|
|
|
echo '</div>'; |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
static function show_stable_branch() { |
|
425
|
|
|
$org_data = Jetpack_Beta::get_org_data(); |
|
426
|
|
|
|
|
427
|
|
|
self::show_branch( |
|
428
|
|
|
__( 'Latest Stable', 'jetpack-beta' ), |
|
429
|
|
|
'stable', |
|
430
|
|
|
(object) array( |
|
431
|
|
|
'branch' => 'stable', |
|
432
|
|
|
'update_date' => $org_data->last_updated |
|
433
|
|
|
), |
|
434
|
|
|
'stable' |
|
435
|
|
|
); |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
View Code Duplication |
static function show_search_prs() { |
|
439
|
|
|
$manifest = Jetpack_Beta::get_beta_manifest(); |
|
440
|
|
|
if ( empty( $manifest->pr ) ) { |
|
441
|
|
|
return; |
|
442
|
|
|
} |
|
443
|
|
|
?> |
|
444
|
|
|
<div class="dops-navigation"> |
|
445
|
|
|
<div class="dops-section-nav has-pinned-items"> |
|
446
|
|
|
<div class="dops-section-nav__panel"> |
|
447
|
|
|
<div class="is-pinned is-open dops-search" role="search"> |
|
448
|
|
|
<div aria-controls="search-component" aria-label="<?php esc_attr_e( 'Open Search', 'jetpack-beta' ); ?>" tabindex="-1"> |
|
449
|
|
|
<svg class="gridicon gridicons-search dops-search-open__icon" height="24" |
|
450
|
|
|
viewbox="0 0 24 24" width="24"> |
|
451
|
|
|
<g> |
|
452
|
|
|
<path d="M21 19l-5.154-5.154C16.574 12.742 17 11.42 17 10c0-3.866-3.134-7-7-7s-7 3.134-7 7 3.134 7 7 7c1.42 0 2.742-.426 3.846-1.154L19 21l2-2zM5 10c0-2.757 2.243-5 5-5s5 2.243 5 5-2.243 5-5 5-5-2.243-5-5z"></path> |
|
453
|
|
|
</g> |
|
454
|
|
|
</svg> |
|
455
|
|
|
</div> |
|
456
|
|
|
<input aria-hidden="false" class="dops-search__input" id="search-component-prs" |
|
457
|
|
|
placeholder="<?php esc_attr_e( 'Search for a Jetpack Feature Branch', 'jetpack-beta' ); ?>" role="search" type="search" value=""> |
|
458
|
|
|
<span aria-controls="search-component" id="search-component-prs-close" aria-label="<?php esc_attr_e( 'Close Search','jetpack-beta'); ?>" |
|
459
|
|
|
tabindex="0"> |
|
460
|
|
|
<svg class="gridicon gridicons-cross dops-search-close__icon" height="24" |
|
461
|
|
|
viewbox="0 0 24 24" width="24"> |
|
462
|
|
|
<g> |
|
463
|
|
|
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"></path> |
|
464
|
|
|
</g> |
|
465
|
|
|
</svg> |
|
466
|
|
|
</span> |
|
467
|
|
|
</div> |
|
468
|
|
|
</div> |
|
469
|
|
|
</div> |
|
470
|
|
|
</div> |
|
471
|
|
|
<?php |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
View Code Duplication |
static function show_search_org_tags() { |
|
475
|
|
|
$org_data = Jetpack_Beta::get_org_data(); |
|
476
|
|
|
if ( empty( $org_data->versions ) ) { |
|
477
|
|
|
return; |
|
478
|
|
|
} |
|
479
|
|
|
?> |
|
480
|
|
|
<div class="dops-navigation"> |
|
481
|
|
|
<div class="dops-section-nav has-pinned-items"> |
|
482
|
|
|
<div class="dops-section-nav__panel"> |
|
483
|
|
|
<div class="is-pinned is-open dops-search" role="search"> |
|
484
|
|
|
<div aria-controls="search-component" aria-label="<?php esc_attr_e( 'Open Search', 'jetpack-beta' ); ?>" tabindex="-1"> |
|
485
|
|
|
<svg class="gridicon gridicons-search dops-search-open__icon" height="24" |
|
486
|
|
|
viewbox="0 0 24 24" width="24"> |
|
487
|
|
|
<g> |
|
488
|
|
|
<path d="M21 19l-5.154-5.154C16.574 12.742 17 11.42 17 10c0-3.866-3.134-7-7-7s-7 3.134-7 7 3.134 7 7 7c1.42 0 2.742-.426 3.846-1.154L19 21l2-2zM5 10c0-2.757 2.243-5 5-5s5 2.243 5 5-2.243 5-5 5-5-2.243-5-5z"></path> |
|
489
|
|
|
</g> |
|
490
|
|
|
</svg> |
|
491
|
|
|
</div> |
|
492
|
|
|
<input aria-hidden="false" class="dops-search__input" id="search-component-tags" |
|
493
|
|
|
placeholder="<?php esc_attr_e( 'Search for a Jetpack tag', 'jetpack-beta' ); ?>" role="search" type="search" value=""> |
|
494
|
|
|
<span aria-controls="search-component" id="search-component-tags-close" aria-label="<?php esc_attr_e( 'Close Search','jetpack-beta'); ?>" |
|
495
|
|
|
tabindex="0"> |
|
496
|
|
|
<svg class="gridicon gridicons-cross dops-search-close__icon" height="24" |
|
497
|
|
|
viewbox="0 0 24 24" width="24"> |
|
498
|
|
|
<g> |
|
499
|
|
|
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"></path> |
|
500
|
|
|
</g> |
|
501
|
|
|
</svg> |
|
502
|
|
|
</span> |
|
503
|
|
|
</div> |
|
504
|
|
|
</div> |
|
505
|
|
|
</div> |
|
506
|
|
|
</div> |
|
507
|
|
|
<?php |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
static function show_toggle_autoupdates() { |
|
511
|
|
|
$autoupdate = (bool) Jetpack_Beta::is_set_to_autoupdate(); |
|
512
|
|
|
self::show_toggle( __( 'Autoupdates', 'jetpack-beta' ), 'autoupdates', $autoupdate ); |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
static function show_toggle_emails() { |
|
516
|
|
|
if ( ! Jetpack_Beta::is_set_to_autoupdate() || defined( 'JETPACK_BETA_SKIP_EMAIL' ) ) { |
|
517
|
|
|
return; |
|
518
|
|
|
} |
|
519
|
|
|
$email_notification = (bool) Jetpack_Beta::is_set_to_email_notifications(); |
|
520
|
|
|
self::show_toggle( __( 'Email Notifications', 'jetpack-beta' ), 'email_notifications', $email_notification ); |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
static function show_toggle( $name, $option, $value ) { |
|
524
|
|
|
$query = array( |
|
525
|
|
|
'page' => 'jetpack-beta', |
|
526
|
|
|
'_action' => 'toggle_enable_' . $option, |
|
527
|
|
|
'_nonce' => wp_create_nonce( 'enable_' . $option ), |
|
528
|
|
|
); |
|
529
|
|
|
|
|
530
|
|
|
?> |
|
531
|
|
|
<a |
|
532
|
|
|
href="<?php echo esc_url( Jetpack_Beta::admin_url( '?' . build_query( $query ) ) ); ?>" |
|
533
|
|
|
class="form-toggle__label <?php echo ( $value ? 'is-active' : '' ); ?>" |
|
534
|
|
|
data-jptracks-name="jetpack_beta_toggle_<?php echo esc_attr( $option ); ?>" |
|
535
|
|
|
data-jptracks-prop="<?php echo absint( ! $value ); ?>" |
|
536
|
|
|
> |
|
537
|
|
|
<span class="form-toggle-explanation" ><?php echo esc_html( $name ); ?></span> |
|
538
|
|
|
<span class="form-toggle__switch" tabindex="0" ></span> |
|
539
|
|
|
<span class="form-toggle__label-content" ></span> |
|
540
|
|
|
</a> |
|
541
|
|
|
<?php |
|
542
|
|
|
} |
|
543
|
|
|
|
|
544
|
|
|
static function show_needed_updates() { |
|
545
|
|
|
// Jetpack Stable not up to date? |
|
546
|
|
|
$should_update_stable_version = Jetpack_Beta::should_update_stable_version(); |
|
547
|
|
|
$should_update_dev_version = Jetpack_Beta::should_update_dev_version(); |
|
548
|
|
|
$should_update_dev_to_master = Jetpack_Beta::should_update_dev_to_master(); |
|
549
|
|
|
|
|
550
|
|
|
if ( ! $should_update_stable_version |
|
551
|
|
|
&& ! $should_update_dev_version |
|
552
|
|
|
&& ! $should_update_dev_to_master ) { |
|
553
|
|
|
return; |
|
554
|
|
|
} |
|
555
|
|
|
?> |
|
556
|
|
|
<div class="jetpack-beta__wrap jetpack-beta__update-needed"> |
|
557
|
|
|
<h2><?php esc_html_e( 'Some updates are required', 'jetpack-beta' ); ?></h2> |
|
558
|
|
|
<?php |
|
559
|
|
|
|
|
560
|
|
View Code Duplication |
if ( $should_update_stable_version ) { |
|
561
|
|
|
self::update_card( |
|
562
|
|
|
__( 'Latest Stable', 'jetpack-beta' ), |
|
563
|
|
|
__( 'Needs an update', 'jetpack-beta' ), |
|
564
|
|
|
self::update_action_url( 'stable', 'stable' ) |
|
565
|
|
|
); |
|
566
|
|
|
} |
|
567
|
|
|
// Jetpack Dev Folder not up to date? |
|
568
|
|
|
if ( $should_update_dev_version ) { |
|
569
|
|
|
list( $dev_branch, $dev_section ) = Jetpack_Beta::get_branch_and_section_dev(); |
|
570
|
|
|
self::update_card( |
|
571
|
|
|
Jetpack_Beta::get_jetpack_plugin_pretty_version( true ), |
|
572
|
|
|
__( 'Is not running the latest version', 'jetpack-beta' ), |
|
573
|
|
|
self::update_action_url( $dev_branch, $dev_section ) |
|
574
|
|
|
); |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
View Code Duplication |
if ( $should_update_dev_to_master ) { |
|
578
|
|
|
self::update_card( |
|
579
|
|
|
__( 'Feature Branch was merged', 'jetpack-beta' ), |
|
580
|
|
|
__( 'Go back to Jetpack\'s Bleeding Edge version.', 'jetpack-beta' ), |
|
581
|
|
|
self::update_action_url( 'master', 'master' ) |
|
582
|
|
|
); |
|
583
|
|
|
} ?> |
|
584
|
|
|
</div> |
|
585
|
|
|
<?php |
|
586
|
|
|
} |
|
587
|
|
|
|
|
588
|
|
|
static function update_card( $header, $sub_header, $url ) { ?> |
|
589
|
|
|
<div class="dops-foldable-card has-expanded-summary dops-card is-compact"> |
|
590
|
|
|
<div class="dops-foldable-card__header has-border" > |
|
591
|
|
|
<span class="dops-foldable-card__main"> |
|
592
|
|
|
<div class="dops-foldable-card__header-text"> |
|
593
|
|
|
<div class="dops-foldable-card__header-text branch-card-header"><?php echo esc_html( $header ); ?></div> |
|
594
|
|
|
<div class="dops-foldable-card__subheader"><?php echo esc_html( $sub_header ); ?></div> |
|
595
|
|
|
</div> |
|
596
|
|
|
</span> |
|
597
|
|
|
<span class="dops-foldable-card__secondary"> |
|
598
|
|
|
<span class="dops-foldable-card__summary"> |
|
599
|
|
|
<a |
|
600
|
|
|
href="<?php echo esc_url( $url ); ?>" |
|
601
|
|
|
class="is-primary jp-form-button activate-branch dops-button is-compact"><?php _e( 'Update', 'jetpack-beta' ); ?></a> |
|
602
|
|
|
</span> |
|
603
|
|
|
</span> |
|
604
|
|
|
</div> |
|
605
|
|
|
</div> |
|
606
|
|
|
<?php |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
static function update_action_url( $branch, $section ) { |
|
610
|
|
|
$query = array( |
|
611
|
|
|
'page' => 'jetpack-beta', |
|
612
|
|
|
'update-branch' => $branch, |
|
613
|
|
|
'section' => $section, |
|
614
|
|
|
'_nonce' => wp_create_nonce( 'update_branch' ), |
|
615
|
|
|
); |
|
616
|
|
|
|
|
617
|
|
|
return Jetpack_Beta::admin_url( '?' . build_query( $query ) ); |
|
618
|
|
|
} |
|
619
|
|
|
} |
|
620
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.