diff --git a/gitea-options.php b/gitea-options.php
index 7ebfffa..bd3f7dd 100644
--- a/gitea-options.php
+++ b/gitea-options.php
@@ -2,9 +2,12 @@
defined( 'ABSPATH' ) or exit;
+include_once(ABSPATH.'wp-admin/includes/class-wp-upgrader.php');
+
class Gitea_Options {
private static $_instance;
+ var $install_log = false;
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
@@ -31,6 +34,7 @@ class Gitea_Options {
if (isset($_POST['gitea_options'])) {
update_option('gitea_options', $_POST['gitea_options']);
}
+
}
function options_page() {
@@ -42,68 +46,197 @@ class Gitea_Options {
);
?>
+
+
+
+
+
-
-
-
- =__('Reset Cache')?>
-
-
- =date('d/m/Y H:i:s', get_option('gitea_last_checked'))?>
-
+
+
+ plugins: =date('d/m/Y H:i:s', get_option('gitea_plugins_updated'))?>
+ themes: =date('d/m/Y H:i:s', get_option('gitea_themes_updated'))?>
+
+
+
+
$plugin) {
+ $plugin['url'] = $plugin['gitea_host'].$plugin['gitea_repo'];
$repositories[$plugin['gitea_host']]['plugin'][$slug] = $plugin;
}
foreach ($themes as $slug => $theme) {
+ $theme['url'] = $theme['gitea_host'].$theme['gitea_repo'];
$repositories[$plugin['gitea_host']]['theme'][$slug] = $theme;
}
@@ -131,5 +266,44 @@ class Gitea_Options {
return (array)get_option('gitea_options');
}
+ function install($data) {
+ $url = parse_url($data['url']);
+ $host = $url['scheme'].'://'.$url['host'].'/';
+ $repo = str_replace('.git', '', trim($url['path'], '/'));
+
+ $updater = Gitea_Updater::getInstance();
+ $package = $updater->get_gitea_url($host, $repo, '/archive/master.zip', $data['access_token']);
+
+ if ($data['type'] == 'plugin') {
+
+ add_filter('install_plugin_complete_actions', array($this, 'installed'), 10, 3);
+
+ $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
+ $upgrader->install($package);
+
+ remove_filter('install_plugin_complete_actions', array($this, 'installed'), 10, 3);
+
+ } elseif ($data['type'] == 'theme') {
+
+ add_filter('install_theme_complete_actions', array($this, 'installed'), 10, 3);
+
+ $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'theme', 'api') ) );
+ $upgrader->install($package);
+
+ remove_filter('install_theme_complete_actions', array($this, 'installed'), 10, 3);
+
+ }
+
+ }
+
+ function installed($install_actions, $api, $file) {
+ $return = '' . __( 'Return' ) . '';
+
+ if (isset($install_actions['plugins_page'])) $install_actions['plugins_page'] = $return;
+ if (isset($install_actions['themes_page'])) $install_actions['themes_page'] = $return;
+
+
+ return $install_actions;
+ }
}
diff --git a/gitea-updater.php b/gitea-updater.php
index 0732e72..614e07d 100644
--- a/gitea-updater.php
+++ b/gitea-updater.php
@@ -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;