class-taxonomy-metabox.php
13 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php
/**
* @package WPSEO\Admin
*/
/**
* This class generates the metabox on the edit term page.
*/
class WPSEO_Taxonomy_Metabox {
/**
* @var stdClass
*/
private $term;
/**
* @var string
*/
private $taxonomy;
/**
* @var WPSEO_Taxonomy_Fields_Presenter
*/
private $taxonomy_tab_content;
/**
* The constructor.
*
* @param string $taxonomy The taxonomy.
* @param stdClass $term The term.
*/
public function __construct( $taxonomy, $term ) {
$this->term = $term;
$this->taxonomy = $taxonomy;
$this->taxonomy_tab_content = new WPSEO_Taxonomy_Fields_Presenter( $this->term );
add_action( 'admin_footer', array( $this, 'template_generic_tab' ) );
add_action( 'admin_footer', array( $this, 'template_keyword_tab' ) );
}
/**
* Shows the Yoast SEO metabox for the term.
*/
public function display() {
$content_sections = $this->get_content_sections();
$product_title = 'Yoast SEO';
if ( file_exists( WPSEO_PATH . 'premium/' ) ) {
$product_title .= ' Premium';
}
printf( '<div id="wpseo_meta" class="postbox yoast wpseo-taxonomy-metabox-postbox"><h2><span>%1$s</span></h2>', $product_title );
echo '<div class="inside">';
$helpcenter_tab = new WPSEO_Option_Tab( 'tax-metabox', 'Meta box',
array( 'video_url' => 'https://yoa.st/metabox-taxonomy-screencast' ) );
$helpcenter = new WPSEO_Help_Center( 'tax-metabox', $helpcenter_tab );
$helpcenter->output_help_center();
echo '<div id="taxonomy_overall"></div>';
if ( ! defined( 'WPSEO_PREMIUM_FILE' ) ) {
echo $this->get_buy_premium_link();
}
echo '<div class="wpseo-metabox-sidebar"><ul>';
foreach ( $content_sections as $content_section ) {
if ( $content_section->name === 'premium' ) {
continue;
}
$content_section->display_link();
}
echo '</ul></div>';
foreach ( $content_sections as $content_section ) {
$content_section->display_content();
}
echo '</div></div>';
}
/**
* Returns the relevant metabox sections for the current view.
*
* @return WPSEO_Metabox_Section[]
*/
private function get_content_sections() {
$content_sections = array(
$this->get_content_meta_section(),
$this->get_social_meta_section(),
$this->get_settings_meta_section(),
);
if ( ! defined( 'WPSEO_PREMIUM_FILE' ) ) {
$content_sections[] = $this->get_buy_premium_section();
}
return $content_sections;
}
/**
* Returns the metabox section for the content analysis.
*
* @return WPSEO_Metabox_Section
*/
private function get_content_meta_section() {
$taxonomy_content_fields = new WPSEO_Taxonomy_Content_Fields( $this->term );
$content = $this->taxonomy_tab_content->html( $taxonomy_content_fields->get() );
$tab = new WPSEO_Metabox_Form_Tab(
'content',
$content,
__( '', 'wordpress-seo' ),
array(
'tab_class' => 'yoast-seo__remove-tab',
)
);
return new WPSEO_Metabox_Tab_Section(
'content',
'<span class="screen-reader-text">' . __( 'Content optimization', 'wordpress-seo' ) . '</span><span class="yst-traffic-light-container">' . $this->traffic_light_svg() . '</span>',
array( $tab ),
array(
'link_aria_label' => __( 'Content optimization', 'wordpress-seo' ),
'link_class' => 'yoast-tooltip yoast-tooltip-e',
)
);
}
/**
* Returns the metabox section for the settings.
*
* @return WPSEO_Metabox_Section
*/
private function get_settings_meta_section() {
$taxonomy_settings_fields = new WPSEO_Taxonomy_Settings_Fields( $this->term );
$content = $this->taxonomy_tab_content->html( $taxonomy_settings_fields->get() );
$tab = new WPSEO_Metabox_Form_Tab(
'settings',
$content,
__( 'Settings', 'wordpress-seo' ),
array(
'single' => true,
)
);
return new WPSEO_Metabox_Tab_Section(
'settings',
'<span class="screen-reader-text">' . __( 'Settings', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-admin-generic"></span>',
array( $tab ),
array(
'link_aria_label' => __( 'Settings', 'wordpress-seo' ),
'link_class' => 'yoast-tooltip yoast-tooltip-e',
)
);
}
/**
* Returns the metabox section for the social settings.
*
* @return WPSEO_Metabox_Section
*/
private function get_social_meta_section() {
$options = WPSEO_Options::get_option( 'wpseo_social' );
$taxonomy_social_fields = new WPSEO_Taxonomy_Social_Fields( $this->term );
$tabs = array();
$single = true;
if ( $options['opengraph'] === true && $options['twitter'] === true ) {
$single = null;
}
if ( $options['opengraph'] === true ) {
$facebook_meta_fields = $taxonomy_social_fields->get_by_network( 'opengraph' );
$tabs[] = new WPSEO_Metabox_Form_Tab(
'facebook',
$this->taxonomy_tab_content->html( $facebook_meta_fields ),
'<span class="screen-reader-text">' . __( 'Facebook / Open Graph metadata', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-facebook-alt"></span>',
array(
'link_aria_label' => __( 'Facebook / Open Graph metadata', 'wordpress-seo' ),
'link_class' => 'yoast-tooltip yoast-tooltip-se',
'single' => $single,
)
);
}
if ( $options['twitter'] === true ) {
$twitter_meta_fields = $taxonomy_social_fields->get_by_network( 'twitter' );
$tabs[] = new WPSEO_Metabox_Form_Tab(
'twitter',
$this->taxonomy_tab_content->html( $twitter_meta_fields ),
'<span class="screen-reader-text">' . __( 'Twitter metadata', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-twitter"></span>',
array(
'link_aria_label' => __( 'Twitter metadata', 'wordpress-seo' ),
'link_class' => 'yoast-tooltip yoast-tooltip-se',
'single' => $single,
)
);
}
return new WPSEO_Metabox_Tab_Section(
'social',
'<span class="screen-reader-text">' . __( 'Social', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-share"></span>',
$tabs,
array(
'link_aria_label' => __( 'Social', 'wordpress-seo' ),
'link_class' => 'yoast-tooltip yoast-tooltip-e',
)
);
}
/**
* Returns a link to activate the Buy Premium tab.
*
* @return string
*/
private function get_buy_premium_link() {
return sprintf( "<div class='%s'><a href='#wpseo-meta-section-premium' class='wpseo-meta-section-link'><span class='dashicons dashicons-star-filled wpseo-buy-premium'></span>%s</a></div>",
'wpseo-metabox-buy-premium',
__( 'Go Premium', 'wordpress-seo' )
);
}
/**
* Returns the metabox section for the Premium section..
*
* @return WPSEO_Metabox_Section
*/
private function get_buy_premium_section() {
$content = sprintf( "<div class='wpseo-metabox-premium-description'>
%s
<ul class='wpseo-metabox-premium-advantages'>
<li>
<strong>%s</strong> - %s
</li>
<li>
<strong>%s</strong> - %s
</li>
<li>
<strong>%s</strong> - %s
</li>
<li>
<strong>%s</strong> - %s
</li>
</ul>
<a target='_blank' id='wpseo-buy-premium-popup-button' class='button button-buy-premium wpseo-metabox-go-to' href='%s'>
%s
</a>
<p><a target='_blank' class='wpseo-metabox-go-to' href='%s'>%s</a></p>
</div>",
/* translators: %1$s expands to Yoast SEO Premium. */
sprintf( __( 'You\'re not getting the benefits of %1$s yet. If you had %1$s, you could use its awesome features:', 'wordpress-seo' ), 'Yoast SEO Premium' ),
__( 'Redirect manager', 'wordpress-seo' ),
__( 'Create and manage redirects within your WordPress install.', 'wordpress-seo' ),
__( 'Multiple focus keywords', 'wordpress-seo' ),
__( 'Optimize a single post for up to 5 keywords.', 'wordpress-seo' ),
__( 'Social Previews', 'wordpress-seo' ),
__( 'Check what your Facebook or Twitter post will look like.', 'wordpress-seo' ),
__( 'Premium support', 'wordpress-seo' ),
__( 'Gain access to our 24/7 support team.', 'wordpress-seo' ),
'https://yoa.st/pe-buy-premium',
/* translators: %s expands to Yoast SEO Premium. */
sprintf( __( 'Get %s now!', 'wordpress-seo' ), 'Yoast SEO Premium' ),
'https://yoa.st/pe-premium-page',
__( 'More info', 'wordpress-seo' )
);
$tab = new WPSEO_Metabox_Form_Tab(
'premium',
$content,
'Yoast SEO Premium',
array(
'single' => true,
)
);
return new WPSEO_Metabox_Tab_Section(
'premium',
'<span class="dashicons dashicons-star-filled wpseo-buy-premium"></span>',
array( $tab ),
array(
'link_aria_label' => 'Yoast SEO Premium',
'link_class' => 'yoast-tooltip yoast-tooltip-e',
)
);
}
/**
* Test whether we are on a public taxonomy - no metabox actions needed if we are not
* Unfortunately we have to hook most everything in before the point where all taxonomies are registered and
* we know which taxonomy is being requested, so we need to use this check in nearly every hooked in function.
*
* @since 1.5.0
*/
private function tax_is_public() {
// Don't make static as taxonomies may still be added during the run.
$taxonomy = get_taxonomy( $this->taxonomy );
return $taxonomy->public;
}
/**
* Return the SVG for the traffic light in the metabox.
*/
public function traffic_light_svg() {
return <<<SVG
<svg class="yst-traffic-light init" version="1.1" xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
x="0px" y="0px" viewBox="0 0 30 47" enable-background="new 0 0 30 47" xml:space="preserve">
<g id="BG_1_">
</g>
<g id="traffic_light">
<g>
<g>
<g>
<path fill="#5B2942" d="M22,0H8C3.6,0,0,3.6,0,7.9v31.1C0,43.4,3.6,47,8,47h14c4.4,0,8-3.6,8-7.9V7.9C30,3.6,26.4,0,22,0z
M27.5,38.8c0,3.1-2.6,5.7-5.8,5.7H8.3c-3.2,0-5.8-2.5-5.8-5.7V8.3c0-1.5,0.6-2.9,1.7-4c1.1-1,2.5-1.6,4.1-1.6h13.4
c1.5,0,3,0.6,4.1,1.6c1.1,1.1,1.7,2.5,1.7,4V38.8z"/>
</g>
<g class="traffic-light-color traffic-light-red">
<ellipse fill="#C8C8C8" cx="15" cy="23.5" rx="5.7" ry="5.6"/>
<ellipse fill="#DC3232" cx="15" cy="10.9" rx="5.7" ry="5.6"/>
<ellipse fill="#C8C8C8" cx="15" cy="36.1" rx="5.7" ry="5.6"/>
</g>
<g class="traffic-light-color traffic-light-orange">
<ellipse fill="#F49A00" cx="15" cy="23.5" rx="5.7" ry="5.6"/>
<ellipse fill="#C8C8C8" cx="15" cy="10.9" rx="5.7" ry="5.6"/>
<ellipse fill="#C8C8C8" cx="15" cy="36.1" rx="5.7" ry="5.6"/>
</g>
<g class="traffic-light-color traffic-light-green">
<ellipse fill="#C8C8C8" cx="15" cy="23.5" rx="5.7" ry="5.6"/>
<ellipse fill="#C8C8C8" cx="15" cy="10.9" rx="5.7" ry="5.6"/>
<ellipse fill="#63B22B" cx="15" cy="36.1" rx="5.7" ry="5.6"/>
</g>
<g class="traffic-light-color traffic-light-empty">
<ellipse fill="#C8C8C8" cx="15" cy="23.5" rx="5.7" ry="5.6"/>
<ellipse fill="#C8C8C8" cx="15" cy="10.9" rx="5.7" ry="5.6"/>
<ellipse fill="#C8C8C8" cx="15" cy="36.1" rx="5.7" ry="5.6"/>
</g>
<g class="traffic-light-color traffic-light-init">
<ellipse fill="#5B2942" cx="15" cy="23.5" rx="5.7" ry="5.6"/>
<ellipse fill="#5B2942" cx="15" cy="10.9" rx="5.7" ry="5.6"/>
<ellipse fill="#5B2942" cx="15" cy="36.1" rx="5.7" ry="5.6"/>
</g>
</g>
</g>
</g>
</svg>
SVG;
}
/**
* Generic tab.
*/
public function template_generic_tab() {
// This template belongs to the post scraper so don't echo it if it isn't enqueued.
if ( ! wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ) ) {
return;
}
echo '<script type="text/html" id="tmpl-generic_tab">
<li class="<# if ( data.classes ) { #>{{data.classes}}<# } #><# if ( data.active ) { #> active<# } #>">
<a class="wpseo_tablink" href="#wpseo_generic" data-score="{{data.score}}">
<span class="wpseo-score-icon {{data.score}}"></span>
<span class="wpseo-tab-prefix">{{data.prefix}}</span>
<span class="wpseo-tab-label">{{data.label}}</span>
<span class="screen-reader-text wpseo-generic-tab-textual-score">{{data.scoreText}}</span>
</a>
<# if ( data.hideable ) { #>
<button type="button" class="remove-tab" aria-label="{{data.removeLabel}}"><span>x</span></button>
<# } #>
</li>
</script>';
}
/**
* Keyword tab for enabling analysis of multiple keywords.
*/
public function template_keyword_tab() {
// This template belongs to the term scraper so don't echo it if it isn't enqueued.
if ( ! wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ) ) {
return;
}
echo '<script type="text/html" id="tmpl-keyword_tab">
<li class="<# if ( data.classes ) { #>{{data.classes}}<# } #><# if ( data.active ) { #> active<# } #>">
<a class="wpseo_tablink" href="#wpseo_content" data-keyword="{{data.keyword}}" data-score="{{data.score}}">
<span class="wpseo-score-icon {{data.score}}"></span>
<span class="wpseo-tab-prefix">{{data.prefix}}</span>
<em class="wpseo-keyword">{{data.label}}</em>
<span class="screen-reader-text wpseo-keyword-tab-textual-score">{{data.scoreText}}</span>
</a>
<# if ( data.hideable ) { #>
<button type="button" class="remove-keyword" aria-label="{{data.removeLabel}}"><span>x</span></button>
<# } #>
</li>
</script>';
}
}