This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlovidy_InstallIndicator.php
72 lines (58 loc) · 2.27 KB
/
Flovidy_InstallIndicator.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
<?php
include_once('Flovidy_OptionsManager.php');
class Flovidy_InstallIndicator extends Flovidy_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) {
// Read the string from the comment header of the main plugin file
$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());
}
}