remote install
This commit is contained in:
parent
996b5bc50a
commit
4bd2231777
2 changed files with 238 additions and 91 deletions
|
|
@ -43,11 +43,6 @@ class Gitea_Updater {
|
|||
|
||||
Gitea_Options::getInstance();
|
||||
|
||||
add_action('admin_init', array($this, 'admin_init'));
|
||||
|
||||
// force check in core update, plugins and themes pages
|
||||
// add_action('admin_init', array($this, 'admin_pages_update_transient'));
|
||||
|
||||
// plugins checks
|
||||
add_filter('plugins_api', array($this, 'plugins_api'), 10, 3);
|
||||
add_filter('pre_set_site_transient_update_plugins', array($this, 'pre_set_site_transient_update_plugins'));
|
||||
|
|
@ -56,7 +51,7 @@ class Gitea_Updater {
|
|||
add_filter('pre_set_site_transient_update_themes', array($this, 'pre_set_site_transient_update_themes'));
|
||||
|
||||
// rename directories
|
||||
add_filter('upgrader_source_selection', array($this, 'upgrader_source_selection'), 10, 4);
|
||||
// add_filter('upgrader_source_selection', array($this, 'upgrader_source_selection'), 10, 4);
|
||||
|
||||
// extra plugins and themes headers (Gitea Host and Gitea URI)
|
||||
add_filter('extra_plugin_headers', array($this, 'extra_headers'));
|
||||
|
|
@ -64,15 +59,6 @@ class Gitea_Updater {
|
|||
|
||||
}
|
||||
|
||||
|
||||
function admin_init() {
|
||||
|
||||
// cached data
|
||||
// $this->plugins = (array)get_option('gitea_plugins');
|
||||
// $this->themes = (array)get_option('gitea_themes');
|
||||
|
||||
}
|
||||
|
||||
function get_gitea_all() {
|
||||
$this->get_gitea_plugins();
|
||||
$this->get_gitea_themes();
|
||||
|
|
@ -89,11 +75,12 @@ class Gitea_Updater {
|
|||
// this is a gitea plugin
|
||||
|
||||
$slug = trim(dirname($plugin_slug), '/');
|
||||
$file = basename($plugin_slug);
|
||||
$host = $this->get_gitea_host($plugin['Gitea Host']);
|
||||
$repo = $plugin['Gitea URI'];
|
||||
$local_version = strtolower($plugin['Version']);
|
||||
|
||||
$url = $this->get_gitea_url($host, $repo, '/raw/master/'.basename($plugin_slug));
|
||||
$url = $this->get_gitea_url($host, $repo, '/raw/master/'.$file);
|
||||
if ($url != false) {
|
||||
$new_version = $this->get_gitea_version($url, 'plugin');
|
||||
$new_version = $new_version ? $new_version : $local_version;
|
||||
|
|
@ -105,7 +92,7 @@ class Gitea_Updater {
|
|||
$gitea = array(
|
||||
'plugin' => $plugin_slug,
|
||||
'slug' => $slug,
|
||||
'file' => basename($plugin_slug),
|
||||
'file' => $file,
|
||||
'name' => $plugin['Name'],
|
||||
'gitea_host' => $host,
|
||||
'gitea_repo' => $repo,
|
||||
|
|
@ -122,6 +109,7 @@ class Gitea_Updater {
|
|||
}
|
||||
|
||||
update_option('gitea_plugins', $this->plugins);
|
||||
update_option('gitea_plugins_updated', time());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -168,6 +156,7 @@ class Gitea_Updater {
|
|||
}
|
||||
|
||||
update_option('gitea_themes', $this->themes);
|
||||
update_option('gitea_themes_updated', time());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -191,9 +180,13 @@ class Gitea_Updater {
|
|||
return !empty($token) ? $token : false;
|
||||
}
|
||||
|
||||
function get_gitea_url($host, $repo, $args = '') {
|
||||
$access_token = $this->get_gitea_token($host, $repo);
|
||||
if (!$access_token) return false;
|
||||
function get_gitea_url($host, $repo, $args = '', $access_token = false) {
|
||||
|
||||
if ($access_token === false)
|
||||
$access_token = $this->get_gitea_token($host, $repo);
|
||||
|
||||
if (!$access_token) return false;
|
||||
|
||||
return $host.'api/v1/repos/'.$repo.$args.'?access_token='.$access_token;
|
||||
}
|
||||
|
||||
|
|
@ -255,14 +248,14 @@ class Gitea_Updater {
|
|||
unset($transient->response[$git_plugin['plugin']]);
|
||||
if (version_compare($git_plugin['local_version'], $git_plugin['new_version'], '<')) {
|
||||
|
||||
$object = new stdClass;
|
||||
$object->slug = $git_plugin['slug'];
|
||||
$object->plugin = $git_plugin['plugin'];
|
||||
$object->new_version = $git_plugin['new_version'];
|
||||
$object->url = $git_plugin['url'];
|
||||
$object->package = $git_plugin['package'];
|
||||
// $object = new stdClass;
|
||||
// $object->slug = $git_plugin['slug'];
|
||||
// $object->plugin = $git_plugin['plugin'];
|
||||
// $object->new_version = $git_plugin['new_version'];
|
||||
// $object->url = $git_plugin['url'];
|
||||
// $object->package = $git_plugin['package'];
|
||||
|
||||
$transient->response[$git_plugin['plugin']] = $object;
|
||||
$transient->response[$git_plugin['plugin']] = (object)$git_plugin;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -288,26 +281,6 @@ class Gitea_Updater {
|
|||
return $transient;
|
||||
}
|
||||
|
||||
public function admin_pages_update_transient() {
|
||||
// force update data on 'plugins.php', 'themes.php', 'update-core.php'
|
||||
|
||||
global $pagenow;
|
||||
|
||||
$admin_pages = array('plugins.php', 'themes.php', 'update-core.php');
|
||||
$is_admin_page = in_array($pagenow, $admin_pages) ? true : false;
|
||||
$transient = 'update_'.rtrim($pagenow, '.php');
|
||||
$transient = 'update_update-core' === $transient ? 'update_core' : $transient;
|
||||
|
||||
if ($is_admin_page && current_user_can($transient)) {
|
||||
$current = get_site_transient($transient);
|
||||
$current = $this->pre_set_site_transient_update_plugins($current);
|
||||
$current = $this->pre_set_site_transient_update_themes($current);
|
||||
set_site_transient($transient, $current);
|
||||
}
|
||||
|
||||
remove_filter('admin_init', array($this, 'admin_pages_update_transient'));
|
||||
}
|
||||
|
||||
function upgrader_source_selection($source, $remote_source, $upgrader, $hook_extra = null) {
|
||||
global $wp_filesystem;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue