| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Freemius |
| 4 |
* @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 |
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 6 |
* @since 1.0.3 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* @property int $blog_id |
| 15 |
*/ |
| 16 |
#[AllowDynamicProperties] |
| 17 |
class FS_Site extends FS_Scope_Entity { |
| 18 |
/** |
| 19 |
* @var number |
| 20 |
*/ |
| 21 |
public $site_id; |
| 22 |
/** |
| 23 |
* @var number |
| 24 |
*/ |
| 25 |
public $plugin_id; |
| 26 |
/** |
| 27 |
* @var number |
| 28 |
*/ |
| 29 |
public $user_id; |
| 30 |
/** |
| 31 |
* @var string |
| 32 |
*/ |
| 33 |
public $title; |
| 34 |
/** |
| 35 |
* @var string |
| 36 |
*/ |
| 37 |
public $url; |
| 38 |
/** |
| 39 |
* @var string |
| 40 |
*/ |
| 41 |
public $version; |
| 42 |
/** |
| 43 |
* @var string E.g. en-GB |
| 44 |
*/ |
| 45 |
public $language; |
| 46 |
/** |
| 47 |
* @var string Platform version (e.g WordPress version). |
| 48 |
*/ |
| 49 |
public $platform_version; |
| 50 |
/** |
| 51 |
* Freemius SDK version |
| 52 |
* |
| 53 |
* @author Leo Fajardo (@leorw) |
| 54 |
* @since 1.2.2 |
| 55 |
* |
| 56 |
* @var string SDK version (e.g.: 1.2.2) |
| 57 |
*/ |
| 58 |
public $sdk_version; |
| 59 |
/** |
| 60 |
* @var string Programming language version (e.g PHP version). |
| 61 |
*/ |
| 62 |
public $programming_language_version; |
| 63 |
/** |
| 64 |
* @var number|null |
| 65 |
*/ |
| 66 |
public $plan_id; |
| 67 |
/** |
| 68 |
* @var number|null |
| 69 |
*/ |
| 70 |
public $license_id; |
| 71 |
/** |
| 72 |
* @var number|null |
| 73 |
*/ |
| 74 |
public $trial_plan_id; |
| 75 |
/** |
| 76 |
* @var string|null |
| 77 |
*/ |
| 78 |
public $trial_ends; |
| 79 |
/** |
| 80 |
* @since 1.0.9 |
| 81 |
* |
| 82 |
* @var bool |
| 83 |
*/ |
| 84 |
public $is_premium = false; |
| 85 |
/** |
| 86 |
* @author Leo Fajardo (@leorw) |
| 87 |
* |
| 88 |
* @since 1.2.1.5 |
| 89 |
* @deprecated Since 2.5.1 |
| 90 |
* @todo Remove after a few releases. |
| 91 |
* |
| 92 |
* @var bool |
| 93 |
*/ |
| 94 |
public $is_disconnected = false; |
| 95 |
/** |
| 96 |
* @since 2.0.0 |
| 97 |
* |
| 98 |
* @var bool |
| 99 |
*/ |
| 100 |
public $is_active = true; |
| 101 |
/** |
| 102 |
* @since 2.0.0 |
| 103 |
* |
| 104 |
* @var bool |
| 105 |
*/ |
| 106 |
public $is_uninstalled = false; |
| 107 |
/** |
| 108 |
* @author Edgar Melkonyan |
| 109 |
* |
| 110 |
* @since 2.4.2 |
| 111 |
* |
| 112 |
* @var bool |
| 113 |
*/ |
| 114 |
public $is_beta; |
| 115 |
|
| 116 |
/** |
| 117 |
* @param stdClass|bool $site |
| 118 |
*/ |
| 119 |
function __construct( $site = false ) { |
| 120 |
parent::__construct( $site ); |
| 121 |
|
| 122 |
if ( is_object( $site ) ) { |
| 123 |
$this->plan_id = $site->plan_id; |
| 124 |
} |
| 125 |
|
| 126 |
if ( ! is_bool( $this->is_disconnected ) ) { |
| 127 |
$this->is_disconnected = false; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
static function get_type() { |
| 132 |
return 'install'; |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* @author Vova Feldman (@svovaf) |
| 137 |
* @since 2.0.0 |
| 138 |
* |
| 139 |
* @param string $url |
| 140 |
* |
| 141 |
* @return bool |
| 142 |
*/ |
| 143 |
static function is_localhost_by_address( $url ) { |
| 144 |
if ( false !== strpos( $url, '127.0.0.1' ) || |
| 145 |
false !== strpos( $url, 'localhost' ) |
| 146 |
) { |
| 147 |
return true; |
| 148 |
} |
| 149 |
|
| 150 |
if ( ! fs_starts_with( $url, 'http' ) ) { |
| 151 |
$url = 'http://' . $url; |
| 152 |
} |
| 153 |
|
| 154 |
$url_parts = parse_url( $url ); |
| 155 |
|
| 156 |
$subdomain = $url_parts['host']; |
| 157 |
|
| 158 |
return ( |
| 159 |
// Starts with. |
| 160 |
fs_starts_with( $subdomain, 'local.' ) || |
| 161 |
fs_starts_with( $subdomain, 'dev.' ) || |
| 162 |
fs_starts_with( $subdomain, 'test.' ) || |
| 163 |
fs_starts_with( $subdomain, 'stage.' ) || |
| 164 |
fs_starts_with( $subdomain, 'staging.' ) || |
| 165 |
|
| 166 |
// Ends with. |
| 167 |
fs_ends_with( $subdomain, '.dev' ) || |
| 168 |
fs_ends_with( $subdomain, '.test' ) || |
| 169 |
fs_ends_with( $subdomain, '.staging' ) || |
| 170 |
fs_ends_with( $subdomain, '.local' ) || |
| 171 |
fs_ends_with( $subdomain, '.example' ) || |
| 172 |
fs_ends_with( $subdomain, '.invalid' ) || |
| 173 |
// GoDaddy test/dev. |
| 174 |
fs_ends_with( $subdomain, '.myftpupload.com' ) || |
| 175 |
// ngrok tunneling. |
| 176 |
fs_ends_with( $subdomain, '.ngrok.io' ) || |
| 177 |
// wpsandbox. |
| 178 |
fs_ends_with( $subdomain, '.wpsandbox.pro' ) || |
| 179 |
// SiteGround staging. |
| 180 |
fs_starts_with( $subdomain, 'staging' ) || |
| 181 |
// WPEngine staging. |
| 182 |
fs_ends_with( $subdomain, '.staging.wpengine.com' ) || |
| 183 |
fs_ends_with( $subdomain, '.dev.wpengine.com' ) || |
| 184 |
fs_ends_with( $subdomain, '.wpengine.com' ) || |
| 185 |
// Pantheon |
| 186 |
( fs_ends_with( $subdomain, 'pantheonsite.io' ) && |
| 187 |
( fs_starts_with( $subdomain, 'test-' ) || fs_starts_with( $subdomain, 'dev-' ) ) ) || |
| 188 |
// Cloudways |
| 189 |
fs_ends_with( $subdomain, '.cloudwaysapps.com' ) || |
| 190 |
// Kinsta |
| 191 |
( |
| 192 |
( fs_starts_with( $subdomain, 'staging-' ) || fs_starts_with( $subdomain, 'env-' ) ) && |
| 193 |
( fs_ends_with( $subdomain, '.kinsta.com' ) || fs_ends_with( $subdomain, '.kinsta.cloud' ) ) |
| 194 |
) || |
| 195 |
// DesktopServer |
| 196 |
fs_ends_with( $subdomain, '.dev.cc' ) || |
| 197 |
// Pressable |
| 198 |
fs_ends_with( $subdomain, '.mystagingwebsite.com' ) || |
| 199 |
// WPMU DEV |
| 200 |
( fs_ends_with( $subdomain, '.tempurl.host' ) || fs_ends_with( $subdomain, '.wpmudev.host' ) ) || |
| 201 |
// Vendasta |
| 202 |
( fs_ends_with( $subdomain, '.websitepro-staging.com' ) || fs_ends_with( $subdomain, '.websitepro.hosting' ) ) || |
| 203 |
// InstaWP |
| 204 |
fs_ends_with( $subdomain, '.instawp.xyz' ) |
| 205 |
); |
| 206 |
} |
| 207 |
|
| 208 |
function is_localhost() { |
| 209 |
return ( WP_FS__IS_LOCALHOST_FOR_SERVER || self::is_localhost_by_address( $this->url ) ); |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Check if site in trial. |
| 214 |
* |
| 215 |
* @author Vova Feldman (@svovaf) |
| 216 |
* @since 1.0.9 |
| 217 |
* |
| 218 |
* @return bool |
| 219 |
*/ |
| 220 |
function is_trial() { |
| 221 |
return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME ); |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Check if user already utilized the trial with the current install. |
| 226 |
* |
| 227 |
* @author Vova Feldman (@svovaf) |
| 228 |
* @since 1.0.9 |
| 229 |
* |
| 230 |
* @return bool |
| 231 |
*/ |
| 232 |
function is_trial_utilized() { |
| 233 |
return is_numeric( $this->trial_plan_id ); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* @author Edgar Melkonyan |
| 238 |
* |
| 239 |
* @return bool |
| 240 |
*/ |
| 241 |
function is_beta() { |
| 242 |
return ( isset( $this->is_beta ) && true === $this->is_beta ); |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* @author Leo Fajardo (@leorw) |
| 247 |
* @since 2.5.1 |
| 248 |
* |
| 249 |
* @param string $site_url |
| 250 |
* |
| 251 |
* @return bool |
| 252 |
*/ |
| 253 |
function is_clone( $site_url ) { |
| 254 |
$clone_install_url = trailingslashit( fs_strip_url_protocol( $this->url ) ); |
| 255 |
|
| 256 |
return ( $clone_install_url !== $site_url ); |
| 257 |
} |
| 258 |
} |