125 lines
4.1 KiB
PHP
125 lines
4.1 KiB
PHP
<?php
|
|
|
|
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'));
|
|
}
|
|
|
|
function admin_menu() {
|
|
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'),
|
|
);
|
|
?>
|
|
<div class="wrap">
|
|
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post">
|
|
<?php /* settings_fields('gitea_options_page'); */ ?>
|
|
|
|
<h1>Gitea Updater</h1>
|
|
|
|
<?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 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;
|
|
|
|
}
|
|
|
|
}
|
|
|