* @link https://www.fireplugins.com * @copyright Copyright © 2024 FirePlugins All Rights Reserved * @license GNU GPLv3 or later */ namespace FireBox\Core\Helpers; if (!defined('ABSPATH')) { exit; // Exit if accessed directly. } class Plugin { public static function getLatestVersion() { $url = FPF_GET_LICENSE_VERSION_URL . 'firebox'; $response = wp_remote_get($url); if (!is_array($response)) { return; } $response_decoded = null; try { $response_decoded = json_decode($response['body']); } catch (Exception $ex) { return; } if (!isset($response_decoded->version)) { return; } return $response_decoded->version; } /** * Checks whether the plugin is outdated. * * @param int $days_old * * @return bool */ public static function isOutdated($days_old = 120) { if (!defined('FBOX_RELEASE_DATE')) { return false; } if (!$then = strtotime(FBOX_RELEASE_DATE)) { return false; } $days_old = (int) $days_old; $now = time(); $diff = $now - $then; $days_diff = round($diff / (60 * 60 * 24)); if ($days_diff <= $days_old) { return false; } return true; } /** * Returns the installation date. * * @return string */ public static function getInstallationDate() { $path = self::getExtensionsDataFilePath(); // If file does not exist, abort if (!file_exists($path)) { return; } // If file exists, retrieve its contents $content = file_get_contents($path); // Decode it if (!$content = json_decode($content, true)) { return; } // Ensure install date exists if (!isset($content['install_date'])) { return; } return $content['install_date']; } /** * Sets the installation date. * * @param string $install_date * * @return bool */ public static function setInstallationDate($install_date = null) { $path = self::getExtensionsDataFilePath(); // If file does not exist, abort if (!file_exists($path)) { file_put_contents($path, json_encode( [ 'install_date' => $install_date ] )); return; } // If file exists, retrieve its contents $content = file_get_contents($path); // Decode it $content = json_decode($content, true); if (isset($content['install_date'])) { return false; } $content['install_date'] = $install_date; file_put_contents($path, json_encode($content)); } /** * The file path that stores all extensions data. * * @return string */ public static function getExtensionsDataFilePath() { return \FPFramework\Helpers\WPHelper::getPluginUploadsDirectory('firebox') . '/data.json'; } }