ModelLicense.php
2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Nextend\SmartSlider3\Application\Model;
use Nextend\Framework\Model\StorageSectionManager;
use Nextend\Framework\Notification\Notification;
use Nextend\Framework\Pattern\SingletonTrait;
use Nextend\SmartSlider3\SmartSlider3Info;
/**
* Class ModelLicense
*
* @package Nextend\SmartSlider3\Application\Model
*
*/
class ModelLicense {
use SingletonTrait;
private $key;
public function __construct() {
if (defined('SMART_SLIDER_LICENSE')) {
$this->key = SMART_SLIDER_LICENSE;
} else {
$this->key = StorageSectionManager::getStorage('smartslider')
->get('license', 'key');
}
}
public function hasKey() {
return !empty($this->key);
}
public function maybeActiveLazy() {
$lastActive = StorageSectionManager::getStorage('smartslider')
->get('license', 'isActive');
return $lastActive > 0;
}
public function maybeActive() {
$lastActive = StorageSectionManager::getStorage('smartslider')
->get('license', 'isActive');
if ($lastActive && $lastActive > strtotime("-1 week")) {
return true;
}
return false;
}
public function getKey() {
return $this->key;
}
public function setKey($licenseKey) {
StorageSectionManager::getStorage('smartslider')
->set('license', 'key', $licenseKey);
StorageSectionManager::getStorage('smartslider')
->set('license', 'isActive', time());
if ($licenseKey == '') {
StorageSectionManager::getStorage('smartslider')
->set('license', 'isActive', '0');
}
$this->key = $licenseKey;
}
public function checkKey($license, $action = 'licensecheck') {
return 0;
}
public function isActive($cacheAccepted = true) {
if ($cacheAccepted && $this->maybeActive()) {
return 'OK';
}
$status = $this->checkKey($this->key);
if ($this->hasKey() && $status == 'OK') {
StorageSectionManager::getStorage('smartslider')
->set('license', 'isActive', time());
return $status;
}
StorageSectionManager::getStorage('smartslider')
->set('license', 'isActive', '0');
return $status;
}
public function deAuthorize() {
if ($this->hasKey()) {
$this->setKey('');
Notification::notice(n2_('Smart Slider 3 deactivated on this site!'));
return 'OK';
}
return false;
}
}