rename functions
This commit is contained in:
parent
67981c517d
commit
222bbaf084
2 changed files with 24 additions and 26 deletions
|
|
@ -36,7 +36,7 @@ class Gitea_Options {
|
||||||
function options_post() {
|
function options_post() {
|
||||||
|
|
||||||
if (isset($_GET['force-check'])) {
|
if (isset($_GET['force-check'])) {
|
||||||
Gitea_Updater::getInstance()->get_gitea_all();
|
Gitea_Updater::getInstance()->get_all();
|
||||||
set_site_transient('update_plugins', null);
|
set_site_transient('update_plugins', null);
|
||||||
set_site_transient('update_themes', null);
|
set_site_transient('update_themes', null);
|
||||||
}
|
}
|
||||||
|
|
@ -69,8 +69,6 @@ class Gitea_Options {
|
||||||
</div>
|
</div>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|
||||||
<a href="#" id="show-tokens" class="dashicons dashicons-visibility"></a>
|
|
||||||
|
|
||||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post" class="box access">
|
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post" class="box access">
|
||||||
|
|
||||||
<div class="title">
|
<div class="title">
|
||||||
|
|
@ -213,7 +211,7 @@ class Gitea_Options {
|
||||||
$repo = str_replace('.git', '', trim($url['path'], '/'));
|
$repo = str_replace('.git', '', trim($url['path'], '/'));
|
||||||
|
|
||||||
$updater = Gitea_Updater::getInstance();
|
$updater = Gitea_Updater::getInstance();
|
||||||
$package = $updater->get_gitea_url($host, $repo, '/archive/master.zip', $data['access_token']);
|
$package = $updater->get_url($host, $repo, '/archive/master.zip', $data['access_token']);
|
||||||
|
|
||||||
if ($data['type'] == 'plugin') {
|
if ($data['type'] == 'plugin') {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,12 +55,12 @@ class Gitea_Updater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_gitea_all() {
|
function get_all() {
|
||||||
$this->get_gitea_plugins();
|
$this->get_plugins();
|
||||||
$this->get_gitea_themes();
|
$this->get_themes();
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_gitea_plugins() {
|
function get_plugins() {
|
||||||
$this->plugins = array();
|
$this->plugins = array();
|
||||||
$plugins = get_plugins();
|
$plugins = get_plugins();
|
||||||
|
|
||||||
|
|
@ -72,13 +72,13 @@ class Gitea_Updater {
|
||||||
|
|
||||||
$slug = trim(dirname($plugin_slug), '/');
|
$slug = trim(dirname($plugin_slug), '/');
|
||||||
$file = basename($plugin_slug);
|
$file = basename($plugin_slug);
|
||||||
$host = $this->get_gitea_host($plugin['Gitea Host']);
|
$host = $this->get_host($plugin['Gitea Host']);
|
||||||
$repo = $plugin['Gitea URI'];
|
$repo = $plugin['Gitea URI'];
|
||||||
$local_version = strtolower($plugin['Version']);
|
$local_version = strtolower($plugin['Version']);
|
||||||
|
|
||||||
$url = $this->get_gitea_url($host, $repo, '/raw/master/'.$file);
|
$url = $this->get_url($host, $repo, '/raw/master/'.$file);
|
||||||
if ($url != false) {
|
if ($url != false) {
|
||||||
$new_version = $this->get_gitea_version($url, 'plugin');
|
$new_version = $this->get_version($url, 'plugin');
|
||||||
$new_version = $new_version ? $new_version : $local_version;
|
$new_version = $new_version ? $new_version : $local_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,7 +96,7 @@ class Gitea_Updater {
|
||||||
'url' => $host.$repo,
|
'url' => $host.$repo,
|
||||||
'local_version' => $local_version,
|
'local_version' => $local_version,
|
||||||
'new_version' => $new_version,
|
'new_version' => $new_version,
|
||||||
'package' => $this->get_gitea_url($host, $repo, '/archive/master.zip'),
|
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->plugins[$slug] = $gitea;
|
$this->plugins[$slug] = $gitea;
|
||||||
|
|
@ -109,7 +109,7 @@ class Gitea_Updater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_gitea_themes() {
|
function get_themes() {
|
||||||
$this->themes = array();
|
$this->themes = array();
|
||||||
$themes = wp_get_themes();
|
$themes = wp_get_themes();
|
||||||
|
|
||||||
|
|
@ -120,13 +120,13 @@ class Gitea_Updater {
|
||||||
// this is a gitea theme
|
// this is a gitea theme
|
||||||
|
|
||||||
$slug = $theme->stylesheet;
|
$slug = $theme->stylesheet;
|
||||||
$host = $this->get_gitea_host($theme->get('Gitea Host'));
|
$host = $this->get_host($theme->get('Gitea Host'));
|
||||||
$repo = $theme->get('Gitea URI');
|
$repo = $theme->get('Gitea URI');
|
||||||
$local_version = strtolower($theme->get('Version'));
|
$local_version = strtolower($theme->get('Version'));
|
||||||
|
|
||||||
$url = $this->get_gitea_url($host, $repo, '/raw/master/style.css');
|
$url = $this->get_url($host, $repo, '/raw/master/style.css');
|
||||||
if ($url != false) {
|
if ($url != false) {
|
||||||
$new_version = $this->get_gitea_version($url, 'plugin');
|
$new_version = $this->get_version($url, 'plugin');
|
||||||
$new_version = $new_version ? $new_version : $local_version;
|
$new_version = $new_version ? $new_version : $local_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +143,7 @@ class Gitea_Updater {
|
||||||
'url' => $theme->get('AuthorURI'),//$host.$repo,
|
'url' => $theme->get('AuthorURI'),//$host.$repo,
|
||||||
'local_version' => $local_version,
|
'local_version' => $local_version,
|
||||||
'new_version' => $new_version,
|
'new_version' => $new_version,
|
||||||
'package' => $this->get_gitea_url($host, $repo, '/archive/master.zip'),
|
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->themes[$slug] = $gitea;
|
$this->themes[$slug] = $gitea;
|
||||||
|
|
@ -156,11 +156,11 @@ class Gitea_Updater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_gitea_host($host) {
|
function get_host($host) {
|
||||||
return rtrim($host, '/').'/';
|
return rtrim($host, '/').'/';
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_gitea_token($host, $repo) {
|
function get_token($host, $repo) {
|
||||||
$options = Gitea_Options::get();
|
$options = Gitea_Options::get();
|
||||||
$token = '';
|
$token = '';
|
||||||
|
|
||||||
|
|
@ -176,17 +176,17 @@ class Gitea_Updater {
|
||||||
return !empty($token) ? $token : false;
|
return !empty($token) ? $token : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_gitea_url($host, $repo, $args = '', $access_token = false) {
|
function get_url($host, $repo, $args = '', $access_token = false) {
|
||||||
|
|
||||||
if ($access_token === false) {
|
if ($access_token === false) {
|
||||||
$access_token = $this->get_gitea_token($host, $repo);
|
$access_token = $this->get_token($host, $repo);
|
||||||
if (!$access_token) return false;
|
if (!$access_token) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $host.'api/v1/repos/'.$repo.$args.'?access_token='.$access_token;
|
return $host.'api/v1/repos/'.$repo.$args.'?access_token='.$access_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_gitea_file($url) {
|
function get_file($url) {
|
||||||
$request = wp_remote_get($url);
|
$request = wp_remote_get($url);
|
||||||
|
|
||||||
if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
|
if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
|
||||||
|
|
@ -197,9 +197,9 @@ class Gitea_Updater {
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_gitea_version($url, $type) {
|
function get_version($url, $type) {
|
||||||
|
|
||||||
$request = $this->get_gitea_file($url);
|
$request = $this->get_file($url);
|
||||||
|
|
||||||
if (!$request) return false;
|
if (!$request) return false;
|
||||||
|
|
||||||
|
|
@ -236,7 +236,7 @@ class Gitea_Updater {
|
||||||
function pre_set_site_transient_update_plugins($transient) {
|
function pre_set_site_transient_update_plugins($transient) {
|
||||||
// check if some plugin needs update
|
// check if some plugin needs update
|
||||||
|
|
||||||
$this->get_gitea_plugins();
|
$this->get_plugins();
|
||||||
|
|
||||||
foreach ($this->plugins as $plugin => $git_plugin) {
|
foreach ($this->plugins as $plugin => $git_plugin) {
|
||||||
|
|
||||||
|
|
@ -254,7 +254,7 @@ class Gitea_Updater {
|
||||||
function pre_set_site_transient_update_themes($transient) {
|
function pre_set_site_transient_update_themes($transient) {
|
||||||
// check if some theme needs update
|
// check if some theme needs update
|
||||||
|
|
||||||
$this->get_gitea_themes();
|
$this->get_themes();
|
||||||
|
|
||||||
foreach ($this->themes as $theme => $git_theme) {
|
foreach ($this->themes as $theme => $git_theme) {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue