version
This commit is contained in:
parent
54177285b3
commit
782e68676e
1 changed files with 33 additions and 13 deletions
|
|
@ -30,7 +30,7 @@ class Gitea_Updater
|
||||||
}
|
}
|
||||||
|
|
||||||
private $cache = 86400; // 1 day in seconds
|
private $cache = 86400; // 1 day in seconds
|
||||||
private $site = '';
|
private $id = '';
|
||||||
|
|
||||||
public $plugins = array();
|
public $plugins = array();
|
||||||
public $themes = array();
|
public $themes = array();
|
||||||
|
|
@ -38,7 +38,7 @@ class Gitea_Updater
|
||||||
function __construct()
|
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'));
|
add_action('plugins_loaded', array($this, 'plugins_loaded'));
|
||||||
|
|
||||||
|
|
@ -77,23 +77,33 @@ class Gitea_Updater
|
||||||
$this->get_themes();
|
$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)
|
function update($type)
|
||||||
{
|
{
|
||||||
// disable cache in case of a force-check from admin site
|
// disable cache in case of a force-check from admin site
|
||||||
if (isset($_GET['force-check'])) {
|
if ($this->is_force_check()) {
|
||||||
$this->cache = 30;
|
$this->cache = 30;
|
||||||
}
|
}
|
||||||
// small hack for multiple checks when asked throw IWP
|
// small hack for multiple checks when asked throw IWP
|
||||||
foreach ($_POST as $key => $value) {
|
if ($this->is_iwp()) {
|
||||||
if (substr($key, 0, 5) == '_IWP_') {
|
|
||||||
$this->cache = 300;
|
$this->cache = 300;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$last_update = get_option('gitea_' . $type . '_updated');
|
$last_update = get_option('gitea_' . $type . '_updated');
|
||||||
|
|
||||||
|
|
||||||
echo $type . ' ' . $this->cache . ' ---- ' . ($last_update + $this->cache) < time() . "\n\n";
|
|
||||||
|
|
||||||
return ($last_update + $this->cache) < time();
|
return ($last_update + $this->cache) < time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,7 +163,9 @@ class Gitea_Updater
|
||||||
}
|
}
|
||||||
|
|
||||||
update_option('gitea_plugins', $this->plugins);
|
update_option('gitea_plugins', $this->plugins);
|
||||||
|
if ($this->update('plugins')) {
|
||||||
update_option('gitea_plugins_updated', time());
|
update_option('gitea_plugins_updated', time());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,7 +225,9 @@ class Gitea_Updater
|
||||||
}
|
}
|
||||||
|
|
||||||
update_option('gitea_themes', $this->themes);
|
update_option('gitea_themes', $this->themes);
|
||||||
|
if ($this->update('themes')) {
|
||||||
update_option('gitea_themes_updated', time());
|
update_option('gitea_themes_updated', time());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,7 +261,13 @@ class Gitea_Updater
|
||||||
if (!$access_token) return false;
|
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)
|
function get_file($url)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue