diff --git a/gitea-updater.php b/gitea-updater.php index 1ef4d33..5d67831 100644 --- a/gitea-updater.php +++ b/gitea-updater.php @@ -30,7 +30,7 @@ class Gitea_Updater } private $cache = 86400; // 1 day in seconds - private $site = ''; + private $id = ''; public $plugins = array(); public $themes = array(); @@ -38,7 +38,7 @@ class Gitea_Updater function __construct() { - $this->site = str_replace(array('http://', 'https://'), '', get_site_url()); + $this->id = str_replace(array('http://', 'https://'), '', get_site_url()); add_action('plugins_loaded', array($this, 'plugins_loaded')); @@ -77,23 +77,33 @@ class Gitea_Updater $this->get_themes(); } + function is_force_check() + { + return isset($_GET['force-check']); + } + + function is_iwp() + { + foreach ($_POST as $key => $value) { + if (substr($key, 0, 5) == '_IWP_') { + return true; + } + } + return false; + } + function update($type) { // disable cache in case of a force-check from admin site - if (isset($_GET['force-check'])) { + if ($this->is_force_check()) { $this->cache = 30; } // small hack for multiple checks when asked throw IWP - foreach ($_POST as $key => $value) { - if (substr($key, 0, 5) == '_IWP_') { - $this->cache = 300; - } + if ($this->is_iwp()) { + $this->cache = 300; } $last_update = get_option('gitea_' . $type . '_updated'); - - echo $type . ' ' . $this->cache . ' ---- ' . ($last_update + $this->cache) < time() . "\n\n"; - return ($last_update + $this->cache) < time(); } @@ -153,7 +163,9 @@ class Gitea_Updater } update_option('gitea_plugins', $this->plugins); - update_option('gitea_plugins_updated', time()); + if ($this->update('plugins')) { + update_option('gitea_plugins_updated', time()); + } } @@ -213,7 +225,9 @@ class Gitea_Updater } update_option('gitea_themes', $this->themes); - update_option('gitea_themes_updated', time()); + if ($this->update('themes')) { + update_option('gitea_themes_updated', time()); + } } @@ -247,7 +261,13 @@ class Gitea_Updater if (!$access_token) return false; } - return $host . 'api/v1/repos/' . $repo . $args . '?access_token=' . $access_token . '&wp=' . urlencode($this->site); + $add = '&id=' . $this->id; + if ($this->is_iwp()) + $add .= '&from=iwp'; + elseif ($this->is_force_check()) + $add .= '&from=force-check'; + + return $host . 'api/v1/repos/' . $repo . $args . '?access_token=' . $access_token . $add; } function get_file($url)