class-gsc-platform-tabs.php
2.14 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
<?php
/**
* @package WPSEO\Admin|Google_Search_Console
*/
/**
* Class WPSEO_GSC_Platform_Tabs
*/
class WPSEO_GSC_Platform_Tabs {
/**
* @var string
*/
private $current_tab;
/**
* Return the tabs as a string
*
* @return string
*/
public function __toString() {
return $this->platform_tabs();
}
/**
* Getting the current_tab
*
* @return string
*/
public function current_tab() {
return $this->current_tab;
}
/**
* Loops through the array with all the platforms and convert it into an array
*
* @return string
*/
private function platform_tabs() {
$tabs = array( 'settings' => __( 'Settings', 'wordpress-seo' ) );
$platforms = array(
'web' => __( 'Desktop', 'wordpress-seo' ),
'smartphone_only' => __( 'Smartphone', 'wordpress-seo' ),
'mobile' => __( 'Feature phone', 'wordpress-seo' ),
);
if ( WPSEO_GSC_Settings::get_profile() !== '' ) {
$tabs = array_merge( $platforms, $tabs );
}
$admin_link = admin_url( 'admin.php?page=wpseo_search_console&tab=' );
$this->set_current_tab( $tabs );
$return = '';
foreach ( $tabs as $platform_target => $platform_value ) {
$return .= $this->platform_tab( $platform_target, $platform_value, $admin_link );
}
return $return;
}
/**
* Setting the current tab
*
* @param array $platforms Set of platforms (desktop, mobile, feature phone).
*/
private function set_current_tab( array $platforms ) {
$this->current_tab = key( $platforms );
if ( $current_platform = filter_input( INPUT_GET, 'tab' ) ) {
$this->current_tab = $current_platform;
}
}
/**
* Parses the tab
*
* @param string $platform_target Platform (desktop, mobile, feature phone).
* @param string $platform_value Link anchor.
* @param string $admin_link Link URL admin base.
*
* @return string
*/
private function platform_tab( $platform_target, $platform_value, $admin_link ) {
$active = '';
if ( $this->current_tab === $platform_target ) {
$active = ' nav-tab-active';
}
return '<a class="nav-tab ' . $active . '" id="' . $platform_target . '-tab" href="' . $admin_link . $platform_target . '">' . $platform_value . '</a>';
}
}