Completed
Push — kraftbj-patch-2 ( f1a4bb...ba1272 )
by
unknown
25:04 queued 15:38
created

Inline_Help   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A register_actions() 0 14 2
A add_fab_icon() 0 53 2
A add_fab_styles() 0 3 1
1
<?php
2
/**
3
 * Inline Help.
4
 *
5
 * Handles providing a LiveChat icon within WPAdmin until such time
6
 * as the full live chat experience can be run in a non-Calypso environment.
7
 *
8
 * @package automattic/jetpack
9
 */
10
11
namespace Automattic\Jetpack\Dashboard_Customizations;
12
13
/**
14
 * Class Inline_Help.
15
 */
16
class Inline_Help {
17
18
	/**
19
	 * Inline_Help constructor.
20
	 */
21
	public function __construct() {
22
		$this->register_actions();
23
	}
24
25
	/**
26
	 * Registers actions.
27
	 *
28
	 * @return void
29
	 */
30
	public function register_actions() {
31
		// phpcs:disable WordPress.Security.NonceVerification.Recommended
32
		// Do not inject the FAB icon on embedded screens since the parent window may already contain a FAB icon.
33
		$is_framed = ! empty( $_GET['frame-nonce'] );
34
35
		if ( $is_framed ) {
36
			return;
37
		}
38
		// phpcs:enable WordPress.Security.NonceVerification.Recommended
39
40
		add_action( 'admin_footer', array( $this, 'add_fab_icon' ) );
41
42
		add_action( 'admin_enqueue_scripts', array( $this, 'add_fab_styles' ) );
43
	}
44
45
	/**
46
	 * Outputs "FAB" icon markup and SVG.
47
	 *
48
	 * @return void|string the HTML markup for the FAB or early exit.
49
	 */
50
	public function add_fab_icon() {
51
52
		if ( wp_doing_ajax() ) {
53
			return;
54
		}
55
56
		$svg_allowed = array(
57
			'svg'   => array(
58
				'id'              => true,
59
				'class'           => true,
60
				'aria-hidden'     => true,
61
				'aria-labelledby' => true,
62
				'role'            => true,
63
				'xmlns'           => true,
64
				'width'           => true,
65
				'height'          => true,
66
				'viewbox'         => true, // <= Must be lower case!
67
			),
68
			'g'     => array( 'fill' => true ),
69
			'title' => array( 'title' => true ),
70
			'path'  => array(
71
				'd'    => true,
72
				'fill' => true,
73
			),
74
		);
75
76
		$gridicon_help = file_get_contents( __DIR__ . '/gridicon-help.svg', true );
77
78
		// Add tracking data to link to be picked up by Calypso for GA and Tracks usage.
79
		$tracking_href = add_query_arg(
80
			array(
81
				'utm_source'  => 'wp_admin',
82
				'utm_medium'  => 'other',
83
				'utm_content' => 'jetpack_masterbar_inline_help_click',
84
				'flags'       => 'a8c-analytics.on',
85
			),
86
			'https://wordpress.com/help'
87
		);
88
89
		// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
90
		// We trust that output in the template has been escaped.
91
		echo load_template(
92
			__DIR__ . '/inline-help-template.php',
93
			true,
94
			array(
95
				'href'        => $tracking_href,
96
				'icon'        => $gridicon_help,
97
				'svg_allowed' => $svg_allowed,
98
			)
99
		);
100
		// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
101
102
	}
103
104
	/**
105
	 * Enqueues FAB CSS styles.
106
	 *
107
	 * @return void
108
	 */
109
	public function add_fab_styles() {
110
		wp_enqueue_style( 'a8c-faux-inline-help', plugins_url( 'inline-help.css', __FILE__ ), array(), JETPACK__VERSION );
111
	}
112
}
113