remote install
This commit is contained in:
parent
996b5bc50a
commit
4bd2231777
2 changed files with 238 additions and 91 deletions
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
include_once(ABSPATH.'wp-admin/includes/class-wp-upgrader.php');
|
||||
|
||||
class Gitea_Options {
|
||||
|
||||
private static $_instance;
|
||||
var $install_log = false;
|
||||
|
||||
public static function getInstance() {
|
||||
if (!(self::$_instance instanceof self)) {
|
||||
|
|
@ -31,6 +34,7 @@ class Gitea_Options {
|
|||
if (isset($_POST['gitea_options'])) {
|
||||
update_option('gitea_options', $_POST['gitea_options']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function options_page() {
|
||||
|
|
@ -42,68 +46,197 @@ class Gitea_Options {
|
|||
);
|
||||
?>
|
||||
<div class="wrap">
|
||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post">
|
||||
|
||||
<h1>Gitea Updater</h1>
|
||||
<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 if (isset($_POST['gitea_install'])) : ?>
|
||||
<div class="box install">
|
||||
<div class="title">
|
||||
<h3>Install Results</h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
<?php $this->install($_POST['gitea_install']); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post" class="box access">
|
||||
|
||||
<?php foreach ($packages as $type => $items) : ?>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td colspan="3">
|
||||
<?=$titles[$type]?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php foreach ($items as $slug => $package) : ?>
|
||||
<div class="title">
|
||||
<h3>Access Tokens</h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
|
||||
<p>The access token from a repository always have priority over the global.</p>
|
||||
|
||||
<?php foreach ($repositories as $repository => $packages) : ?>
|
||||
<br>
|
||||
<table class="widefat striped gitea">
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="package">
|
||||
<a href="<?=$package['url']?>"><?=$package['name']?></a>
|
||||
<td colspan="3" class="repository">
|
||||
<a href="<?=$repository?>"><strong><?=parse_url($repository)['host']?></strong></a>
|
||||
</td>
|
||||
<td>
|
||||
<input type="password" name="gitea_options[repo_token][<?=$package['url']?>]" value="<?=@$options['repo_token'][$package['url']]?>" placeholder="Access Token">
|
||||
<input type="password" name="gitea_options[host_token][<?=$repository?>]" value="<?=@$options['host_token'][$repository]?>" placeholder="Global Access Token">
|
||||
</td>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
|
||||
<?php foreach ($packages as $type => $items) : ?>
|
||||
<tr>
|
||||
<td class="empty"></td>
|
||||
<td colspan="3" class="type">
|
||||
<?=$titles[$type]?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php foreach ($items as $slug => $package) : ?>
|
||||
<tr>
|
||||
<td class="empty"></td>
|
||||
<td class="empty"></td>
|
||||
<td class="package">
|
||||
<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">
|
||||
</td>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</table>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</table>
|
||||
<?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>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post" class="box install">
|
||||
<div class="title">
|
||||
<h3>Install from URL</h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th>
|
||||
<label>Type</label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="gitea_install[type]">
|
||||
<option value="plugin"><?=__('Plugins')?></option>
|
||||
<option value="theme"><?=__('Themes')?></option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label>Repository URL</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="gitea_install[url]" value="https://git.paucapo.com/wp/pau-cleanwordpress.git">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label>Access Token</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="gitea_install[access_token]" value="9ebc78834767d2ce0f95ec8a5ab597bc1fbc9ed6">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?=__('Install Now')?>">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<?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>
|
||||
<?=date('d/m/Y H:i:s', get_option('gitea_last_checked'))?>
|
||||
<textarea style="width:100%" rows="2" onfocus="this.rows=30;" onblur="this.rows=2;" readonly><?php var_dump(get_plugin_updates()); ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="times">
|
||||
plugins: <?=date('d/m/Y H:i:s', get_option('gitea_plugins_updated'))?>
|
||||
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>
|
||||
|
||||
<style>
|
||||
.wrap {
|
||||
overflow: hidden;
|
||||
}
|
||||
.box {
|
||||
margin: 20px 0;
|
||||
background: #FFFFFF;
|
||||
border: 1px solid #E5E5E5;
|
||||
position: relative;
|
||||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
.box .title {
|
||||
border-bottom: 1px solid #EEEEEE;
|
||||
margin: 0;
|
||||
padding: 15px;
|
||||
background: #FFFFFF;
|
||||
}
|
||||
.box .title h3 {
|
||||
font-size: 14px;
|
||||
line-height: 1em;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.box .inner {
|
||||
padding: 15px;
|
||||
}
|
||||
table.gitea {
|
||||
min-width: 700px;
|
||||
width: auto;
|
||||
}
|
||||
table.gitea input {
|
||||
min-width: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.gitea td {
|
||||
vertical-align: middle;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
table.gitea td.repository {
|
||||
width: 210px;
|
||||
}
|
||||
table.gitea td.type {
|
||||
width: 190px;
|
||||
}
|
||||
table.gitea td.package {
|
||||
min-width: 250px;
|
||||
width: 170px;
|
||||
}
|
||||
table.gitea td.empty {
|
||||
width: 1px;
|
||||
}
|
||||
table.gitea input {
|
||||
width: 70%;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 782px) {
|
||||
table.gitea td {
|
||||
display: block;
|
||||
}
|
||||
table.gitea td.empty {
|
||||
display: none;
|
||||
}
|
||||
table.gitea input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.times {
|
||||
color: #555d66;
|
||||
float: right;
|
||||
padding: 10px;
|
||||
font-style: italic;
|
||||
}
|
||||
.form-table input[type=text] {
|
||||
width: 75%;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
|
|
@ -116,10 +249,12 @@ class Gitea_Options {
|
|||
$repositories = array();
|
||||
|
||||
foreach ($plugins as $slug => $plugin) {
|
||||
$plugin['url'] = $plugin['gitea_host'].$plugin['gitea_repo'];
|
||||
$repositories[$plugin['gitea_host']]['plugin'][$slug] = $plugin;
|
||||
}
|
||||
|
||||
foreach ($themes as $slug => $theme) {
|
||||
$theme['url'] = $theme['gitea_host'].$theme['gitea_repo'];
|
||||
$repositories[$plugin['gitea_host']]['theme'][$slug] = $theme;
|
||||
}
|
||||
|
||||
|
|
@ -131,5 +266,44 @@ class Gitea_Options {
|
|||
return (array)get_option('gitea_options');
|
||||
}
|
||||
|
||||
function install($data) {
|
||||
$url = parse_url($data['url']);
|
||||
$host = $url['scheme'].'://'.$url['host'].'/';
|
||||
$repo = str_replace('.git', '', trim($url['path'], '/'));
|
||||
|
||||
$updater = Gitea_Updater::getInstance();
|
||||
$package = $updater->get_gitea_url($host, $repo, '/archive/master.zip', $data['access_token']);
|
||||
|
||||
if ($data['type'] == 'plugin') {
|
||||
|
||||
add_filter('install_plugin_complete_actions', array($this, 'installed'), 10, 3);
|
||||
|
||||
$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);
|
||||
|
||||
} elseif ($data['type'] == 'theme') {
|
||||
|
||||
add_filter('install_theme_complete_actions', array($this, 'installed'), 10, 3);
|
||||
|
||||
$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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
return $install_actions;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue