cleanup, prepare localization, show tokens
This commit is contained in:
parent
4bd2231777
commit
2a47c356ee
2 changed files with 53 additions and 60 deletions
|
|
@ -40,7 +40,7 @@ class Gitea_Options {
|
|||
function options_page() {
|
||||
$options = (array)get_option('gitea_options');
|
||||
$repositories = $this->get_repositories();
|
||||
$titles = array(
|
||||
$types = array(
|
||||
'plugin' => __('Plugins'),
|
||||
'theme' => __('Themes'),
|
||||
);
|
||||
|
|
@ -52,21 +52,24 @@ class Gitea_Options {
|
|||
<?php if (isset($_POST['gitea_install'])) : ?>
|
||||
<div class="box install">
|
||||
<div class="title">
|
||||
<h3>Install Results</h3>
|
||||
<h3><?=__('Install Results', 'gitea')?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
<?php $this->install($_POST['gitea_install']); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
|
||||
<a href="#" id="show-tokens"><?=__('Show Tokens', 'gitea')?></a>
|
||||
|
||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post" class="box access">
|
||||
|
||||
<div class="title">
|
||||
<h3>Access Tokens</h3>
|
||||
<h3><?=__('Access Tokens', 'gitea')?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
|
||||
<p>The access token from a repository always have priority over the global.</p>
|
||||
<p><?=__('The access token from a repository always have priority over the global.', 'gitea')?></p>
|
||||
|
||||
<?php foreach ($repositories as $repository => $packages) : ?>
|
||||
<br>
|
||||
|
|
@ -76,7 +79,7 @@ class Gitea_Options {
|
|||
<a href="<?=$repository?>"><strong><?=parse_url($repository)['host']?></strong></a>
|
||||
</td>
|
||||
<td>
|
||||
<input type="password" name="gitea_options[host_token][<?=$repository?>]" value="<?=@$options['host_token'][$repository]?>" placeholder="Global Access Token">
|
||||
<input type="password" class="token" name="gitea_options[host_token][<?=$repository?>]" value="<?=@$options['host_token'][$repository]?>" placeholder="<?=__('Global Access Token', 'gitea')?>">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
|
@ -84,7 +87,7 @@ class Gitea_Options {
|
|||
<tr>
|
||||
<td class="empty"></td>
|
||||
<td colspan="3" class="type">
|
||||
<?=$titles[$type]?>
|
||||
<?=$types[$type]?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php foreach ($items as $slug => $package) : ?>
|
||||
|
|
@ -95,7 +98,7 @@ class Gitea_Options {
|
|||
<a href="<?=$package['url']?>"><?=$package['name']?></a>
|
||||
</td>
|
||||
<td class="input">
|
||||
<input type="password" name="gitea_options[repo_token][<?=$package['url']?>]" value="<?=@$options['repo_token'][$package['url']]?>" placeholder="Access Token">
|
||||
<input type="password" class="token" name="gitea_options[repo_token][<?=$package['url']?>]" value="<?=@$options['repo_token'][$package['url']]?>" placeholder="<?=__('Access Token', 'gitea')?>">
|
||||
</td>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -105,8 +108,8 @@ class Gitea_Options {
|
|||
<?php endforeach; ?>
|
||||
|
||||
<p class="submit">
|
||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?=__('Save Changes')?>">
|
||||
<a href="<?=admin_url('options-general.php?page=gitea-updater&force-check=1')?>" class="button button-primary"><?=__('Reset Cache')?></a>
|
||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?=__('Save Changes', 'gitea')?>">
|
||||
<a href="<?=admin_url('options-general.php?page=gitea-updater&force-check=1')?>" class="button button-primary"><?=__('Reset Cache', 'gitea')?></a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
|
@ -115,42 +118,44 @@ class Gitea_Options {
|
|||
|
||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post" class="box install">
|
||||
<div class="title">
|
||||
<h3>Install from URL</h3>
|
||||
<h3><?=__('Install from URL', 'gitea')?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
|
||||
<p><?=__('Only with <code>http://</code> or <code>https://</code> links, It\'s not working with <code>ssh://</code> links!', 'gitea')?></p>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th>
|
||||
<label>Type</label>
|
||||
<label><?=__('Type', 'gitea')?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="gitea_install[type]">
|
||||
<option value="plugin"><?=__('Plugins')?></option>
|
||||
<option value="theme"><?=__('Themes')?></option>
|
||||
<option value="plugin"><?=__('Plugins', 'gitea')?></option>
|
||||
<option value="theme"><?=__('Themes', 'gitea')?></option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label>Repository URL</label>
|
||||
<label><?=__('Repository URL', 'gitea')?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="gitea_install[url]" value="https://git.paucapo.com/wp/pau-cleanwordpress.git">
|
||||
<input type="text" name="gitea_install[url]" placeholder="https://host/org/repo or https://host/org/repo.git">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label>Access Token</label>
|
||||
<label><?=__('Access Token', 'gitea')?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="gitea_install[access_token]" value="9ebc78834767d2ce0f95ec8a5ab597bc1fbc9ed6">
|
||||
<input type="password" class="token" name="gitea_install[access_token]">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?=__('Install Now')?>">
|
||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?=__('Install Now', 'gitea')?>">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
@ -165,12 +170,15 @@ class Gitea_Options {
|
|||
themes: <?=date('d/m/Y H:i:s', get_option('gitea_themes_updated'))?>
|
||||
</div>
|
||||
|
||||
<textarea style="width:100%" rows="2" onfocus="this.rows=30;" onblur="this.rows=2;" readonly><?php var_dump($repositories); ?></textarea>
|
||||
<?php /*<textarea style="width:100%" rows="2" onfocus="this.rows=30;" onblur="this.rows=2;" readonly><?php var_dump($repositories); ?></textarea> */ ?>
|
||||
|
||||
<style>
|
||||
.wrap {
|
||||
overflow: hidden;
|
||||
}
|
||||
#show-tokens {
|
||||
float: right;
|
||||
}
|
||||
.box {
|
||||
margin: 20px 0;
|
||||
background: #FFFFFF;
|
||||
|
|
@ -235,10 +243,23 @@ class Gitea_Options {
|
|||
padding: 10px;
|
||||
font-style: italic;
|
||||
}
|
||||
.form-table input[type=text] {
|
||||
.form-table input[type=text],
|
||||
.form-table input[type=password] {
|
||||
width: 75%;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
jQuery('#show-tokens').on('click', function() {
|
||||
if (jQuery('input.token').attr('type') == 'password') {
|
||||
jQuery('input.token').attr('type', 'text');
|
||||
jQuery(this).html('<?=__('Hide Tokens', 'gitea')?>');
|
||||
} else {
|
||||
jQuery('input.token').attr('type', 'password');
|
||||
jQuery(this).html('<?=__('Show Tokens', 'gitea')?>');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
|
@ -276,34 +297,31 @@ class Gitea_Options {
|
|||
|
||||
if ($data['type'] == 'plugin') {
|
||||
|
||||
add_filter('install_plugin_complete_actions', array($this, 'installed'), 10, 3);
|
||||
add_filter('install_plugin_complete_actions', array($this, 'install_actions'));
|
||||
|
||||
$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);
|
||||
remove_filter('install_plugin_complete_actions', array($this, 'install_actions'));
|
||||
|
||||
} elseif ($data['type'] == 'theme') {
|
||||
|
||||
add_filter('install_theme_complete_actions', array($this, 'installed'), 10, 3);
|
||||
add_filter('install_theme_complete_actions', array($this, 'install_actions'));
|
||||
|
||||
$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);
|
||||
remove_filter('install_theme_complete_actions', array($this, 'install_actions'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function installed($install_actions, $api, $file) {
|
||||
$return = '<a href="' . admin_url('options-general.php?page=gitea-updater') . '" target="_parent">' . __( 'Return' ) . '</a>';
|
||||
|
||||
if (isset($install_actions['plugins_page'])) $install_actions['plugins_page'] = $return;
|
||||
if (isset($install_actions['themes_page'])) $install_actions['themes_page'] = $return;
|
||||
|
||||
|
||||
function install_actions($install_actions) {
|
||||
unset($install_actions['plugins_page'], $install_actions['themes_page']);
|
||||
$install_actions['gitea_page'] = '<a href="' . admin_url('options-general.php?page=gitea-updater') . '" target="_parent">' . __( 'Return', 'gitea' ) . '</a>';
|
||||
return $install_actions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ class Gitea_Updater {
|
|||
public $themes = array();
|
||||
public $remote_managemnet = true;
|
||||
|
||||
|
||||
function __construct() {
|
||||
|
||||
Gitea_Options::getInstance();
|
||||
|
|
@ -50,9 +49,6 @@ class Gitea_Updater {
|
|||
// themes checks
|
||||
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);
|
||||
|
||||
// extra plugins and themes headers (Gitea Host and Gitea URI)
|
||||
add_filter('extra_plugin_headers', array($this, 'extra_headers'));
|
||||
add_filter('extra_theme_headers', array($this, 'extra_headers'));
|
||||
|
|
@ -182,10 +178,10 @@ class Gitea_Updater {
|
|||
|
||||
function get_gitea_url($host, $repo, $args = '', $access_token = false) {
|
||||
|
||||
if ($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;
|
||||
}
|
||||
|
|
@ -238,7 +234,7 @@ class Gitea_Updater {
|
|||
}
|
||||
|
||||
function pre_set_site_transient_update_plugins($transient) {
|
||||
// check if some plugin needs update using the cached data
|
||||
// check if some plugin needs update
|
||||
|
||||
$this->get_gitea_plugins();
|
||||
|
||||
|
|
@ -247,14 +243,6 @@ class Gitea_Updater {
|
|||
if (isset($transient->response[$git_plugin['plugin']]))
|
||||
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'];
|
||||
|
||||
$transient->response[$git_plugin['plugin']] = (object)$git_plugin;
|
||||
}
|
||||
|
||||
|
|
@ -281,19 +269,6 @@ class Gitea_Updater {
|
|||
return $transient;
|
||||
}
|
||||
|
||||
function upgrader_source_selection($source, $remote_source, $upgrader, $hook_extra = null) {
|
||||
global $wp_filesystem;
|
||||
|
||||
$plugin = isset($hook_extra['plugin']) ? $hook_extra['plugin'] : false;
|
||||
if (isset($this->plugins[$plugin]) && $plugin) {
|
||||
$new_source = trailingslashit($remote_source).dirname($plugin);
|
||||
$wp_filesystem->move($source, $new_source);
|
||||
return trailingslashit($new_source);
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
function get_file_headers($contents, $type) {
|
||||
|
||||
$gitea_headers = array(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue