PluginProbe
Listdom: AI-powered Business Directory with Classifieds Ads Listings / trunk
Listdom: AI-powered Business Directory with Classifieds Ads Listings vtrunk
6.0.0 5.9.0 5.8.1 5.8.0 5.7.0 5.6.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.2.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.8.0 1.9.0 All 75 releases
listdom / app / includes / plugin / licensing.php

licensing.php in Listdom: AI-powered Business Directory with Classifieds Ads Listings trunk, at app/includes/plugin/licensing.php

118 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Webilia\WP\Plugin\Licensing;
4
5 class LSD_Plugin_Licensing
6 {
7 /**
8 * @var Licensing
9 */
10 private $handler;
11
12 /**
13 * @var string
14 */
15 private $prefix;
16
17 /**
18 * Constructor
19 */
20 function __construct(array $args = [])
21 {
22 $this->prefix = $args['prefix'] ?? '';
23
24 $license_key_option = $args['license_key_option'] ?? $args['prefix'].'_purchase_code';
25 $activation_id_option = $args['activation_id_option'] ?? $args['prefix'].'_activation_id';
26 $basename = $args['basename'] ?? LSD_BASENAME;
27
28 // Webilia Licensing Server
29 $this->handler = new Licensing(
30 $license_key_option,
31 $activation_id_option,
32 $basename,
33 LSD_LICENSING_SERVER
34 );
35 }
36
37 /**
38 * @param bool $mask
39 * @return string
40 */
41 public function getLicenseKey(bool $mask = false): string
42 {
43 $license_key = (string) $this->handler->getLicenseKey();
44
45 if ($mask && trim($license_key))
46 {
47 $length = strlen($license_key);
48
49 if ($length > 8) $license_key = substr($license_key, 0, 4) . str_repeat('*', min(10, $length - 8)) . substr($license_key, -4);
50 else $license_key = str_repeat('*', $length);
51 }
52
53 return $license_key;
54 }
55
56 /**
57 * @return mixed
58 */
59 public function getActivationId()
60 {
61 return $this->handler->getActivationId();
62 }
63
64 /**
65 * @return string
66 */
67 public function getBasename(): string
68 {
69 return $this->handler->getBasename();
70 }
71
72 /**
73 * @return string
74 */
75 public function getPrefix(): string
76 {
77 return $this->prefix;
78 }
79
80 /**
81 * Check to See if License is Valid
82 *
83 * @return bool
84 */
85 public function isLicenseValid(): bool
86 {
87 return $this->handler->isValid();
88 }
89
90 /**
91 * @param string $license_key
92 * @return array
93 */
94 public function activate(string $license_key): array
95 {
96 [$status, $response] = $this->handler->activate($license_key);
97
98 if($response === Licensing::STATUS_VALID) $message = esc_html__('License key is valid and your website activated successfully!', 'listdom');
99 else if($response === Licensing::STATUS_INVALID) $message = esc_html__('The license key is either invalid, expired, not meant for this product, or has reached its activation limit. Please verify the key or obtain a new one if needed.', 'listdom');
100 else if($response === Licensing::ERROR_UNKNOWN) $message = esc_html__('Something went wrong!', 'listdom');
101 else if($response === Licensing::ERROR_CONNECTION) $message = esc_html__('It seems your website cannot connect to webilia.com server for validating the license key! Please consult with your host provider.', 'listdom');
102 else $message = $response;
103
104 return [$status, $message];
105 }
106
107 public function deactivate(string $license_key): array
108 {
109 $message = esc_html__("The license key has been successfully removed, and your website is now deactivated.", 'listdom');
110
111 // Webilia Key
112 $status = $this->handler->deactivate($license_key);
113 if(!$status) $message = esc_html__("License deactivation error. Retry later or contact support. We apologize for any inconvenience.", 'listdom');
114
115 return [$status, $message];
116 }
117 }
118