]> _ Git - couzy.git/blob
95c62758d9f9ace7696c69fcfd0009dd446d0e82
[couzy.git] /
1 <?php
2 /**
3  * @package WPSEO\Admin|Google_Search_Console
4  */
5
6 /**
7  * Class WPSEO_GSC_Mapper
8  */
9 class WPSEO_GSC_Mapper {
10
11         /**
12          * The platforms which can be mapped.
13          *
14          * @var array
15          */
16         private static $platforms = array(
17                 'web'             => 'web',
18                 'mobile'          => 'mobile',
19                 'smartphone_only' => 'smartphoneOnly',
20                 'settings'        => 'settings', // This one is basicly not a platform, but a tab.
21         );
22
23         /**
24          * The categories which can be mapped
25          *
26          * @var array
27          */
28         private static $categories = array(
29                 'access_denied'    => 'authPermissions',
30                 'faulty_redirects' => 'manyToOneRedirect',
31                 'not_followed'     => 'notFollowed',
32                 'not_found'        => 'notFound',
33                 'other'            => 'other',
34                 'roboted'          => 'roboted',
35                 'server_error'     => 'serverError',
36                 'soft_404'         => 'soft404',
37         );
38
39         /**
40          * If there is no platform, just get the first key out of the array and redirect to it.
41          *
42          * @param string $platform
43          *
44          * @return mixed
45          */
46         public static function get_current_platform( $platform ) {
47                 if ( $current_platform = filter_input( INPUT_GET, $platform ) ) {
48                         return $current_platform;
49                 }
50
51                 wp_redirect( add_query_arg( $platform, key( self::$platforms ) ) );
52                 exit;
53         }
54
55         /**
56          * Mapping the platform
57          *
58          * @param string $platform
59          *
60          * @return mixed
61          */
62         public static function platform_to_api( $platform ) {
63                 if ( ! empty( $platform ) && array_key_exists( $platform, self::$platforms ) ) {
64                         return self::$platforms[ $platform ];
65                 }
66         }
67
68         /**
69          * Mapping the given platform by value and return its key
70          *
71          * @param string $platform
72          *
73          * @return string
74          */
75         public static function platform_from_api( $platform ) {
76                 if ( ! empty( $platform ) && $platform = array_search( $platform, self::$platforms ) ) {
77                         return $platform;
78                 }
79
80                 return $platform;
81         }
82
83         /**
84          * Mapping the given category by searching for its key.
85          *
86          * @param string $category
87          *
88          * @return mixed
89          */
90         public static function category_to_api( $category) {
91                 if ( ! empty( $category ) && array_key_exists( $category, self::$categories ) ) {
92                         return self::$categories[ $category ];
93                 }
94
95                 return $category;
96         }
97
98         /**
99          * Mapping the given category by value and return its key
100          *
101          * @param string $category
102          *
103          * @return string
104          */
105         public static function category_from_api( $category ) {
106                 if ( ! empty( $category ) && $category = array_search( $category, self::$categories ) ) {
107                         return $category;
108                 }
109
110                 return $category;
111         }
112
113 }