| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * A class to easily manage licenses for Polylang Pro and addons |
| 8 | 5 | * |
| @@ -8,62 +5,10 @@ | ||
| 8 | 5 | * |
| 9 | 6 | * @since 1.9 |
| 10 | 7 | */ |
| 11 | 8 | class PLL_License { |
| 12 | - /** | |
| 13 | - * Sanitized plugin name. | |
| 14 | - * | |
| 15 | - * @var string | |
| 16 | - */ | |
| 17 | - public $id; | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * Plugin name. | |
| 21 | - * | |
| 22 | - * @var string | |
| 23 | - */ | |
| 24 | - public $name; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * License key. | |
| 28 | - * | |
| 29 | - * @var string | |
| 30 | - */ | |
| 31 | - public $license_key; | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * License data, obtained from the API request. | |
| 35 | - * | |
| 36 | - * @var stdClass | |
| 37 | - */ | |
| 38 | - public $license_data; | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * Main plugin file. | |
| 42 | - * | |
| 43 | - * @var string | |
| 44 | - */ | |
| 45 | - private $file; | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * Current plugin version. | |
| 49 | - * | |
| 50 | - * @var string | |
| 51 | - */ | |
| 52 | - private $version; | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * Plugin author. | |
| 56 | - * | |
| 57 | - * @var string | |
| 58 | - */ | |
| 59 | - private $author; | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * API url. | |
| 63 | - * | |
| 64 | - * @var string. | |
| 65 | - */ | |
| 9 | + public $id, $name, $license_key, $license_data; | |
| 10 | + private $file, $version, $author; | |
| 66 | 11 | private $api_url = 'https://polylang.pro'; |
| 67 | 12 | |
| 68 | 13 | /** |
| 69 | 14 | * Constructor |
| @@ -108,10 +53,8 @@ | ||
| 108 | 53 | /** |
| 109 | 54 | * Auto updater |
| 110 | 55 | * |
| 111 | 56 | * @since 1.9 |
| 112 | - * | |
| 113 | - * @return void | |
| 114 | 57 | */ |
| 115 | 58 | public function auto_updater() { |
| 116 | 59 | $args = array( |
| 117 | 60 | 'version' => $this->version, |
| @@ -185,20 +128,13 @@ | ||
| 185 | 128 | * |
| 186 | 129 | * @since 1.9 |
| 187 | 130 | * |
| 188 | 131 | * @param string $request check_license | activate_license | deactivate_license |
| 189 | - * @return void | |
| 190 | 132 | */ |
| 191 | 133 | private function api_request( $request ) { |
| 192 | 134 | $licenses = get_option( 'polylang_licenses' ); |
| 135 | + unset( $licenses[ $this->id ], $this->license_data ); | |
| 193 | 136 | |
| 194 | - if ( is_array( $licenses ) ) { | |
| 195 | - unset( $licenses[ $this->id ] ); | |
| 196 | - } else { | |
| 197 | - $licenses = array(); | |
| 198 | - } | |
| 199 | - unset( $this->license_data ); | |
| 200 | - | |
| 201 | 137 | if ( ! empty( $this->license_key ) ) { |
| 202 | 138 | // Data to send in our API request |
| 203 | 139 | $api_params = array( |
| 204 | 140 | 'edd_action' => $request, |
| @@ -210,9 +146,9 @@ | ||
| 210 | 146 | // Call the API |
| 211 | 147 | $response = wp_remote_post( |
| 212 | 148 | $this->api_url, |
| 213 | 149 | array( |
| 214 | - 'timeout' => 3, | |
| 150 | + 'timeout' => 15, | |
| 215 | 151 | 'sslverify' => false, |
| 216 | 152 | 'body' => $api_params, |
| 217 | 153 | ) |
| 218 | 154 | ); |
| @@ -231,125 +167,6 @@ | ||
| 231 | 167 | } |
| 232 | 168 | } |
| 233 | 169 | |
| 234 | 170 | update_option( 'polylang_licenses', $licenses ); // FIXME called multiple times when saving all licenses |
| 235 | - } | |
| 236 | - | |
| 237 | - /** | |
| 238 | - * Get the html form field in a table row (one per license key) for display | |
| 239 | - * | |
| 240 | - * @since 2.7 | |
| 241 | - * | |
| 242 | - * @return string | |
| 243 | - */ | |
| 244 | - public function get_form_field() { | |
| 245 | - if ( ! empty( $this->license_data ) ) { | |
| 246 | - $license = $this->license_data; | |
| 247 | - } | |
| 248 | - | |
| 249 | - $class = 'license-null'; | |
| 250 | - $message = ''; | |
| 251 | - | |
| 252 | - $out = sprintf( | |
| 253 | - '<td><label for="pll-licenses[%1$s]">%2$s</label></td>' . | |
| 254 | - '<td><input name="licenses[%1$s]" id="pll-licenses[%1$s]" type="password" value="%3$s" class="regular-text code" />', | |
| 255 | - esc_attr( $this->id ), | |
| 256 | - esc_attr( $this->name ), | |
| 257 | - esc_html( $this->license_key ) | |
| 258 | - ); | |
| 259 | - | |
| 260 | - if ( ! empty( $license ) && is_object( $license ) ) { | |
| 261 | - $now = time(); | |
| 262 | - $expiration = isset( $license->expires ) ? strtotime( $license->expires ) : false; | |
| 263 | - | |
| 264 | - // Special case: the license expired after the last check | |
| 265 | - if ( $license->success && $expiration && $expiration < $now ) { | |
| 266 | - $license->success = false; | |
| 267 | - $license->error = 'expired'; | |
| 268 | - } | |
| 269 | - | |
| 270 | - if ( false === $license->success ) { | |
| 271 | - $class = 'notice-error notice-alt'; | |
| 272 | - | |
| 273 | - switch ( $license->error ) { | |
| 274 | - case 'expired': | |
| 275 | - $message = sprintf( | |
| 276 | - /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ | |
| 277 | - esc_html__( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ), | |
| 278 | - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ), | |
| 279 | - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ), | |
| 280 | - '</a>' | |
| 281 | - ); | |
| 282 | - break; | |
| 283 | - | |
| 284 | - case 'disabled': | |
| 285 | - case 'revoked': | |
| 286 | - $message = esc_html__( 'Your license key has been disabled.', 'polylang' ); | |
| 287 | - break; | |
| 288 | - | |
| 289 | - case 'missing': | |
| 290 | - $message = sprintf( | |
| 291 | - /* translators: %1$s is link start tag, %2$s is link end tag. */ | |
| 292 | - esc_html__( 'Invalid license. Please %1$svisit your account page%2$s and verify it.', 'polylang' ), | |
| 293 | - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ), | |
| 294 | - '</a>' | |
| 295 | - ); | |
| 296 | - break; | |
| 297 | - | |
| 298 | - case 'invalid': | |
| 299 | - case 'site_inactive': | |
| 300 | - $message = sprintf( | |
| 301 | - /* translators: %1$s is a product name, %2$s is link start tag, %3$s is link end tag. */ | |
| 302 | - esc_html__( 'Your %1$s license key is not active for this URL. Please %2$svisit your account page%3$s to manage your license key URLs.', 'polylang' ), | |
| 303 | - esc_html( $this->name ), | |
| 304 | - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ), | |
| 305 | - '</a>' | |
| 306 | - ); | |
| 307 | - break; | |
| 308 | - | |
| 309 | - case 'item_name_mismatch': | |
| 310 | - /* translators: %s is a product name */ | |
| 311 | - $message = sprintf( esc_html__( 'This is not a %s license key.', 'polylang' ), esc_html( $this->name ) ); | |
| 312 | - break; | |
| 313 | - | |
| 314 | - case 'no_activations_left': | |
| 315 | - $message = sprintf( | |
| 316 | - /* translators: %1$s is link start tag, %2$s is link end tag */ | |
| 317 | - esc_html__( 'Your license key has reached its activation limit. %1$sView possible upgrades%2$s now.', 'polylang' ), | |
| 318 | - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ), | |
| 319 | - '</a>' | |
| 320 | - ); | |
| 321 | - break; | |
| 322 | - } | |
| 323 | - } else { | |
| 324 | - $class = 'license-valid'; | |
| 325 | - | |
| 326 | - $out .= sprintf( '<button id="deactivate_%s" type="button" class="button button-secondary pll-deactivate-license">%s</button>', esc_attr( $this->id ), esc_html__( 'Deactivate', 'polylang' ) ); | |
| 327 | - | |
| 328 | - if ( 'lifetime' === $license->expires ) { | |
| 329 | - $message = esc_html__( 'The license key never expires.', 'polylang' ); | |
| 330 | - } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) { | |
| 331 | - $class = 'notice-warning notice-alt'; | |
| 332 | - $message = sprintf( | |
| 333 | - /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ | |
| 334 | - esc_html__( 'Your license key will expire soon! Precisely, it will expire on %1$s. %2$sRenew your license key today!%3$s.', 'polylang' ), | |
| 335 | - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ), | |
| 336 | - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ), | |
| 337 | - '</a>' | |
| 338 | - ); | |
| 339 | - } else { | |
| 340 | - $message = sprintf( | |
| 341 | - /* translators: %s is a date */ | |
| 342 | - esc_html__( 'Your license key expires on %s.', 'polylang' ), | |
| 343 | - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ) | |
| 344 | - ); | |
| 345 | - } | |
| 346 | - } | |
| 347 | - } | |
| 348 | - | |
| 349 | - if ( ! empty( $message ) ) { | |
| 350 | - $out .= '<p>' . $message . '</p>'; | |
| 351 | - } | |
| 352 | - | |
| 353 | - return sprintf( '<tr id="pll-license-%s" class="%s">%s</tr>', esc_attr( $this->id ), $class, $out ); | |
| 354 | 171 | } |
| 355 | 172 | } |