PluginProbe
Hostinger Tools / 2.0.4
Hostinger Tools v2.0.4
3.0.78 3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 All 109 releases
← All changes | includes/class-hostinger-helper.php +127 -12 1.8.12.0.4 View file →
@@ -1,9 +1,24 @@
1 1 <?php
2 2
3 -if ( ! defined( 'ABSPATH' ) ) exit;
3 +class Hostinger_Helper {
4 + public const HOSTINGER_FREE_SUBDOMAIN_URL = 'hostingersite.com';
5 + public const HOSTINGER_PAGE = '/wp-admin/admin.php?page=hostinger';
6 + public const CLIENT_WOO_COMPLETED_ACTIONS = 'woocommerce_task_list_tracked_completed_tasks';
7 + private const PROMOTIONAL_LINKS = array(
8 + 'fr_FR' => 'https://www.hostinger.fr/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
9 + 'es_ES' => 'https://www.hostinger.es/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
10 + 'ar' => 'https://www.hostinger.ae/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
11 + 'zh_CN' => 'https://www.hostinger.com.hk/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
12 + 'id_ID' => 'https://www.hostinger.co.id/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
13 + 'lt_LT' => 'https://www.hostinger.lt/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
14 + 'pt_PT' => 'https://www.hostinger.pt/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
15 + 'uk' => 'https://www.hostinger.com.ua/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
16 + 'tr_TR' => 'https://www.hostinger.com.tr/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
17 + 'en_US' => 'https://www.hostinger.com/cpanel-login?r=%2Fjump-to%2Fnew-panel%2Fsection%2Freferrals&utm_source=Banner&utm_medium=HostingerWPplugin',
18 + );
4 19
5 -class Hostinger_Helper {
20 + private const HPANEL_DOMAIN_URL = 'https://hpanel.hostinger.com/websites/';
6 21
7 22 /**
8 23 *
9 24 * Check if plugin is active
@@ -22,18 +37,13 @@
22 37 return false;
23 38 }
24 39
25 40 public static function get_api_token(): string {
26 - require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
27 - require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
28 -
29 41 $api_token = '';
30 - $token_path = HOSTINGER_WP_TOKEN;
31 - $filesystem = new WP_Filesystem_Direct( true );
32 - $token_file = $filesystem->get_contents( $token_path );
42 + $token_file = HOSTINGER_WP_TOKEN;
33 43
34 - if ( file_exists( $token_path ) && ! empty( $token_file ) ) {
35 - $api_token = $token_file;
44 + if ( file_exists( $token_file ) && ! empty( file_get_contents( $token_file ) ) ) {
45 + $api_token = file_get_contents( $token_file );
36 46 }
37 47
38 48 return $api_token;
39 49 }
@@ -46,9 +56,9 @@
46 56 * @access public
47 57 */
48 58
49 59 public function get_host_info(): string {
50 - $host = sanitize_text_field( $_SERVER['HTTP_HOST'] ?? '' );
60 + $host = $_SERVER['HTTP_HOST'] ?? '';
51 61 $site_url = get_site_url();
52 62 $site_url = preg_replace( '#^https?://#', '', $site_url );
53 63
54 64 if ( ! empty( $site_url ) && ! empty( $host ) && strpos( $site_url, $host ) === 0 ) {
@@ -61,8 +71,113 @@
61 71
62 72 return $host;
63 73 }
64 74
75 + public function is_preview_domain(): bool {
76 + if ( function_exists( 'getallheaders' ) ) {
77 + $headers = getallheaders();
78 + }
65 79
80 + if ( isset( $headers['X-Preview-Indicator'] ) && $headers['X-Preview-Indicator'] ) {
81 + return true;
82 + }
83 +
84 + return false;
85 + }
86 +
87 + public function is_free_subdomain(): bool {
88 + $site_url = preg_replace( '#^https?://#', '', get_site_url() );
89 +
90 + return ! empty( $site_url ) && strpos( $site_url, self::HOSTINGER_FREE_SUBDOMAIN_URL ) !== false;
91 + }
92 +
93 + public function is_hostinger_admin_page(): bool {
94 +
95 + if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
96 + return false;
97 + }
98 +
99 + $current_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] );
100 +
101 + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
102 + return false;
103 + }
104 +
105 + if ( isset( $current_uri ) && strpos( $current_uri, '/wp-json/' ) !== false ) {
106 + return false;
107 + }
108 +
109 + if ( strpos( $current_uri, self::HOSTINGER_PAGE ) !== false ) {
110 + return true;
111 + }
112 +
113 + return false;
114 + }
115 +
116 + /**
117 + *
118 + * Error log
119 + *
120 + * @since 1.9.6
121 + * @access public
122 + */
123 + public function error_log( string $message ): void {
124 + if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
125 + error_log( print_r( $message, true ) );
126 + }
127 + }
128 +
129 + public function default_woocommerce_survey_steps_completed( array $steps ): bool {
130 + $completed_actions = get_option( self::CLIENT_WOO_COMPLETED_ACTIONS, array() );
131 +
132 + return empty( array_diff( $steps, $completed_actions ) );
133 + }
134 +
135 + public function is_this_page( string $page ): bool {
136 +
137 + if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
138 + return false;
139 + }
140 +
141 + $current_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] );
142 +
143 + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
144 + return false;
145 + }
146 +
147 + if ( isset( $current_uri ) && strpos( $current_uri, '/wp-json/' ) !== false ) {
148 + return false;
149 + }
150 +
151 + if ( strpos( $current_uri, $page ) !== false ) {
152 + return true;
153 + }
154 +
155 + return false;
156 + }
157 +
158 + public function get_promotional_link_url( string $locale ): string {
159 + if ( isset( self::PROMOTIONAL_LINKS[ $locale ] ) ) {
160 + return self::PROMOTIONAL_LINKS[ $locale ];
161 + }
162 +
163 + return self::PROMOTIONAL_LINKS['en_US'];
164 + }
165 +
166 + public function get_domain_from_url(): string {
167 + $host = parse_url( get_site_url(), PHP_URL_HOST );
168 +
169 + return $host === false ? self::HPANEL_DOMAIN_URL : $host;
170 + }
171 +
172 + public function get_hpanel_domain_url(): string {
173 + $domain_url = $this->get_domain_from_url();
174 +
175 + if( $domain_url === self::HPANEL_DOMAIN_URL ) {
176 + return $domain_url;
177 + }
178 +
179 + return self::HPANEL_DOMAIN_URL . $domain_url;
180 + }
66 181 }
67 182
68 -$hostiner_helper = new Hostinger_Helper();
183 +$hostinger_helper = new Hostinger_Helper();