PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Wordpress / Update.php
backup / src / JetBackup / Wordpress Last commit date
.htaccess 1 year ago Abilities.php 1 day ago Blog.php 1 year ago Helper.php 5 months ago Init.php 5 months ago Installer.php 7 months ago MySQL.php 1 year ago UI.php 4 months ago Update.php 1 year ago Wordpress.php 1 day ago index.html 1 year ago web.config 1 year ago
Update.php
120 lines
1 <?php
2
3 namespace JetBackup\Wordpress;
4
5 use JetBackup\Exception\HttpRequestException;
6 use JetBackup\Factory;
7 use JetBackup\JetBackup;
8 use JetBackup\Settings\Updates;
9 use JetBackup\Web\JetHttp;
10 use stdClass;
11
12 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
13
14 class Update {
15 const REPO_URL = 'https://repo.jetlicense.com';
16 const REPO_EXTENSIONS_URL = self::REPO_URL . '/extensions/%s';
17 const REPO_EXTENSIONS_DATA_URL = self::REPO_EXTENSIONS_URL . '/repodata_v2';
18 const TRANSIENT = 'jetbackup_plugin_updates';
19
20 const WP_ASSETS_URL = 'https://ps.w.org/' . JetBackup::PLUGIN_NAME . '/assets';
21
22 private function __construct() {}
23
24 /**
25 * @return array|null
26 */
27 private static function _fetchRepoData():?array {
28
29 $tier = Factory::getSettingsUpdates()->getUpdateTier();
30
31 try {
32 $response = JetHttp::request()
33 ->setReturnTransfer()
34 ->setSSLVerify(0, 0)
35 ->exec(sprintf(self::REPO_EXTENSIONS_DATA_URL, $tier));
36
37 if($response->getHeaders()->getCode() != 200) return null;
38 $data = json_decode($response->getBody());
39 return (array) ($data !== false ? $data : []);
40 } catch(HttpRequestException $e) {
41 return null;
42 }
43 }
44
45 /**
46 * NOTE: WordPress may pass a boolean (false) if the update_plugins transient is not set or has expired.
47 *
48 * @param object|null $transient
49 *
50 * @return object
51 */
52 public static function check($transient):object {
53
54 if (!$transient || !is_object($transient)) {
55 $transient = new stdClass();
56 $transient->response = [];
57 $transient->no_update = [];
58 }
59
60 $tier = Factory::getSettingsUpdates()->getUpdateTier();
61 if($tier == Updates::TIER_RELEASE) return $transient;
62
63 $repo_data = Wordpress::getTransient(self::TRANSIENT);
64
65 if(!$repo_data || !isset($repo_data->tier) || $repo_data->tier != $tier || !isset($repo_data->last_check) || $repo_data->last_check < (time() - 86400)) {
66 if(!($repo_data = self::_fetchRepoData())) return $transient;
67
68 if(is_array($repo_data)) {
69
70 $newest_package = new stdClass();
71 foreach($repo_data as $package) {
72 if(!isset($newest_package->version) || (isset($package->version) && version_compare($newest_package->version, $package->version, '<'))) $newest_package = $package;
73 }
74
75 $repo_data = $newest_package;
76 }
77
78 // Check if we found any version in our repo
79 if(!isset($repo_data->version)) return $transient;
80
81 $repo_data->tier = $tier;
82 $repo_data->last_check = time();
83 Wordpress::setTransient(self::TRANSIENT, $repo_data);
84 }
85
86 $current = new stdClass();
87 if(isset($transient->response[JetBackup::PLUGIN_SLUG])) $current = $transient->response[JetBackup::PLUGIN_SLUG];
88 if(isset($transient->no_update[JetBackup::PLUGIN_SLUG])) $current = $transient->no_update[JetBackup::PLUGIN_SLUG];
89
90 $object = (object) [
91 'id' => 'w.org/plugins/' . JetBackup::PLUGIN_NAME,
92 'slug' => JetBackup::PLUGIN_NAME,
93 'plugin' => JetBackup::PLUGIN_SLUG,
94 'new_version' => $repo_data->version,
95 'url' => $current->url ?? 'https://wordpress.org/plugins/' . JetBackup::PLUGIN_NAME . '/',
96 'icons' => $current->icons ?? [
97 '1x' => self::WP_ASSETS_URL . '/icon-128x128.png?rev=3113473',
98 ],
99 'banners' => $current->banners ?? [
100 '2x' => self::WP_ASSETS_URL . '/banner-1544x500.png?rev=2858586',
101 '1x' => self::WP_ASSETS_URL . '/banner-772x250.png?rev=2858590',
102 ],
103 'banners_rtl' => $current->banners_rtl ?? [],
104 'package' => sprintf(self::REPO_EXTENSIONS_URL, $tier) . '/' . $repo_data->package,
105 'requires' => $repo_data->min_version,
106 'tested' => $repo_data->tested_on ?? JetBackup::TESTED_ON_WP_VERSION,
107 'requires_php' => $repo_data->requires_php ?? JetBackup::MINIMUM_PHP_VERSION
108 ];
109
110 if(version_compare($repo_data->version, JetBackup::VERSION, '>')) {
111 $transient->response[JetBackup::PLUGIN_SLUG] = $object;
112 if(isset($transient->no_update[JetBackup::PLUGIN_SLUG])) unset($transient->no_update[JetBackup::PLUGIN_SLUG]);
113 } else {
114 $transient->no_update[JetBackup::PLUGIN_SLUG] = $object;
115 if(isset($transient->response[JetBackup::PLUGIN_SLUG])) unset($transient->response[JetBackup::PLUGIN_SLUG]);
116 }
117
118 return $transient;
119 }
120 }