settings almost done!
This commit is contained in:
parent
86156ba3cd
commit
e19b894737
2 changed files with 169 additions and 126 deletions
|
|
@ -4,56 +4,122 @@ defined( 'ABSPATH' ) or exit;
|
|||
|
||||
class Gitea_Updater_Settings {
|
||||
|
||||
private static $_instance;
|
||||
|
||||
public static function getInstance() {
|
||||
if (!(self::$_instance instanceof self)) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
function __construct() {
|
||||
add_action('admin_menu', array($this, 'admin_menu'));
|
||||
add_action('admin_init', array($this, 'admin_init'));
|
||||
}
|
||||
|
||||
function admin_menu() {
|
||||
add_options_page('Gitea Upater', 'Gitea Upater', 'manage_options', 'gitea-upater', array($this, 'options_page'));
|
||||
}
|
||||
|
||||
function admin_init() {
|
||||
register_setting('gitea_options_page', 'gitea_options');
|
||||
|
||||
// add_settings_section(
|
||||
// 'gitea_options_section',
|
||||
// __('Your section description', 'gitea'),
|
||||
// '__return_false',
|
||||
// 'gitea_options_page'
|
||||
// );
|
||||
|
||||
// add_settings_field(
|
||||
// 'gitea_acces_token',
|
||||
// __('Access token', 'gitea'),
|
||||
// array($this, 'access_token'),
|
||||
// 'gitea_options_page',
|
||||
// 'gitea_options_section'
|
||||
// );
|
||||
}
|
||||
|
||||
function access_token() {
|
||||
$options = get_option('gitea_options');
|
||||
?>
|
||||
<input type='text' name='gitea_options[gitea_acces_token]' value='<?php echo $options['gitea_acces_token']; ?>'>
|
||||
<?php
|
||||
add_options_page('Gitea Updater', 'Gitea Updater', 'manage_options', 'gitea-updater', array($this, 'options_page'));
|
||||
}
|
||||
|
||||
function options_page() {
|
||||
if (isset($_GET['force-check'])) {
|
||||
Gitea_Updater::getInstance()->get_gitea_all();
|
||||
}
|
||||
if (isset($_POST['gitea_options'])) {
|
||||
update_option('gitea_options', $_POST['gitea_options']);
|
||||
}
|
||||
$options = (array)get_option('gitea_options');
|
||||
$repositories = $this->get_repositories();
|
||||
$titles = array(
|
||||
'plugin' => __('Plugins'),
|
||||
'theme' => __('Themes'),
|
||||
);
|
||||
?>
|
||||
<form action='options.php' method='post'>
|
||||
<div class="wrap">
|
||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post">
|
||||
<?php /* settings_fields('gitea_options_page'); */ ?>
|
||||
|
||||
<h2>Gitea Upater</h2>
|
||||
<h1>Gitea Updater</h1>
|
||||
|
||||
<?php
|
||||
settings_fields('gitea_options_page');
|
||||
// do_settings_sections('gitea_options_page');
|
||||
?>
|
||||
<?php foreach ($repositories as $repository => $packages) : ?>
|
||||
<br>
|
||||
<table class="widefat striped gitea">
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<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">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
<?php foreach ($packages as $type => $items) : ?>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td colspan="3">
|
||||
<?=$titles[$type]?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php foreach ($items as $slug => $package) : ?>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="package">
|
||||
<a href="<?=$package['url']?>"><?=$package['name']?></a>
|
||||
</td>
|
||||
<td>
|
||||
<input type="password" name="gitea_options[repo_token][<?=$package['url']?>]" value="<?=@$options['repo_token'][$package['url']]?>" placeholder="Access Token">
|
||||
</td>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</table>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php /*submit_button();*/ ?>
|
||||
<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>
|
||||
</p>
|
||||
</form>
|
||||
<textarea style="width:100%" rows="2" onfocus="this.rows=30;" onblur="this.rows=2;" readonly><?php var_dump($options); ?></textarea>
|
||||
</div>
|
||||
<style>
|
||||
table.gitea {
|
||||
min-width: 700px;
|
||||
width: auto;
|
||||
}
|
||||
table.gitea input {
|
||||
min-width: 400px;
|
||||
}
|
||||
table.gitea td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
table.gitea td.package {
|
||||
min-width: 250px;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
function get_repositories() {
|
||||
$plugins = (array)get_option('gitea_plugins');
|
||||
$themes = (array)get_option('gitea_themes');
|
||||
|
||||
$repositories = array();
|
||||
|
||||
foreach ($plugins as $slug => $plugin) {
|
||||
$repositories[$plugin['gitea_host']]['plugin'][$slug] = $plugin;
|
||||
}
|
||||
|
||||
foreach ($themes as $slug => $theme) {
|
||||
$repositories[$plugin['gitea_host']]['theme'][$slug] = $theme;
|
||||
}
|
||||
|
||||
return $repositories;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue