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,27 +1,16 @@
|
||||||
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 () {
|
$('input.token').each(function () {
|
||||||
var token = $(this)
|
var token = $(this);
|
||||||
var toggle = $('<a href="#" class="token-toggle dashicons dashicons-visibility"></a>');
|
var toggle = $('<a href="#" class="token-toggle dashicons dashicons-visibility"></a>');
|
||||||
token.wrap('<span class="token-box"></span>').after(toggle);
|
token.wrap('<span class="token-box"></span>').after(toggle);
|
||||||
toggle.on('click', function () {
|
toggle.on('click', function () {
|
||||||
if (token.attr('type') == 'password') {
|
if (token.attr('type') === 'password') {
|
||||||
token.attr('type', 'text')
|
token.attr('type', 'text');
|
||||||
toggle.addClass('dashicons-hidden').removeClass('dashicons-visibility')
|
toggle.addClass('dashicons-hidden').removeClass('dashicons-visibility');
|
||||||
} else {
|
} else {
|
||||||
token.attr('type', 'password')
|
token.attr('type', 'password');
|
||||||
toggle.addClass('dashicons-visibility').removeClass('dashicons-hidden')
|
toggle.addClass('dashicons-visibility').removeClass('dashicons-hidden');
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
@ -29,8 +18,8 @@ jQuery(document).ready(function($) {
|
||||||
|
|
||||||
$('.repo-toggle').on('click', function () {
|
$('.repo-toggle').on('click', function () {
|
||||||
var id = $(this).data('repo');
|
var id = $(this).data('repo');
|
||||||
$('.repo-'+id).toggleClass('open')
|
$('.repo-' + id).toggleClass('open');
|
||||||
$('.repo-'+id+' > ul.packages').slideToggle(400)
|
$('.repo-' + id + ' > ul.packages').slideToggle(400);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
.wrap {
|
.wrap {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
#show-tokens {
|
#show-tokens {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.box {
|
.box {
|
||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
background: #FFFFFF;
|
background: #FFFFFF;
|
||||||
|
|
@ -11,18 +13,21 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
|
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
|
||||||
}
|
}
|
||||||
|
|
||||||
.box .title {
|
.box .title {
|
||||||
border-bottom: 1px solid #EEEEEE;
|
border-bottom: 1px solid #EEEEEE;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
background: #FFFFFF;
|
background: #FFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
.box .title h3 {
|
.box .title h3 {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 1em;
|
line-height: 1em;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.box .inner {
|
.box .inner {
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
}
|
}
|
||||||
|
|
@ -34,45 +39,54 @@
|
||||||
border-top: 1px solid #e5e5e5;
|
border-top: 1px solid #e5e5e5;
|
||||||
box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
|
box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea > li {
|
.gitea > li {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border-bottom: 1px solid #e5e5e5;
|
border-bottom: 1px solid #e5e5e5;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea > li > ul {
|
.gitea > li > ul {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea > li li {
|
.gitea > li li {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 8px 15px;
|
padding: 8px 15px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
// width: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea ul.packages > li {
|
.gitea ul.packages > li {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea li.repository,
|
.gitea li.repository,
|
||||||
.gitea li.package {
|
.gitea li.package {
|
||||||
width: 210px;
|
width: 210px;
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea a {
|
.gitea a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
outline: 0;
|
outline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea a:focus,
|
.gitea a:focus,
|
||||||
.gitea a:active {
|
.gitea a:active {
|
||||||
outline: 0;
|
outline: 0;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea a.repo-toggle {
|
.gitea a.repo-toggle {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 14px;
|
line-height: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea > li:hover .row-actions {
|
.gitea > li:hover .row-actions {
|
||||||
left: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea input.token {
|
.gitea input.token {
|
||||||
width: 70%;
|
width: 70%;
|
||||||
}
|
}
|
||||||
|
|
@ -89,24 +103,26 @@
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-table input[type=text],
|
.form-table input[type=text],
|
||||||
.form-table input[type=password] {
|
.form-table input[type=password] {
|
||||||
width: 75%;
|
width: 75%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.repo-row > ul.packages {
|
.repo-row > ul.packages {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.repo-row > ul:first-child {
|
.repo-row > ul:first-child {
|
||||||
transition: all 0.4s;
|
transition: all 0.4s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.repo-row.open > ul:first-child {
|
.repo-row.open > ul:first-child {
|
||||||
background: #2a9bd9;
|
background: #2a9bd9;
|
||||||
border-color: #2a9bd9;
|
border-color: #2a9bd9;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.repo-row.open > ul:first-child a {
|
.repo-row.open > ul:first-child a {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
@ -114,6 +130,7 @@
|
||||||
.token-box {
|
.token-box {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.token-toggle {
|
.token-toggle {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
|
|
@ -122,9 +139,11 @@
|
||||||
margin-top: -10px;
|
margin-top: -10px;
|
||||||
color: #aaa !important;
|
color: #aaa !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.token-toggle:hover {
|
.token-toggle:hover {
|
||||||
color: #aaa !important;
|
color: #aaa !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.token-toggle:focus,
|
.token-toggle:focus,
|
||||||
.token-toggle:active {
|
.token-toggle:active {
|
||||||
outline: 0;
|
outline: 0;
|
||||||
|
|
|
||||||
|
|
@ -4,36 +4,42 @@ 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;
|
private static $_instance;
|
||||||
var $page = false;
|
var $page = false;
|
||||||
|
|
||||||
public static function getInstance() {
|
public static function getInstance()
|
||||||
|
{
|
||||||
if (!(self::$_instance instanceof self)) {
|
if (!(self::$_instance instanceof self)) {
|
||||||
self::$_instance = new self();
|
self::$_instance = new self();
|
||||||
}
|
}
|
||||||
return self::$_instance;
|
return self::$_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
function __construct() {
|
function __construct()
|
||||||
|
{
|
||||||
add_action('admin_menu', array($this, 'admin_menu'));
|
add_action('admin_menu', array($this, 'admin_menu'));
|
||||||
add_action('admin_enqueue_scripts', array($this, 'enqueue_assets'));
|
add_action('admin_enqueue_scripts', array($this, 'enqueue_assets'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function admin_menu() {
|
function admin_menu()
|
||||||
|
{
|
||||||
$this->page = add_options_page('Gitea Updater', 'Gitea Updater', 'manage_options', 'gitea-updater', array($this, 'options_page'));
|
$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'));
|
add_action('load-' . $this->page, array($this, 'options_post'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function enqueue_assets($hook) {
|
function enqueue_assets($hook)
|
||||||
|
{
|
||||||
if ($hook != $this->page) return;
|
if ($hook != $this->page) return;
|
||||||
|
|
||||||
wp_enqueue_style('gitea-updater', plugins_url('/assets/style.css', __FILE__));
|
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_script('gitea-js', plugins_url('/assets/script.js', __FILE__), array('jquery'), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function options_post() {
|
function options_post()
|
||||||
|
{
|
||||||
|
|
||||||
if (isset($_GET['force-check'])) {
|
if (isset($_GET['force-check'])) {
|
||||||
Gitea_Updater::getInstance()->get_all();
|
Gitea_Updater::getInstance()->get_all();
|
||||||
|
|
@ -46,7 +52,8 @@ class Gitea_Options {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function options_page() {
|
function options_page()
|
||||||
|
{
|
||||||
$options = (array)get_option('gitea_options');
|
$options = (array)get_option('gitea_options');
|
||||||
$repositories = $this->get_repositories();
|
$repositories = $this->get_repositories();
|
||||||
$types = array(
|
$types = array(
|
||||||
|
|
@ -69,7 +76,8 @@ class Gitea_Options {
|
||||||
</div>
|
</div>
|
||||||
<?php else : ?>
|
<?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">
|
<div class="title">
|
||||||
<h3><?= __('Access Tokens', 'gitea') ?></h3>
|
<h3><?= __('Access Tokens', 'gitea') ?></h3>
|
||||||
|
|
@ -79,15 +87,20 @@ class Gitea_Options {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="gitea">
|
<ul class="gitea">
|
||||||
<?php $r = 0; foreach ($repositories as $repository => $packages) : $r++;?>
|
<?php $r = 0;
|
||||||
|
foreach ($repositories as $repository => $packages) : $r++; ?>
|
||||||
<li class="repo-row repo-<?= $r ?>">
|
<li class="repo-row repo-<?= $r ?>">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="repository">
|
<li class="repository">
|
||||||
<strong><a href="#" class="repo-toggle" data-repo="<?=$r?>"><?=parse_url($repository)['host']?></a></strong>
|
<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>
|
<a href="<?= $repository ?>"><span class="dashicons dashicons-external"></span></a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="password" class="token" name="gitea_options[host_token][<?=$repository?>]" value="<?=@$options['host_token'][$repository]?>" placeholder="<?=__('Global Access Token', 'gitea')?>">
|
<input type="password" class="token"
|
||||||
|
name="gitea_options[host_token][<?= $repository ?>]"
|
||||||
|
value="<?= @$options['host_token'][$repository] ?>"
|
||||||
|
placeholder="<?= __('Global Access Token', 'gitea') ?>">
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="striped packages">
|
<ul class="striped packages">
|
||||||
|
|
@ -100,7 +113,10 @@ class Gitea_Options {
|
||||||
<a href="<?= $package['url'] ?>"><?= $package['name'] ?></a>
|
<a href="<?= $package['url'] ?>"><?= $package['name'] ?></a>
|
||||||
</li>
|
</li>
|
||||||
<li class="input">
|
<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')?>">
|
<input type="password" class="token"
|
||||||
|
name="gitea_options[repo_token][<?= $package['url'] ?>]"
|
||||||
|
value="<?= @$options['repo_token'][$package['url']] ?>"
|
||||||
|
placeholder="<?= __('Access Token', 'gitea') ?>">
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
@ -114,15 +130,18 @@ class Gitea_Options {
|
||||||
|
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<p class="submit">
|
<p class="submit">
|
||||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?=__('Save Changes', 'gitea')?>">
|
<input type="submit" name="submit" id="submit" class="button button-primary"
|
||||||
<a href="<?=admin_url('options-general.php?page=gitea-updater&force-check=1')?>" class="button button-primary"><?=__('Reset Cache', 'gitea')?></a>
|
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>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form action="<?=admin_url('options-general.php?page=gitea-updater')?>" method="post" class="box install">
|
<form action="<?= admin_url('options-general.php?page=gitea-updater') ?>" method="post"
|
||||||
|
class="box install">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<h3><?= __('Install from URL', 'gitea') ?></h3>
|
<h3><?= __('Install from URL', 'gitea') ?></h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -147,7 +166,8 @@ class Gitea_Options {
|
||||||
<label><?= __('Repository URL', 'gitea') ?></label>
|
<label><?= __('Repository URL', 'gitea') ?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="gitea_install[url]" placeholder="<?=__('https://host/org/repo or https://host/org/repo.git', 'gitea')?>">
|
<input type="text" name="gitea_install[url]"
|
||||||
|
placeholder="<?= __('https://host/org/repo or https://host/org/repo.git', 'gitea') ?>">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -161,7 +181,8 @@ class Gitea_Options {
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<td>
|
<td>
|
||||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?=__('Install Now', 'gitea')?>">
|
<input type="submit" name="submit" id="submit" class="button button-primary"
|
||||||
|
value="<?= __('Install Now', 'gitea') ?>">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
@ -182,7 +203,8 @@ class Gitea_Options {
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_repositories() {
|
function get_repositories()
|
||||||
|
{
|
||||||
$plugins = (array)get_option('gitea_plugins');
|
$plugins = (array)get_option('gitea_plugins');
|
||||||
$themes = (array)get_option('gitea_themes');
|
$themes = (array)get_option('gitea_themes');
|
||||||
|
|
||||||
|
|
@ -202,11 +224,13 @@ class Gitea_Options {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get() {
|
static function get()
|
||||||
|
{
|
||||||
return (array)get_option('gitea_options');
|
return (array)get_option('gitea_options');
|
||||||
}
|
}
|
||||||
|
|
||||||
function install($data) {
|
function install($data)
|
||||||
|
{
|
||||||
$url = parse_url($data['url']);
|
$url = parse_url($data['url']);
|
||||||
$host = $url['scheme'] . '://' . $url['host'] . '/';
|
$host = $url['scheme'] . '://' . $url['host'] . '/';
|
||||||
$repo = str_replace('.git', '', trim($url['path'], '/'));
|
$repo = str_replace('.git', '', trim($url['path'], '/'));
|
||||||
|
|
@ -236,7 +260,8 @@ class Gitea_Options {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_actions($install_actions) {
|
function install_actions($install_actions)
|
||||||
|
{
|
||||||
unset($install_actions['plugins_page'], $install_actions['themes_page']);
|
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>';
|
$install_actions['gitea_page'] = '<a href="' . admin_url('options-general.php?page=gitea-updater') . '" target="_parent">' . __('Return', 'gitea') . '</a>';
|
||||||
return $install_actions;
|
return $install_actions;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* Plugin Name: Gitea Updater
|
* Plugin Name: Gitea Updater
|
||||||
* Plugin URI: http://www.paucapo.com
|
* Plugin URI: http://www.paucapo.com
|
||||||
* Description: Plugins updater
|
* Description: Plugins updater
|
||||||
* Version: 0.2.2
|
* Version: 0.3
|
||||||
* Author: Pau Capó
|
* Author: Pau Capó
|
||||||
* Author URI: http://www.paucapo.com
|
* Author URI: http://www.paucapo.com
|
||||||
* Text Domain: gitea
|
* Text Domain: gitea
|
||||||
|
|
@ -17,17 +17,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
defined('ABSPATH') or exit;
|
defined('ABSPATH') or exit;
|
||||||
|
|
||||||
|
|
||||||
require 'gitea-options.php';
|
require 'gitea-options.php';
|
||||||
|
|
||||||
class Gitea_Updater {
|
class Gitea_Updater
|
||||||
|
{
|
||||||
|
|
||||||
private static $_instance;
|
private static $_instance;
|
||||||
|
|
||||||
public static function getInstance() {
|
public static function getInstance()
|
||||||
|
{
|
||||||
if (!(self::$_instance instanceof self)) {
|
if (!(self::$_instance instanceof self)) {
|
||||||
self::$_instance = new self();
|
self::$_instance = new self();
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +38,8 @@ class Gitea_Updater {
|
||||||
public $plugins = array();
|
public $plugins = array();
|
||||||
public $themes = array();
|
public $themes = array();
|
||||||
|
|
||||||
function __construct() {
|
function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
add_action('plugins_loaded', array($this, 'plugins_loaded'));
|
add_action('plugins_loaded', array($this, 'plugins_loaded'));
|
||||||
|
|
||||||
|
|
@ -58,21 +60,27 @@ class Gitea_Updater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function admin_init() {
|
function admin_init()
|
||||||
if (!get_option('gitea_plugins') || !get_option('gitea_plugins'))
|
{
|
||||||
|
if (get_option('gitea_plugins_updated') === false || get_option('gitea_themes_updated') === false)
|
||||||
|
{
|
||||||
$this->get_all();
|
$this->get_all();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function plugins_loaded() {
|
function plugins_loaded()
|
||||||
|
{
|
||||||
load_plugin_textdomain('gitea', FALSE, basename(dirname(__FILE__)) . '/languages/');
|
load_plugin_textdomain('gitea', FALSE, basename(dirname(__FILE__)) . '/languages/');
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_all() {
|
function get_all()
|
||||||
|
{
|
||||||
$this->get_plugins();
|
$this->get_plugins();
|
||||||
$this->get_themes();
|
$this->get_themes();
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_plugins() {
|
function get_plugins()
|
||||||
|
{
|
||||||
$this->plugins = array();
|
$this->plugins = array();
|
||||||
$plugins = get_plugins();
|
$plugins = get_plugins();
|
||||||
|
|
||||||
|
|
@ -121,7 +129,8 @@ class Gitea_Updater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_themes() {
|
function get_themes()
|
||||||
|
{
|
||||||
$this->themes = array();
|
$this->themes = array();
|
||||||
$themes = wp_get_themes();
|
$themes = wp_get_themes();
|
||||||
|
|
||||||
|
|
@ -168,11 +177,13 @@ class Gitea_Updater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_host($host) {
|
function get_host($host)
|
||||||
|
{
|
||||||
return rtrim($host, '/') . '/';
|
return rtrim($host, '/') . '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_token($host, $repo) {
|
function get_token($host, $repo)
|
||||||
|
{
|
||||||
$options = Gitea_Options::get();
|
$options = Gitea_Options::get();
|
||||||
$token = '';
|
$token = '';
|
||||||
|
|
||||||
|
|
@ -188,7 +199,8 @@ class Gitea_Updater {
|
||||||
return !empty($token) ? $token : false;
|
return !empty($token) ? $token : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_url($host, $repo, $args = '', $access_token = false) {
|
function get_url($host, $repo, $args = '', $access_token = false)
|
||||||
|
{
|
||||||
|
|
||||||
if ($access_token === false) {
|
if ($access_token === false) {
|
||||||
$access_token = $this->get_token($host, $repo);
|
$access_token = $this->get_token($host, $repo);
|
||||||
|
|
@ -198,7 +210,8 @@ class Gitea_Updater {
|
||||||
return $host . 'api/v1/repos/' . $repo . $args . '?access_token=' . $access_token;
|
return $host . 'api/v1/repos/' . $repo . $args . '?access_token=' . $access_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_file($url) {
|
function get_file($url)
|
||||||
|
{
|
||||||
$request = wp_remote_get($url);
|
$request = wp_remote_get($url);
|
||||||
|
|
||||||
if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
|
if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
|
||||||
|
|
@ -209,7 +222,8 @@ class Gitea_Updater {
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_version($url, $type) {
|
function get_version($url, $type)
|
||||||
|
{
|
||||||
|
|
||||||
$request = $this->get_file($url);
|
$request = $this->get_file($url);
|
||||||
|
|
||||||
|
|
@ -221,7 +235,8 @@ class Gitea_Updater {
|
||||||
return isset($headers['Version']) ? $headers['Version'] : false;
|
return isset($headers['Version']) ? $headers['Version'] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugins_api($default = false, $action, $args) {
|
function plugins_api($default = false, $action, $args)
|
||||||
|
{
|
||||||
if ('plugin_information' != $action)
|
if ('plugin_information' != $action)
|
||||||
return $default;
|
return $default;
|
||||||
|
|
||||||
|
|
@ -245,7 +260,8 @@ class Gitea_Updater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function pre_set_site_transient_update_plugins($transient) {
|
function pre_set_site_transient_update_plugins($transient)
|
||||||
|
{
|
||||||
// check if some plugin needs update
|
// check if some plugin needs update
|
||||||
|
|
||||||
$this->get_plugins();
|
$this->get_plugins();
|
||||||
|
|
@ -263,7 +279,8 @@ class Gitea_Updater {
|
||||||
return $transient;
|
return $transient;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pre_set_site_transient_update_themes($transient) {
|
function pre_set_site_transient_update_themes($transient)
|
||||||
|
{
|
||||||
// check if some theme needs update
|
// check if some theme needs update
|
||||||
|
|
||||||
$this->get_themes();
|
$this->get_themes();
|
||||||
|
|
@ -281,7 +298,8 @@ class Gitea_Updater {
|
||||||
return $transient;
|
return $transient;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_file_headers($contents, $type) {
|
function get_file_headers($contents, $type)
|
||||||
|
{
|
||||||
|
|
||||||
$gitea_headers = array(
|
$gitea_headers = array(
|
||||||
'GiteaHost' => 'Gitea Host',
|
'GiteaHost' => 'Gitea Host',
|
||||||
|
|
@ -343,7 +361,8 @@ class Gitea_Updater {
|
||||||
return $all_headers;
|
return $all_headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extra_headers($headers) {
|
function extra_headers($headers)
|
||||||
|
{
|
||||||
$headers[] = 'Gitea URI';
|
$headers[] = 'Gitea URI';
|
||||||
$headers[] = 'Gitea Host';
|
$headers[] = 'Gitea Host';
|
||||||
return $headers;
|
return $headers;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue