Completed
Push — add/sync-rest-2 ( f15b08...cc5c19 )
by
unknown
433:14 queued 423:41
created

Jetpack_Sync_Dashboard::jetpack_sync_admin_head()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
class Jetpack_Sync_Dashboard {
4
	static function init() {
5
		add_action( 'wp_ajax_jetpack-sync-queue-status', array( __CLASS__, 'queue_status' ) );
6
	}
7
8
	// returns size of queue and age of oldest item (aka lag)
9
	public function queue_status() {
10
		$client = Jetpack_Sync_Client::getInstance();
11
		$queue = $client->get_sync_queue();
12
13
		return array(
14
			'size' => $queue->size(),
15
			'lag' => $queue->lag()
16
		);
17
	}
18
19
	static function jetpack_sync_admin_head() {
20
		?>
21
		<script type="text/javascript">
22
			jQuery( document ).ready( function($) {
23
				console.log("loaded");
24
			} );
25
		</script>
26
		<?php 
27
	}
28
29
	static function dashboard_ui() {			
30
		if ( ! current_user_can( 'manage_options' ) )
31
			wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
32
33
		$strings = json_encode( array(
34
			'WAITING'     => array(
35
				'action' => __( 'Refresh Status', 'jetpack' ),
36
				'status' => __( 'Indexing request queued and waiting&hellip;', 'jetpack' ),
37
			),
38
			'INDEXING'    => array(
39
				'action' => __( 'Refresh Status', 'jetpack' ),
40
				'status' => __( 'Indexing posts', 'jetpack' ),
41
			),
42
			'DONE'        => array(
43
				'action' => __( 'Reindex Posts', 'jetpack' ),
44
				'status' => __( 'Posts indexed.', 'jetpack' ),
45
			),
46
			'ERROR'       => array(
47
				'action' => __( 'Refresh Status', 'jetpack' ),
48
				'status' => __( 'Status unknown.', 'jetpack' ),
49
			),
50
			'ERROR:LARGE' => array(
51
				'action' => __( 'Refresh Status', 'jetpack' ),
52
				'status' => __( 'This site is too large, please contact Jetpack support to sync.', 'jetpack' ),
53
			),
54
		) );
55
56
		wp_enqueue_script(
57
			'jetpack_sync_reindex_control',
58
			plugins_url( '_inc/jquery.jetpack-sync.js', JETPACK__PLUGIN_FILE ),
59
			array( 'jquery' ),
60
			JETPACK__VERSION
61
		);
62
63
// 		$template = <<<EOT
64
// 			<p class="jetpack_sync_reindex_control" id="jetpack_sync_reindex_control" data-strings="%s">
65
// 				<input type="submit" class="jetpack_sync_reindex_control_action button" value="%s" disabled />
66
// 				<span class="jetpack_sync_reindex_control_status">&hellip;</span>
67
// 			</p>
68
// EOT;
69
70
		$template = <<<EOT
71
			<p class="jetpack_sync_reindex_control" id="jetpack_sync_reindex_control" data-strings="%s">
72
				This is a test 
73
				<input type="submit" class="jetpack_sync_reindex_control_action button" value="%s" disabled />
74
				<span class="jetpack_sync_reindex_control_status">&hellip;</span>
75
			</p>
76
EOT;
77
78
		echo sprintf(
79
			$template,
80
			esc_attr( $strings ),
81
			esc_attr__( 'Refresh Status', 'jetpack' )
82
		);
83
	}
84
85
}
86