-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAST_InstallIndicator.php
More file actions
74 lines (74 loc) · 2.31 KB
/
Copy pathAST_InstallIndicator.php
File metadata and controls
74 lines (74 loc) · 2.31 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
<?php
include_once('AST_OptionsManager.php');
class AST_InstallIndicator extends AST_OptionsManager
{
const optionInstalled = '_installed';
const optionVersion = '_version';
public function isInstalled()
{
return $this->getOption(self::optionInstalled) == true;
}
protected function markAsInstalled()
{
return $this->updateOption(self::optionInstalled, true);
}
protected function markAsUnInstalled()
{
return $this->deleteOption(self::optionInstalled);
}
protected function getVersionSaved()
{
return $this->getOption(self::optionVersion);
}
protected function setVersionSaved($version)
{
return $this->updateOption(self::optionVersion, $version);
}
protected function getMainPluginFileName()
{
return basename(dirname(__FILE__)) . 'php';
}
public function getPluginHeaderValue($key)
{
$data = file_get_contents($this->getPluginDir() . DIRECTORY_SEPARATOR . $this->getMainPluginFileName());
$match = array();
preg_match('/' . $key . ':\s*(\S+)/', $data, $match);
if (count($match) >= 1)
{
return $match[1];
}
return null;
}
protected function getPluginDir()
{
return dirname(__FILE__);
}
public function getVersion()
{
return $this->getPluginHeaderValue('Version');
}
public function isInstalledCodeAnUpgrade()
{
return $this->isSavedVersionLessThan($this->getVersion());
}
public function isSavedVersionLessThan($aVersion)
{
return $this->isVersionLessThan($this->getVersionSaved(), $aVersion);
}
public function isSavedVersionLessThanEqual($aVersion)
{
return $this->isVersionLessThanEqual($this->getVersionSaved(), $aVersion);
}
public function isVersionLessThanEqual($version1, $version2)
{
return (version_compare($version1, $version2) <= 0);
}
public function isVersionLessThan($version1, $version2)
{
return (version_compare($version1, $version2) < 0);
}
protected function saveInstalledVersion()
{
$this->setVersionSaved($this->getVersion());
}
}