bug fix on admin_init and code cleanup
This commit is contained in:
parent
bf32f439e6
commit
d1275eb680
5 changed files with 592 additions and 538 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
|||
*~
|
||||
*.iml
|
||||
.idea
|
||||
|
|
@ -1,37 +1,26 @@
|
|||
jQuery(document).ready(function($) {
|
||||
jQuery(document).ready(function ($) {
|
||||
|
||||
// $('#show-tokens').on('click', function() {
|
||||
// if ($('input.token').attr('type') == 'password') {
|
||||
// $('input.token').attr('type', 'text');
|
||||
// $(this).addClass('dashicons-hidden').removeClass('dashicons-visibility')
|
||||
// } else {
|
||||
// $('input.token').attr('type', 'password');
|
||||
// $(this).addClass('dashicons-visibility').removeClass('dashicons-hidden')
|
||||
// }
|
||||
// return false;
|
||||
// });
|
||||
$('input.token').each(function () {
|
||||
var token = $(this);
|
||||
var toggle = $('<a href="#" class="token-toggle dashicons dashicons-visibility"></a>');
|
||||
token.wrap('<span class="token-box"></span>').after(toggle);
|
||||
toggle.on('click', function () {
|
||||
if (token.attr('type') === 'password') {
|
||||
token.attr('type', 'text');
|
||||
toggle.addClass('dashicons-hidden').removeClass('dashicons-visibility');
|
||||
} else {
|
||||
token.attr('type', 'password');
|
||||
toggle.addClass('dashicons-visibility').removeClass('dashicons-hidden');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
$('input.token').each(function() {
|
||||
var token = $(this)
|
||||
var toggle = $('<a href="#" class="token-toggle dashicons dashicons-visibility"></a>');
|
||||
token.wrap('<span class="token-box"></span>').after(toggle);
|
||||
toggle.on('click', function() {
|
||||
if (token.attr('type') == 'password') {
|
||||
token.attr('type', 'text')
|
||||
toggle.addClass('dashicons-hidden').removeClass('dashicons-visibility')
|
||||
} else {
|
||||
token.attr('type', 'password')
|
||||
toggle.addClass('dashicons-visibility').removeClass('dashicons-hidden')
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
$('.repo-toggle').on('click', function() {
|
||||
var id = $(this).data('repo');
|
||||
$('.repo-'+id).toggleClass('open')
|
||||
$('.repo-'+id+' > ul.packages').slideToggle(400)
|
||||
return false;
|
||||
});
|
||||
$('.repo-toggle').on('click', function () {
|
||||
var id = $(this).data('repo');
|
||||
$('.repo-' + id).toggleClass('open');
|
||||
$('.repo-' + id + ' > ul.packages').slideToggle(400);
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
155
assets/style.css
155
assets/style.css
|
|
@ -1,133 +1,152 @@
|
|||
.wrap {
|
||||
overflow: hidden;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#show-tokens {
|
||||
float: right;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.box {
|
||||
margin: 20px 0;
|
||||
background: #FFFFFF;
|
||||
border: 1px solid #E5E5E5;
|
||||
position: relative;
|
||||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
|
||||
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;
|
||||
border-bottom: 1px solid #EEEEEE;
|
||||
margin: 0;
|
||||
padding: 15px;
|
||||
background: #FFFFFF;
|
||||
}
|
||||
|
||||
.box .title h3 {
|
||||
font-size: 14px;
|
||||
line-height: 1em;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-size: 14px;
|
||||
line-height: 1em;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.box .inner {
|
||||
padding: 15px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.gitea {
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border-top: 1px solid #e5e5e5;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,.04);
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border-top: 1px solid #e5e5e5;
|
||||
box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
|
||||
}
|
||||
|
||||
.gitea > li {
|
||||
overflow: hidden;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.gitea > li > ul {
|
||||
overflow: hidden;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.gitea > li li {
|
||||
box-sizing: border-box;
|
||||
padding: 8px 15px;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
// width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 8px 15px;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.gitea ul.packages > li {
|
||||
padding: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.gitea li.repository,
|
||||
.gitea li.package {
|
||||
width: 210px;
|
||||
float: left;
|
||||
width: 210px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.gitea a {
|
||||
text-decoration: none;
|
||||
outline: 0;
|
||||
text-decoration: none;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.gitea a:focus,
|
||||
.gitea a:active {
|
||||
outline: 0;
|
||||
box-shadow: none;
|
||||
outline: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.gitea a.repo-toggle {
|
||||
font-size: 14px;
|
||||
line-height: 14px;
|
||||
font-size: 14px;
|
||||
line-height: 14px;
|
||||
}
|
||||
|
||||
.gitea > li:hover .row-actions {
|
||||
left: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.gitea input.token {
|
||||
width: 70%;
|
||||
width: 70%;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 782px) {
|
||||
.gitea input.token {
|
||||
width: 100%;
|
||||
}
|
||||
.gitea input.token {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.times {
|
||||
color: #555d66;
|
||||
float: right;
|
||||
padding: 10px;
|
||||
font-style: italic;
|
||||
color: #555d66;
|
||||
float: right;
|
||||
padding: 10px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.form-table input[type=text],
|
||||
.form-table input[type=password] {
|
||||
width: 75%;
|
||||
width: 75%;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.repo-row > ul.packages {
|
||||
display: none;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.repo-row > ul:first-child {
|
||||
transition: all 0.4s;
|
||||
transition: all 0.4s;
|
||||
}
|
||||
|
||||
.repo-row.open > ul:first-child {
|
||||
background: #2a9bd9;
|
||||
border-color: #2a9bd9;
|
||||
color: white;
|
||||
background: #2a9bd9;
|
||||
border-color: #2a9bd9;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.repo-row.open > ul:first-child a {
|
||||
color: white;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.token-box {
|
||||
position: relative;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.token-toggle {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
height: 20px;
|
||||
top: 50%;
|
||||
margin-top: -10px;
|
||||
color: #aaa !important;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
height: 20px;
|
||||
top: 50%;
|
||||
margin-top: -10px;
|
||||
color: #aaa !important;
|
||||
}
|
||||
|
||||
.token-toggle:hover {
|
||||
color: #aaa !important;
|
||||
color: #aaa !important;
|
||||
}
|
||||
|
||||
.token-toggle:focus,
|
||||
.token-toggle:active {
|
||||
outline: 0;
|
||||
box-shadow: none;
|
||||
color: #aaa !important;
|
||||
outline: 0;
|
||||
box-shadow: none;
|
||||
color: #aaa !important;
|
||||
}
|
||||
|
|
@ -1,246 +1,271 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
defined('ABSPATH') or exit;
|
||||
|
||||
include_once(ABSPATH.'wp-admin/includes/class-wp-upgrader.php');
|
||||
include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
||||
|
||||
class Gitea_Options {
|
||||
class Gitea_Options
|
||||
{
|
||||
|
||||
private static $_instance;
|
||||
var $page = false;
|
||||
private static $_instance;
|
||||
var $page = false;
|
||||
|
||||
public static function getInstance() {
|
||||
if (!(self::$_instance instanceof self)) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_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_enqueue_scripts', array($this, 'enqueue_assets'));
|
||||
}
|
||||
function __construct()
|
||||
{
|
||||
add_action('admin_menu', array($this, 'admin_menu'));
|
||||
add_action('admin_enqueue_scripts', array($this, 'enqueue_assets'));
|
||||
}
|
||||
|
||||
function admin_menu() {
|
||||
$this->page = add_options_page('Gitea Updater', 'Gitea Updater', 'manage_options', 'gitea-updater', array($this, 'options_page'));
|
||||
add_action('load-'.$this->page, array($this, 'options_post'));
|
||||
}
|
||||
function admin_menu()
|
||||
{
|
||||
$this->page = add_options_page('Gitea Updater', 'Gitea Updater', 'manage_options', 'gitea-updater', array($this, 'options_page'));
|
||||
add_action('load-' . $this->page, array($this, 'options_post'));
|
||||
}
|
||||
|
||||
function enqueue_assets($hook) {
|
||||
if ($hook != $this->page) return;
|
||||
function enqueue_assets($hook)
|
||||
{
|
||||
if ($hook != $this->page) return;
|
||||
|
||||
wp_enqueue_style('gitea-updater', plugins_url('/assets/style.css', __FILE__));
|
||||
wp_enqueue_script('gitea-js', plugins_url('/assets/script.js', __FILE__), array('jquery'), null, true);
|
||||
}
|
||||
wp_enqueue_style('gitea-updater', plugins_url('/assets/style.css', __FILE__));
|
||||
wp_enqueue_script('gitea-js', plugins_url('/assets/script.js', __FILE__), array('jquery'), null, true);
|
||||
}
|
||||
|
||||
function options_post() {
|
||||
function options_post()
|
||||
{
|
||||
|
||||
if (isset($_GET['force-check'])) {
|
||||
Gitea_Updater::getInstance()->get_all();
|
||||
set_site_transient('update_plugins', null);
|
||||
set_site_transient('update_themes', null);
|
||||
}
|
||||
if (isset($_POST['gitea_options'])) {
|
||||
update_option('gitea_options', $_POST['gitea_options']);
|
||||
}
|
||||
if (isset($_GET['force-check'])) {
|
||||
Gitea_Updater::getInstance()->get_all();
|
||||
set_site_transient('update_plugins', null);
|
||||
set_site_transient('update_themes', null);
|
||||
}
|
||||
if (isset($_POST['gitea_options'])) {
|
||||
update_option('gitea_options', $_POST['gitea_options']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function options_page() {
|
||||
$options = (array)get_option('gitea_options');
|
||||
$repositories = $this->get_repositories();
|
||||
$types = array(
|
||||
'plugin' => __('Plugins'),
|
||||
'theme' => __('Themes'),
|
||||
);
|
||||
?>
|
||||
<div class="wrap">
|
||||
function options_page()
|
||||
{
|
||||
$options = (array)get_option('gitea_options');
|
||||
$repositories = $this->get_repositories();
|
||||
$types = array(
|
||||
'plugin' => __('Plugins'),
|
||||
'theme' => __('Themes'),
|
||||
);
|
||||
?>
|
||||
<div class="wrap">
|
||||
|
||||
<h1>Gitea Updater</h1>
|
||||
<h1>Gitea Updater</h1>
|
||||
|
||||
<?php if (isset($_POST['gitea_install'])) : ?>
|
||||
<div class="box install">
|
||||
<div class="title">
|
||||
<h3><?=__('Install Results', 'gitea')?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
<?php $this->install($_POST['gitea_install']); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<?php if (isset($_POST['gitea_install'])) : ?>
|
||||
<div class="box install">
|
||||
<div class="title">
|
||||
<h3><?= __('Install Results', 'gitea') ?></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">
|
||||
<form action="<?= admin_url('options-general.php?page=gitea-updater') ?>" method="post"
|
||||
class="box access">
|
||||
|
||||
<div class="title">
|
||||
<h3><?=__('Access Tokens', 'gitea')?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
<p><?=__('The access token from a repository always have priority over the global.', 'gitea')?></p>
|
||||
</div>
|
||||
<div class="title">
|
||||
<h3><?= __('Access Tokens', 'gitea') ?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
<p><?= __('The access token from a repository always have priority over the global.', 'gitea') ?></p>
|
||||
</div>
|
||||
|
||||
<ul class="gitea">
|
||||
<?php $r = 0; foreach ($repositories as $repository => $packages) : $r++;?>
|
||||
<li class="repo-row repo-<?=$r?>">
|
||||
<ul>
|
||||
<li class="repository">
|
||||
<strong><a href="#" class="repo-toggle" data-repo="<?=$r?>"><?=parse_url($repository)['host']?></a></strong>
|
||||
<a href="<?=$repository?>"><span class="dashicons dashicons-external"></span></a>
|
||||
</li>
|
||||
<li>
|
||||
<input type="password" class="token" name="gitea_options[host_token][<?=$repository?>]" value="<?=@$options['host_token'][$repository]?>" placeholder="<?=__('Global Access Token', 'gitea')?>">
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="striped packages">
|
||||
<?php foreach ($packages as $type => $items) : ?>
|
||||
<?php foreach ($items as $slug => $package) : ?>
|
||||
<li>
|
||||
<ul>
|
||||
<li class="package">
|
||||
<span class="dashicons dashicons-admin-<?=($type == 'plugin' ? 'plugins' : 'appearance')?>"></span>
|
||||
<a href="<?=$package['url']?>"><?=$package['name']?></a>
|
||||
<ul class="gitea">
|
||||
<?php $r = 0;
|
||||
foreach ($repositories as $repository => $packages) : $r++; ?>
|
||||
<li class="repo-row repo-<?= $r ?>">
|
||||
<ul>
|
||||
<li class="repository">
|
||||
<strong><a href="#" class="repo-toggle"
|
||||
data-repo="<?= $r ?>"><?= parse_url($repository)['host'] ?></a></strong>
|
||||
<a href="<?= $repository ?>"><span class="dashicons dashicons-external"></span></a>
|
||||
</li>
|
||||
<li class="input">
|
||||
<input type="password" class="token" name="gitea_options[repo_token][<?=$package['url']?>]" value="<?=@$options['repo_token'][$package['url']]?>" placeholder="<?=__('Access Token', 'gitea')?>">
|
||||
<li>
|
||||
<input type="password" class="token"
|
||||
name="gitea_options[host_token][<?= $repository ?>]"
|
||||
value="<?= @$options['host_token'][$repository] ?>"
|
||||
placeholder="<?= __('Global Access Token', 'gitea') ?>">
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<ul class="striped packages">
|
||||
<?php foreach ($packages as $type => $items) : ?>
|
||||
<?php foreach ($items as $slug => $package) : ?>
|
||||
<li>
|
||||
<ul>
|
||||
<li class="package">
|
||||
<span class="dashicons dashicons-admin-<?= ($type == 'plugin' ? 'plugins' : 'appearance') ?>"></span>
|
||||
<a href="<?= $package['url'] ?>"><?= $package['name'] ?></a>
|
||||
</li>
|
||||
<li class="input">
|
||||
<input type="password" class="token"
|
||||
name="gitea_options[repo_token][<?= $package['url'] ?>]"
|
||||
value="<?= @$options['repo_token'][$package['url']] ?>"
|
||||
placeholder="<?= __('Access Token', 'gitea') ?>">
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<div class="inner">
|
||||
<p class="submit">
|
||||
<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 class="inner">
|
||||
<p class="submit">
|
||||
<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>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</form>
|
||||
<form action="<?= admin_url('options-general.php?page=gitea-updater') ?>" method="post"
|
||||
class="box install">
|
||||
<div class="title">
|
||||
<h3><?= __('Install from URL', 'gitea') ?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
|
||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post" class="box install">
|
||||
<div class="title">
|
||||
<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>
|
||||
|
||||
<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', 'gitea') ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="gitea_install[type]">
|
||||
<option value="plugin"><?= __('Plugins', 'gitea') ?></option>
|
||||
<option value="theme"><?= __('Themes', 'gitea') ?></option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?= __('Repository URL', 'gitea') ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="gitea_install[url]"
|
||||
placeholder="<?= __('https://host/org/repo or https://host/org/repo.git', 'gitea') ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?= __('Access Token', 'gitea') ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<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', 'gitea') ?>">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th>
|
||||
<label><?=__('Type', 'gitea')?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="gitea_install[type]">
|
||||
<option value="plugin"><?=__('Plugins', 'gitea')?></option>
|
||||
<option value="theme"><?=__('Themes', 'gitea')?></option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?=__('Repository URL', 'gitea')?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="gitea_install[url]" placeholder="<?=__('https://host/org/repo or https://host/org/repo.git', 'gitea')?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?=__('Access Token', 'gitea')?></label>
|
||||
</th>
|
||||
<td>
|
||||
<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', 'gitea')?>">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="times">
|
||||
<?= __('Plugins', 'gitea') ?>: <?= date('d/m/Y H:i:s', get_option('gitea_plugins_updated')) ?>
|
||||
<br>
|
||||
<?= __('Themes', 'gitea') ?>: <?= date('d/m/Y H:i:s', get_option('gitea_themes_updated')) ?>
|
||||
</div>
|
||||
|
||||
<div class="times">
|
||||
<?=__('Plugins', 'gitea')?>: <?=date('d/m/Y H:i:s', get_option('gitea_plugins_updated'))?>
|
||||
<br>
|
||||
<?=__('Themes', 'gitea')?>: <?=date('d/m/Y H:i:s', get_option('gitea_themes_updated'))?>
|
||||
</div>
|
||||
<?php /* <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> */ ?>
|
||||
<?php
|
||||
}
|
||||
|
||||
<?php
|
||||
}
|
||||
function get_repositories()
|
||||
{
|
||||
$plugins = (array)get_option('gitea_plugins');
|
||||
$themes = (array)get_option('gitea_themes');
|
||||
|
||||
function get_repositories() {
|
||||
$plugins = (array)get_option('gitea_plugins');
|
||||
$themes = (array)get_option('gitea_themes');
|
||||
$repositories = array();
|
||||
|
||||
$repositories = array();
|
||||
foreach ($plugins as $slug => $plugin) {
|
||||
$plugin['url'] = $plugin['gitea_host'] . $plugin['gitea_repo'];
|
||||
$repositories[$plugin['gitea_host']]['plugin'][$slug] = $plugin;
|
||||
}
|
||||
|
||||
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[$theme['gitea_host']]['theme'][$slug] = $theme;
|
||||
}
|
||||
|
||||
foreach ($themes as $slug => $theme) {
|
||||
$theme['url'] = $theme['gitea_host'].$theme['gitea_repo'];
|
||||
$repositories[$theme['gitea_host']]['theme'][$slug] = $theme;
|
||||
}
|
||||
return $repositories;
|
||||
|
||||
return $repositories;
|
||||
}
|
||||
|
||||
}
|
||||
static function get()
|
||||
{
|
||||
return (array)get_option('gitea_options');
|
||||
}
|
||||
|
||||
static function get() {
|
||||
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'], '/'));
|
||||
|
||||
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_url($host, $repo, '/archive/master.zip', $data['access_token']);
|
||||
|
||||
$updater = Gitea_Updater::getInstance();
|
||||
$package = $updater->get_url($host, $repo, '/archive/master.zip', $data['access_token']);
|
||||
if ($data['type'] == 'plugin') {
|
||||
|
||||
if ($data['type'] == 'plugin') {
|
||||
add_filter('install_plugin_complete_actions', array($this, 'install_actions'));
|
||||
|
||||
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);
|
||||
|
||||
$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, 'install_actions'));
|
||||
|
||||
remove_filter('install_plugin_complete_actions', array($this, 'install_actions'));
|
||||
} elseif ($data['type'] == 'theme') {
|
||||
|
||||
} elseif ($data['type'] == 'theme') {
|
||||
add_filter('install_theme_complete_actions', array($this, 'install_actions'));
|
||||
|
||||
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);
|
||||
|
||||
$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, 'install_actions'));
|
||||
|
||||
remove_filter('install_theme_complete_actions', array($this, 'install_actions'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* Plugin Name: Gitea Updater
|
||||
* Plugin URI: http://www.paucapo.com
|
||||
* Description: Plugins updater
|
||||
* Version: 0.2.2
|
||||
* Version: 0.3
|
||||
* Author: Pau Capó
|
||||
* Author URI: http://www.paucapo.com
|
||||
* Text Domain: gitea
|
||||
|
|
@ -17,337 +17,356 @@
|
|||
*/
|
||||
|
||||
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
defined('ABSPATH') or exit;
|
||||
|
||||
|
||||
require 'gitea-options.php';
|
||||
|
||||
class Gitea_Updater {
|
||||
class Gitea_Updater
|
||||
{
|
||||
|
||||
private static $_instance;
|
||||
private static $_instance;
|
||||
|
||||
public static function getInstance() {
|
||||
if (!(self::$_instance instanceof self)) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!(self::$_instance instanceof self)) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public $plugins = array();
|
||||
public $themes = array();
|
||||
public $plugins = array();
|
||||
public $themes = array();
|
||||
|
||||
function __construct() {
|
||||
function __construct()
|
||||
{
|
||||
|
||||
add_action('plugins_loaded', array($this, 'plugins_loaded'));
|
||||
add_action('plugins_loaded', array($this, 'plugins_loaded'));
|
||||
|
||||
Gitea_Options::getInstance();
|
||||
Gitea_Options::getInstance();
|
||||
|
||||
add_action('admin_init', array($this, 'admin_init'));
|
||||
add_action('admin_init', array($this, 'admin_init'));
|
||||
|
||||
// plugins checks
|
||||
add_filter('plugins_api', array($this, 'plugins_api'), 10, 3);
|
||||
add_filter('pre_set_site_transient_update_plugins', array($this, 'pre_set_site_transient_update_plugins'));
|
||||
// plugins checks
|
||||
add_filter('plugins_api', array($this, 'plugins_api'), 10, 3);
|
||||
add_filter('pre_set_site_transient_update_plugins', array($this, 'pre_set_site_transient_update_plugins'));
|
||||
|
||||
// themes checks
|
||||
add_filter('pre_set_site_transient_update_themes', array($this, 'pre_set_site_transient_update_themes'));
|
||||
// themes checks
|
||||
add_filter('pre_set_site_transient_update_themes', array($this, 'pre_set_site_transient_update_themes'));
|
||||
|
||||
// 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'));
|
||||
// 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'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function admin_init() {
|
||||
if (!get_option('gitea_plugins') || !get_option('gitea_plugins'))
|
||||
$this->get_all();
|
||||
}
|
||||
function admin_init()
|
||||
{
|
||||
if (get_option('gitea_plugins_updated') === false || get_option('gitea_themes_updated') === false)
|
||||
{
|
||||
$this->get_all();
|
||||
}
|
||||
}
|
||||
|
||||
function plugins_loaded() {
|
||||
load_plugin_textdomain('gitea', FALSE, basename( dirname( __FILE__ ) ) . '/languages/');
|
||||
}
|
||||
function plugins_loaded()
|
||||
{
|
||||
load_plugin_textdomain('gitea', FALSE, basename(dirname(__FILE__)) . '/languages/');
|
||||
}
|
||||
|
||||
function get_all() {
|
||||
$this->get_plugins();
|
||||
$this->get_themes();
|
||||
}
|
||||
function get_all()
|
||||
{
|
||||
$this->get_plugins();
|
||||
$this->get_themes();
|
||||
}
|
||||
|
||||
function get_plugins() {
|
||||
$this->plugins = array();
|
||||
$plugins = get_plugins();
|
||||
function get_plugins()
|
||||
{
|
||||
$this->plugins = array();
|
||||
$plugins = get_plugins();
|
||||
|
||||
foreach ($plugins as $plugin_slug => $plugin) {
|
||||
foreach ($plugins as $plugin_slug => $plugin) {
|
||||
|
||||
if (!empty($plugin['Gitea URI']) && !empty($plugin['Gitea Host'])) {
|
||||
if (!empty($plugin['Gitea URI']) && !empty($plugin['Gitea Host'])) {
|
||||
|
||||
// this is a gitea plugin
|
||||
// this is a gitea plugin
|
||||
|
||||
$slug = trim(dirname($plugin_slug), '/');
|
||||
$file = basename($plugin_slug);
|
||||
$host = $this->get_host($plugin['Gitea Host']);
|
||||
$repo = $plugin['Gitea URI'];
|
||||
$local_version = strtolower($plugin['Version']);
|
||||
$slug = trim(dirname($plugin_slug), '/');
|
||||
$file = basename($plugin_slug);
|
||||
$host = $this->get_host($plugin['Gitea Host']);
|
||||
$repo = $plugin['Gitea URI'];
|
||||
$local_version = strtolower($plugin['Version']);
|
||||
|
||||
$url = $this->get_url($host, $repo, '/raw/master/' . $file);
|
||||
if ($url != false) {
|
||||
$new_version = $this->get_version($url, 'plugin');
|
||||
}
|
||||
$new_version = isset($new_version) && $new_version ? $new_version : $local_version;
|
||||
|
||||
// here we have the remote version from gitea/repo/plugin_file
|
||||
|
||||
// building the plugin data
|
||||
$gitea = array(
|
||||
'plugin' => $plugin_slug,
|
||||
'slug' => $slug,
|
||||
'file' => $file,
|
||||
'name' => $plugin['Name'],
|
||||
'gitea_host' => $host,
|
||||
'gitea_repo' => $repo,
|
||||
'description' => $plugin['Description'],
|
||||
'url' => $host . $repo,
|
||||
'local_version' => $local_version,
|
||||
'new_version' => $new_version,
|
||||
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
|
||||
);
|
||||
|
||||
$this->plugins[$slug] = $gitea;
|
||||
|
||||
$url = $this->get_url($host, $repo, '/raw/master/'.$file);
|
||||
if ($url != false) {
|
||||
$new_version = $this->get_version($url, 'plugin');
|
||||
}
|
||||
$new_version = isset($new_version) && $new_version ? $new_version : $local_version;
|
||||
}
|
||||
|
||||
// here we have the remote version from gitea/repo/plugin_file
|
||||
update_option('gitea_plugins', $this->plugins);
|
||||
update_option('gitea_plugins_updated', time());
|
||||
|
||||
// building the plugin data
|
||||
$gitea = array(
|
||||
'plugin' => $plugin_slug,
|
||||
'slug' => $slug,
|
||||
'file' => $file,
|
||||
'name' => $plugin['Name'],
|
||||
'gitea_host' => $host,
|
||||
'gitea_repo' => $repo,
|
||||
'description' => $plugin['Description'],
|
||||
'url' => $host.$repo,
|
||||
'local_version' => $local_version,
|
||||
'new_version' => $new_version,
|
||||
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
|
||||
);
|
||||
}
|
||||
|
||||
$this->plugins[$slug] = $gitea;
|
||||
function get_themes()
|
||||
{
|
||||
$this->themes = array();
|
||||
$themes = wp_get_themes();
|
||||
|
||||
}
|
||||
}
|
||||
foreach ($themes as $theme) {
|
||||
|
||||
update_option('gitea_plugins', $this->plugins);
|
||||
update_option('gitea_plugins_updated', time());
|
||||
if ($theme->get('Gitea Host') != '' && $theme->get('Gitea URI')) {
|
||||
|
||||
}
|
||||
// this is a gitea theme
|
||||
|
||||
function get_themes() {
|
||||
$this->themes = array();
|
||||
$themes = wp_get_themes();
|
||||
$slug = $theme->stylesheet;
|
||||
$host = $this->get_host($theme->get('Gitea Host'));
|
||||
$repo = $theme->get('Gitea URI');
|
||||
$local_version = strtolower($theme->get('Version'));
|
||||
|
||||
foreach ( $themes as $theme ) {
|
||||
$url = $this->get_url($host, $repo, '/raw/master/style.css');
|
||||
if ($url != false) {
|
||||
$new_version = $this->get_version($url, 'plugin');
|
||||
$new_version = $new_version ? $new_version : $local_version;
|
||||
}
|
||||
|
||||
if ($theme->get('Gitea Host') != '' && $theme->get('Gitea URI')) {
|
||||
// here we have the remote version from gitea/repo/style.css
|
||||
|
||||
// this is a gitea theme
|
||||
// building the theme data
|
||||
$gitea = array(
|
||||
'slug' => $slug,
|
||||
'name' => $theme->get('Name'),
|
||||
'gitea_host' => $host,
|
||||
'gitea_repo' => $repo,
|
||||
'description' => $theme->get('Description'),
|
||||
'author' => $theme->get('Author'),
|
||||
'url' => $theme->get('AuthorURI'),//$host.$repo,
|
||||
'local_version' => $local_version,
|
||||
'new_version' => $new_version,
|
||||
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
|
||||
);
|
||||
|
||||
$slug = $theme->stylesheet;
|
||||
$host = $this->get_host($theme->get('Gitea Host'));
|
||||
$repo = $theme->get('Gitea URI');
|
||||
$local_version = strtolower($theme->get('Version'));
|
||||
|
||||
$url = $this->get_url($host, $repo, '/raw/master/style.css');
|
||||
if ($url != false) {
|
||||
$new_version = $this->get_version($url, 'plugin');
|
||||
$new_version = $new_version ? $new_version : $local_version;
|
||||
$this->themes[$slug] = $gitea;
|
||||
}
|
||||
|
||||
// here we have the remote version from gitea/repo/style.css
|
||||
}
|
||||
|
||||
// building the theme data
|
||||
$gitea = array(
|
||||
'slug' => $slug,
|
||||
'name' => $theme->get('Name'),
|
||||
'gitea_host' => $host,
|
||||
'gitea_repo' => $repo,
|
||||
'description' => $theme->get('Description'),
|
||||
'author' => $theme->get('Author'),
|
||||
'url' => $theme->get('AuthorURI'),//$host.$repo,
|
||||
'local_version' => $local_version,
|
||||
'new_version' => $new_version,
|
||||
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
|
||||
);
|
||||
update_option('gitea_themes', $this->themes);
|
||||
update_option('gitea_themes_updated', time());
|
||||
|
||||
$this->themes[$slug] = $gitea;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
function get_host($host)
|
||||
{
|
||||
return rtrim($host, '/') . '/';
|
||||
}
|
||||
|
||||
update_option('gitea_themes', $this->themes);
|
||||
update_option('gitea_themes_updated', time());
|
||||
function get_token($host, $repo)
|
||||
{
|
||||
$options = Gitea_Options::get();
|
||||
$token = '';
|
||||
|
||||
}
|
||||
// get repo token
|
||||
if (isset($options['repo_token'][$host . $repo]))
|
||||
$token = $options['repo_token'][$host . $repo];
|
||||
|
||||
function get_host($host) {
|
||||
return rtrim($host, '/').'/';
|
||||
}
|
||||
// get host token if repo is empty
|
||||
if (empty($token) && isset($options['host_token'][$host]))
|
||||
$token = $options['host_token'][$host];
|
||||
|
||||
function get_token($host, $repo) {
|
||||
$options = Gitea_Options::get();
|
||||
$token = '';
|
||||
// return token or false if empty
|
||||
return !empty($token) ? $token : false;
|
||||
}
|
||||
|
||||
// get repo token
|
||||
if (isset($options['repo_token'][$host.$repo]))
|
||||
$token = $options['repo_token'][$host.$repo];
|
||||
function get_url($host, $repo, $args = '', $access_token = false)
|
||||
{
|
||||
|
||||
// get host token if repo is empty
|
||||
if (empty($token) && isset($options['host_token'][$host]))
|
||||
$token = $options['host_token'][$host];
|
||||
if ($access_token === false) {
|
||||
$access_token = $this->get_token($host, $repo);
|
||||
if (!$access_token) return false;
|
||||
}
|
||||
|
||||
// return token or false if empty
|
||||
return !empty($token) ? $token : false;
|
||||
}
|
||||
return $host . 'api/v1/repos/' . $repo . $args . '?access_token=' . $access_token;
|
||||
}
|
||||
|
||||
function get_url($host, $repo, $args = '', $access_token = false) {
|
||||
function get_file($url)
|
||||
{
|
||||
$request = wp_remote_get($url);
|
||||
|
||||
if ($access_token === false) {
|
||||
$access_token = $this->get_token($host, $repo);
|
||||
if (!$access_token) return false;
|
||||
}
|
||||
if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $host.'api/v1/repos/'.$repo.$args.'?access_token='.$access_token;
|
||||
}
|
||||
// in $request['body'] we have the content from the file
|
||||
return $request;
|
||||
}
|
||||
|
||||
function get_file($url) {
|
||||
$request = wp_remote_get($url);
|
||||
function get_version($url, $type)
|
||||
{
|
||||
|
||||
if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
|
||||
return false;
|
||||
}
|
||||
$request = $this->get_file($url);
|
||||
|
||||
// in $request['body'] we have the content from the file
|
||||
return $request;
|
||||
}
|
||||
if (!$request) return false;
|
||||
|
||||
function get_version($url, $type) {
|
||||
// get the headers
|
||||
$headers = $this->get_file_headers($request['body'], $type);
|
||||
|
||||
$request = $this->get_file($url);
|
||||
return isset($headers['Version']) ? $headers['Version'] : false;
|
||||
}
|
||||
|
||||
if (!$request) return false;
|
||||
function plugins_api($default = false, $action, $args)
|
||||
{
|
||||
if ('plugin_information' != $action)
|
||||
return $default;
|
||||
|
||||
// get the headers
|
||||
$headers = $this->get_file_headers($request['body'], $type);
|
||||
if (!isset($this->plugins[$args->slug]))
|
||||
return $default;
|
||||
|
||||
return isset($headers['Version']) ? $headers['Version'] : false;
|
||||
}
|
||||
// plugin information (view notes befor update)
|
||||
|
||||
function plugins_api($default = false, $action, $args) {
|
||||
if ('plugin_information' != $action)
|
||||
return $default;
|
||||
$plugin = $this->plugins[$args->slug];
|
||||
|
||||
if (!isset($this->plugins[$args->slug]))
|
||||
return $default;
|
||||
return (object)array(
|
||||
'name' => $plugin['name'],
|
||||
'slug' => $plugin['plugin'],
|
||||
'version' => $plugin['new_version'],
|
||||
'sections' => array(
|
||||
'description' => $plugin['description']
|
||||
),
|
||||
'download_link' => $plugin['package'],
|
||||
'homepage' => $plugin['url'],
|
||||
);
|
||||
|
||||
// plugin information (view notes befor update)
|
||||
}
|
||||
|
||||
$plugin = $this->plugins[$args->slug];
|
||||
function pre_set_site_transient_update_plugins($transient)
|
||||
{
|
||||
// check if some plugin needs update
|
||||
|
||||
return (object) array(
|
||||
'name' => $plugin['name'],
|
||||
'slug' => $plugin['plugin'],
|
||||
'version' => $plugin['new_version'],
|
||||
'sections' => array(
|
||||
'description' => $plugin['description']
|
||||
),
|
||||
'download_link' => $plugin['package'],
|
||||
'homepage' => $plugin['url'],
|
||||
);
|
||||
$this->get_plugins();
|
||||
|
||||
}
|
||||
foreach ($this->plugins as $plugin => $git_plugin) {
|
||||
|
||||
function pre_set_site_transient_update_plugins($transient) {
|
||||
// check if some plugin needs update
|
||||
if (isset($transient->response[$git_plugin['plugin']]))
|
||||
unset($transient->response[$git_plugin['plugin']]);
|
||||
if (version_compare($git_plugin['local_version'], $git_plugin['new_version'], '<')) {
|
||||
$transient->response[$git_plugin['plugin']] = (object)$git_plugin;
|
||||
}
|
||||
|
||||
$this->get_plugins();
|
||||
}
|
||||
|
||||
foreach ($this->plugins as $plugin => $git_plugin) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
if (isset($transient->response[$git_plugin['plugin']]))
|
||||
unset($transient->response[$git_plugin['plugin']]);
|
||||
if (version_compare($git_plugin['local_version'], $git_plugin['new_version'], '<')) {
|
||||
$transient->response[$git_plugin['plugin']] = (object)$git_plugin;
|
||||
}
|
||||
function pre_set_site_transient_update_themes($transient)
|
||||
{
|
||||
// check if some theme needs update
|
||||
|
||||
}
|
||||
$this->get_themes();
|
||||
|
||||
return $transient;
|
||||
}
|
||||
foreach ($this->themes as $theme => $git_theme) {
|
||||
|
||||
function pre_set_site_transient_update_themes($transient) {
|
||||
// check if some theme needs update
|
||||
if (isset($transient->response[$theme]))
|
||||
unset($transient->response[$theme]);
|
||||
if (version_compare($git_theme['local_version'], $git_theme['new_version'], '<')) {
|
||||
$transient->response[$theme] = (array)$git_theme;
|
||||
}
|
||||
|
||||
$this->get_themes();
|
||||
}
|
||||
|
||||
foreach ($this->themes as $theme => $git_theme) {
|
||||
return $transient;
|
||||
}
|
||||
|
||||
if (isset($transient->response[$theme]))
|
||||
unset($transient->response[$theme]);
|
||||
if (version_compare($git_theme['local_version'], $git_theme['new_version'], '<')) {
|
||||
$transient->response[$theme] = (array)$git_theme;
|
||||
}
|
||||
function get_file_headers($contents, $type)
|
||||
{
|
||||
|
||||
}
|
||||
$gitea_headers = array(
|
||||
'GiteaHost' => 'Gitea Host',
|
||||
'GiteaUri' => 'Gitea URI',
|
||||
);
|
||||
|
||||
return $transient;
|
||||
}
|
||||
$default_plugin_headers = array(
|
||||
'Name' => 'Plugin Name',
|
||||
'PluginURI' => 'Plugin URI',
|
||||
'Version' => 'Version',
|
||||
'Description' => 'Description',
|
||||
'Author' => 'Author',
|
||||
'AuthorURI' => 'Author URI',
|
||||
'TextDomain' => 'Text Domain',
|
||||
'DomainPath' => 'Domain Path',
|
||||
'Network' => 'Network',
|
||||
);
|
||||
|
||||
function get_file_headers($contents, $type) {
|
||||
$default_theme_headers = array(
|
||||
'Name' => 'Theme Name',
|
||||
'ThemeURI' => 'Theme URI',
|
||||
'Description' => 'Description',
|
||||
'Author' => 'Author',
|
||||
'AuthorURI' => 'Author URI',
|
||||
'Version' => 'Version',
|
||||
'Template' => 'Template',
|
||||
'Status' => 'Status',
|
||||
'Tags' => 'Tags',
|
||||
'TextDomain' => 'Text Domain',
|
||||
'DomainPath' => 'Domain Path',
|
||||
);
|
||||
|
||||
$gitea_headers = array(
|
||||
'GiteaHost' => 'Gitea Host',
|
||||
'GiteaUri' => 'Gitea URI',
|
||||
);
|
||||
if (false !== strpos($type, 'plugin')) {
|
||||
$all_headers = $default_plugin_headers;
|
||||
}
|
||||
|
||||
$default_plugin_headers = array(
|
||||
'Name' => 'Plugin Name',
|
||||
'PluginURI' => 'Plugin URI',
|
||||
'Version' => 'Version',
|
||||
'Description' => 'Description',
|
||||
'Author' => 'Author',
|
||||
'AuthorURI' => 'Author URI',
|
||||
'TextDomain' => 'Text Domain',
|
||||
'DomainPath' => 'Domain Path',
|
||||
'Network' => 'Network',
|
||||
);
|
||||
if (false !== strpos($type, 'theme')) {
|
||||
$all_headers = $default_theme_headers;
|
||||
}
|
||||
|
||||
$default_theme_headers = array(
|
||||
'Name' => 'Theme Name',
|
||||
'ThemeURI' => 'Theme URI',
|
||||
'Description' => 'Description',
|
||||
'Author' => 'Author',
|
||||
'AuthorURI' => 'Author URI',
|
||||
'Version' => 'Version',
|
||||
'Template' => 'Template',
|
||||
'Status' => 'Status',
|
||||
'Tags' => 'Tags',
|
||||
'TextDomain' => 'Text Domain',
|
||||
'DomainPath' => 'Domain Path',
|
||||
);
|
||||
$file_data = str_replace("\r", "\n", $contents);
|
||||
|
||||
if (false !== strpos($type, 'plugin')) {
|
||||
$all_headers = $default_plugin_headers;
|
||||
}
|
||||
$all_headers = array_merge($gitea_headers, (array)$all_headers);
|
||||
$all_headers = array_unique($all_headers);
|
||||
|
||||
if (false !== strpos($type, 'theme')) {
|
||||
$all_headers = $default_theme_headers;
|
||||
}
|
||||
foreach ($all_headers as $field => $regex) {
|
||||
if (preg_match('/^[ \t\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match) && $match[1]) {
|
||||
$all_headers[$field] = _cleanup_header_comment($match[1]);
|
||||
} else {
|
||||
$all_headers[$field] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$file_data = str_replace("\r", "\n", $contents);
|
||||
$all_headers = array_filter($all_headers,
|
||||
function ($e) use (&$all_headers) {
|
||||
return !empty($e);
|
||||
});
|
||||
|
||||
$all_headers = array_merge($gitea_headers, (array) $all_headers);
|
||||
$all_headers = array_unique($all_headers);
|
||||
return $all_headers;
|
||||
}
|
||||
|
||||
foreach ($all_headers as $field => $regex) {
|
||||
if (preg_match( '/^[ \t\/*#@]*'.preg_quote($regex, '/').':(.*)$/mi', $file_data, $match) && $match[1]) {
|
||||
$all_headers[$field] = _cleanup_header_comment($match[1]);
|
||||
} else {
|
||||
$all_headers[$field] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$all_headers = array_filter($all_headers,
|
||||
function($e) use (&$all_headers) {
|
||||
return !empty($e);
|
||||
});
|
||||
|
||||
return $all_headers;
|
||||
}
|
||||
|
||||
function extra_headers($headers) {
|
||||
$headers[] = 'Gitea URI';
|
||||
$headers[] = 'Gitea Host';
|
||||
return $headers;
|
||||
}
|
||||
function extra_headers($headers)
|
||||
{
|
||||
$headers[] = 'Gitea URI';
|
||||
$headers[] = 'Gitea Host';
|
||||
return $headers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue