| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 2.1.14 |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2024 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Helpers; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class Plugin |
| 20 |
{ |
| 21 |
public static function getLatestVersion() |
| 22 |
{ |
| 23 |
$url = FPF_GET_LICENSE_VERSION_URL . 'firebox'; |
| 24 |
|
| 25 |
$response = wp_remote_get($url); |
| 26 |
|
| 27 |
if (!is_array($response)) |
| 28 |
{ |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
$response_decoded = null; |
| 33 |
|
| 34 |
try |
| 35 |
{ |
| 36 |
$response_decoded = json_decode($response['body']); |
| 37 |
} |
| 38 |
catch (Exception $ex) |
| 39 |
{ |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
if (!isset($response_decoded->version)) |
| 44 |
{ |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
return $response_decoded->version; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Checks whether the plugin is outdated. |
| 53 |
* |
| 54 |
* @param int $days_old |
| 55 |
* |
| 56 |
* @return bool |
| 57 |
*/ |
| 58 |
public static function isOutdated($days_old = 120) |
| 59 |
{ |
| 60 |
if (!defined('FBOX_RELEASE_DATE')) |
| 61 |
{ |
| 62 |
return false; |
| 63 |
} |
| 64 |
|
| 65 |
if (!$then = strtotime(FBOX_RELEASE_DATE)) |
| 66 |
{ |
| 67 |
return false; |
| 68 |
} |
| 69 |
|
| 70 |
$days_old = (int) $days_old; |
| 71 |
$now = time(); |
| 72 |
$diff = $now - $then; |
| 73 |
$days_diff = round($diff / (60 * 60 * 24)); |
| 74 |
|
| 75 |
if ($days_diff <= $days_old) |
| 76 |
{ |
| 77 |
return false; |
| 78 |
} |
| 79 |
|
| 80 |
return true; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Returns the installation date. |
| 85 |
* |
| 86 |
* @return string |
| 87 |
*/ |
| 88 |
public static function getInstallationDate() |
| 89 |
{ |
| 90 |
$path = self::getExtensionsDataFilePath(); |
| 91 |
|
| 92 |
// If file does not exist, abort |
| 93 |
if (!file_exists($path)) |
| 94 |
{ |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
// If file exists, retrieve its contents |
| 99 |
$content = file_get_contents($path); |
| 100 |
|
| 101 |
// Decode it |
| 102 |
if (!$content = json_decode($content, true)) |
| 103 |
{ |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
// Ensure install date exists |
| 108 |
if (!isset($content['install_date'])) |
| 109 |
{ |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
return $content['install_date']; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Sets the installation date. |
| 118 |
* |
| 119 |
* @param string $install_date |
| 120 |
* |
| 121 |
* @return bool |
| 122 |
*/ |
| 123 |
public static function setInstallationDate($install_date = null) |
| 124 |
{ |
| 125 |
$path = self::getExtensionsDataFilePath(); |
| 126 |
|
| 127 |
// If file does not exist, abort |
| 128 |
if (!file_exists($path)) |
| 129 |
{ |
| 130 |
file_put_contents($path, json_encode( |
| 131 |
[ |
| 132 |
'install_date' => $install_date |
| 133 |
] |
| 134 |
)); |
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
// If file exists, retrieve its contents |
| 139 |
$content = file_get_contents($path); |
| 140 |
|
| 141 |
// Decode it |
| 142 |
$content = json_decode($content, true); |
| 143 |
|
| 144 |
if (isset($content['install_date'])) |
| 145 |
{ |
| 146 |
return false; |
| 147 |
} |
| 148 |
|
| 149 |
$content['install_date'] = $install_date; |
| 150 |
|
| 151 |
file_put_contents($path, json_encode($content)); |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* The file path that stores all extensions data. |
| 156 |
* |
| 157 |
* @return string |
| 158 |
*/ |
| 159 |
public static function getExtensionsDataFilePath() |
| 160 |
{ |
| 161 |
return \FPFramework\Helpers\WPHelper::getPluginUploadsDirectory('firebox') . '/data.json'; |
| 162 |
} |
| 163 |
} |