/var/www/hkosl.com/aga/wp-content/plugins/smart-slider-3/library/smartslider/models/Update.php


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
106
107
108
109
110
111
<?php

class N2SmartsliderUpdateModel {

    private static 
$version false;
    private static 
$lastCheck false;

    private 
$storage;

    public function 
__construct() {
        
$this->storage N2Base::getApplication('smartslider')->storage;
    }

    public static function 
getInstance() {
        static 
$ins;
        if (!
$ins) {
            
$ins = new N2SmartsliderUpdateModel();
        }

        return 
$ins;
    }

    public function 
getVersion() {
        if (
self::$version === false) {
            
self::$version $this->storage->get('update''version');
        }

        return 
self::$version;
    }

    public function 
setVersion($version) {
        
$this->storage->set('update''version'$version);
        
self::$version $version;

        
$this->setLastCheck(time());
    }

    public function 
getLastCheck() {
        if (
self::$lastCheck === false) {
            
self::$lastCheck $this->storage->get('update''lastcheck');
        }

        return 
self::$lastCheck;
    }

    public function 
setLastCheck($lastCheck) {
        
self::$lastCheck $lastCheck;
        
$this->storage->set('update''lastcheck'$lastCheck);
    }

    public function 
hasUpdate() {
        
$this->autoCheck();
        if (
version_compare(N2SS3::$version$this->getVersion()) == -1) {
            return 
true;
        }

        return 
false;
    }

    private function 
autoCheck() {
        if (
intval(N2SmartSliderSettings::get('autoupdatecheck'1))) {
            
$time $this->getLastCheck();
            if (!
$time || strtotime("+1 week"$time) < time()) {
                
$this->check();
            }
        }
    }

    public function 
check() {

        
$posts    = array(
            
'action' => 'version'
        
);
        
$response N2SS3::api($posts);
        if (
$response['status'] == 'OK') {
            
$this->setVersion($response['data']['latestVersion']);
        }

        return 
$response['status'];
    }

    public function 
lastCheck() {
        
$time $this->getLastCheck();
        if (empty(
$time)) {
            return 
n2_('never');
        }

        return 
date("Y-m-d H:i"$time);
    }

    public function 
update() {

        
$posts = array(
            
'action' => 'update'
        
);

        
$response N2SS3::api($posts);
        if (
is_string($response)) {
            
$updateStatus N2Platform::updateFromZip($responseN2SS3::getUpdateInfo());
            if (
$updateStatus === true) {
                return 
'OK';
            } else if (
$updateStatus != false) {
                return 
$updateStatus;
            }

            return 
'UPDATE_ERROR';
        }

        return 
$response['status'];
    }
}