Enable self-update support for KGV Updater

This commit is contained in:
2026-04-13 22:06:13 +02:00
parent ab882a7333
commit 04e897b510

View File

@@ -3,6 +3,8 @@
* Plugin Name: KGV Updater
* Plugin URI: https://apex-project.de/
* Description: Aktualisiert KGV-Plugins direkt aus den Gitea-Repositories.
* Update URI: https://git.apex-project.de/RonnyG/KGV-Updater
* Gitea Plugin URI: https://git.apex-project.de/RonnyG/KGV-Updater
* Version: 1.0.0
* Author: Ronny Grobel
* Text Domain: kgv-updater
@@ -13,8 +15,8 @@ if ( ! defined( 'ABSPATH' ) ) {
}
final class KGV_Updater {
const OPTION_TOKEN = 'kgv_updater_gitea_token';
const OPTION_HOST = 'kgv_updater_gitea_host';
const GITEA_HOST = 'git.apex-project.de';
const GITEA_TOKEN = '';
private static $instance = null;
@@ -29,72 +31,6 @@ final class KGV_Updater {
private function __construct() {
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'inject_updates' ) );
add_filter( 'plugins_api', array( $this, 'plugins_api' ), 10, 3 );
add_action( 'admin_menu', array( $this, 'register_settings_page' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
}
public function register_settings() {
register_setting(
'kgv_updater_settings',
self::OPTION_TOKEN,
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '',
)
);
register_setting(
'kgv_updater_settings',
self::OPTION_HOST,
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => 'git.apex-project.de',
)
);
}
public function register_settings_page() {
add_options_page(
'KGV Updater',
'KGV Updater',
'manage_options',
'kgv-updater',
array( $this, 'render_settings_page' )
);
}
public function render_settings_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
?>
<div class="wrap">
<h1>KGV Updater</h1>
<p>Prueft KGV-Plugins mit <code>Update URI</code> auf neue Versionen in Gitea.</p>
<form method="post" action="options.php">
<?php settings_fields( 'kgv_updater_settings' ); ?>
<table class="form-table" role="presentation">
<tr>
<th scope="row"><label for="kgv_updater_gitea_host">Gitea Host</label></th>
<td>
<input type="text" id="kgv_updater_gitea_host" name="<?php echo esc_attr( self::OPTION_HOST ); ?>" value="<?php echo esc_attr( $this->get_gitea_host() ); ?>" class="regular-text" />
<p class="description">Standard: <code>git.apex-project.de</code></p>
</td>
</tr>
<tr>
<th scope="row"><label for="kgv_updater_gitea_token">Gitea Token</label></th>
<td>
<input type="password" id="kgv_updater_gitea_token" name="<?php echo esc_attr( self::OPTION_TOKEN ); ?>" value="<?php echo esc_attr( get_option( self::OPTION_TOKEN, '' ) ); ?>" class="regular-text" autocomplete="new-password" />
<p class="description">Nur noetig fuer private Repositories.</p>
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
public function inject_updates( $transient ) {
@@ -175,14 +111,10 @@ final class KGV_Updater {
}
$plugins = get_plugins();
$host = $this->get_gitea_host();
$host = self::GITEA_HOST;
$managed = array();
foreach ( $plugins as $plugin_file => $plugin_data ) {
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
continue;
}
$update_uri = isset( $plugin_data['UpdateURI'] ) ? trim( (string) $plugin_data['UpdateURI'] ) : '';
$name = isset( $plugin_data['Name'] ) ? (string) $plugin_data['Name'] : '';
@@ -219,7 +151,7 @@ final class KGV_Updater {
'User-Agent' => 'KGV-Updater/1.0',
);
$token = trim( (string) get_option( self::OPTION_TOKEN, '' ) );
$token = trim( (string) self::GITEA_TOKEN );
if ( '' !== $token ) {
$headers['Authorization'] = 'token ' . $token;
}
@@ -313,10 +245,6 @@ final class KGV_Updater {
);
}
private function get_gitea_host() {
$host = trim( (string) get_option( self::OPTION_HOST, 'git.apex-project.de' ) );
return '' !== $host ? $host : 'git.apex-project.de';
}
}
KGV_Updater::instance();