1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
<?php /** * Class Icon. * * @package AmpProject\AmpWP */
namespace AmpProject\AmpWP;
/** * Icons used to visually represent the state of a validation error. * * @package AmpProject\AmpWP * @since 2.0 * @internal */ final class Icon {
/** * Indicates there are validation errors for the AMP page. */ const INVALID = 'amp-invalid';
/** * Indicate an AMP version of the page is available. */ const LINK = 'amp-link';
/** * Indicates the page is valid AMP. */ const VALID = 'amp-valid';
/** * Indicates there are validation errors which have not been explicitly accepted. */ const WARNING = 'amp-warning';
/** * Indicates being on an AMP page. */ const LOGO = 'amp-logo';
/** * Icon class name. * * @var string */ private $icon;
/** * Constructor. * * @param string $icon Icon class name. */ private function __construct( $icon ) { $this->icon = $icon; }
/** * Invalid icon. * * @return Icon */ public static function invalid() { return new self( self::INVALID ); }
/** * Link icon * * @return Icon */ public static function link() { return new self( self::LINK ); }
/** * Valid icon * * @return Icon */ public static function valid() { return new self( self::VALID ); }
/** * Warning icon * * @return Icon */ public static function warning() { return new self( self::WARNING ); }
/** * Logo icon * * @return Icon */ public static function logo() { return new self( self::LOGO ); }
/** * Get color for current icon. * * @return string Hex color for icon. */ public function get_color() { // When updating the colors here, also do so for 'assets/css/src/amp-icons.css'. switch ( $this->icon ) { case self::INVALID: return '#dc3232'; case self::LINK: return '#00a0d2'; case self::VALID: return '#46b450'; case self::WARNING: return '#ffc733'; default: return ''; } }
/** * Render icon as HTML. * * @param array $attributes List of attributes to add to HTML output. * @return string Rendered HTML. */ public function to_html( $attributes = [] ) { $icon_class = 'amp-icon ' . $this->icon;
$attributes['class'] = ! empty( $attributes['class'] ) ? $attributes['class'] . ' ' . $icon_class : $icon_class;
$attributes_string = implode( ' ', array_map( static function ( $key, $value ) { return sprintf( '%s="%s"', esc_attr( sanitize_key( $key ) ), esc_attr( $value ) ); }, array_keys( $attributes ), $attributes ) );
return wp_kses_post( sprintf( '<span %s></span>', $attributes_string ) ); } }
|