]> _ Git - couzy.git/blob
7ca9ce474ef27dadd810618aa731112d4f66ee7e
[couzy.git] /
1 <?php
2 /**
3  * @package WPSEO\Admin|Google_Search_Console
4  */
5
6 /**
7  * Class WPSEO_GSC_Platform_Tabs
8  */
9 class WPSEO_GSC_Platform_Tabs {
10
11         /**
12          * @var string
13          */
14         private $current_tab;
15
16         /**
17          * Return the tabs as a string
18          *
19          * @return string
20          */
21         public function __toString() {
22                 return $this->platform_tabs();
23         }
24
25         /**
26          * Getting the current_tab
27          *
28          * @return string
29          */
30         public function current_tab() {
31                 return $this->current_tab;
32         }
33
34         /**
35          * Loops through the array with all the platforms and convert it into an array
36          *
37          * @return string
38          */
39         private function platform_tabs() {
40                 $tabs = array( 'settings' => __( 'Settings', 'wordpress-seo' ) );
41
42                 $platforms = array(
43                         'web'             => __( 'Desktop', 'wordpress-seo' ),
44                         'smartphone_only' => __( 'Smartphone', 'wordpress-seo' ),
45                         'mobile'          => __( 'Feature phone', 'wordpress-seo' ),
46                 );
47
48                 if ( WPSEO_GSC_Settings::get_profile() !== '' ) {
49                         $tabs = array_merge( $platforms, $tabs );
50                 }
51
52                 $admin_link = admin_url( 'admin.php?page=wpseo_search_console&tab=' );
53
54                 $this->set_current_tab( $tabs );
55
56                 $return = '';
57
58                 foreach ( $tabs as $platform_target => $platform_value ) {
59                         $return .= $this->platform_tab( $platform_target, $platform_value, $admin_link );
60                 }
61
62                 return $return;
63         }
64
65         /**
66          * Setting the current tab
67          *
68          * @param array $platforms
69          */
70         private function set_current_tab( array $platforms ) {
71                 $this->current_tab = key( $platforms );
72                 if ( $current_platform = filter_input( INPUT_GET, 'tab' ) ) {
73                         $this->current_tab = $current_platform;
74                 }
75         }
76
77         /**
78          * Parses the tab
79          *
80          * @param string $platform_target
81          * @param string $platform_value
82          * @param string $admin_link
83          *
84          * @return string
85          */
86         private function platform_tab( $platform_target, $platform_value, $admin_link ) {
87                 $active = '';
88                 if ( $this->current_tab === $platform_target ) {
89                         $active = ' nav-tab-active';
90                 }
91
92                 return '<a class="nav-tab ' . $active . '" id="' . $platform_target . '-tab" href="' . $admin_link . $platform_target . '">' . $platform_value . '</a>';
93         }
94
95 }