localization
This commit is contained in:
parent
67981c517d
commit
40513e3169
8 changed files with 337 additions and 29 deletions
|
|
@ -6,6 +6,7 @@ Description: Plugins updater
|
|||
Version: 0.1.1
|
||||
Author: Pau Capó
|
||||
Author URI: http://www.paucapo.com
|
||||
Text Domain: gitea
|
||||
Gitea Host: https://git.paucapo.com
|
||||
Gitea URI: wp/gitea-updater
|
||||
*/
|
||||
|
|
@ -40,6 +41,8 @@ class Gitea_Updater {
|
|||
|
||||
function __construct() {
|
||||
|
||||
add_action('plugins_loaded', array($this, 'plugins_loaded'));
|
||||
|
||||
Gitea_Options::getInstance();
|
||||
|
||||
// plugins checks
|
||||
|
|
@ -55,12 +58,16 @@ class Gitea_Updater {
|
|||
|
||||
}
|
||||
|
||||
function get_gitea_all() {
|
||||
$this->get_gitea_plugins();
|
||||
$this->get_gitea_themes();
|
||||
function plugins_loaded() {
|
||||
load_plugin_textdomain('gitea', FALSE, basename( dirname( __FILE__ ) ) . '/languages/');
|
||||
}
|
||||
|
||||
function get_gitea_plugins() {
|
||||
function get_all() {
|
||||
$this->get_plugins();
|
||||
$this->get_themes();
|
||||
}
|
||||
|
||||
function get_plugins() {
|
||||
$this->plugins = array();
|
||||
$plugins = get_plugins();
|
||||
|
||||
|
|
@ -72,13 +79,13 @@ class Gitea_Updater {
|
|||
|
||||
$slug = trim(dirname($plugin_slug), '/');
|
||||
$file = basename($plugin_slug);
|
||||
$host = $this->get_gitea_host($plugin['Gitea Host']);
|
||||
$host = $this->get_host($plugin['Gitea Host']);
|
||||
$repo = $plugin['Gitea URI'];
|
||||
$local_version = strtolower($plugin['Version']);
|
||||
|
||||
$url = $this->get_gitea_url($host, $repo, '/raw/master/'.$file);
|
||||
$url = $this->get_url($host, $repo, '/raw/master/'.$file);
|
||||
if ($url != false) {
|
||||
$new_version = $this->get_gitea_version($url, 'plugin');
|
||||
$new_version = $this->get_version($url, 'plugin');
|
||||
$new_version = $new_version ? $new_version : $local_version;
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +103,7 @@ class Gitea_Updater {
|
|||
'url' => $host.$repo,
|
||||
'local_version' => $local_version,
|
||||
'new_version' => $new_version,
|
||||
'package' => $this->get_gitea_url($host, $repo, '/archive/master.zip'),
|
||||
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
|
||||
);
|
||||
|
||||
$this->plugins[$slug] = $gitea;
|
||||
|
|
@ -109,7 +116,7 @@ class Gitea_Updater {
|
|||
|
||||
}
|
||||
|
||||
function get_gitea_themes() {
|
||||
function get_themes() {
|
||||
$this->themes = array();
|
||||
$themes = wp_get_themes();
|
||||
|
||||
|
|
@ -120,13 +127,13 @@ class Gitea_Updater {
|
|||
// this is a gitea theme
|
||||
|
||||
$slug = $theme->stylesheet;
|
||||
$host = $this->get_gitea_host($theme->get('Gitea Host'));
|
||||
$host = $this->get_host($theme->get('Gitea Host'));
|
||||
$repo = $theme->get('Gitea URI');
|
||||
$local_version = strtolower($theme->get('Version'));
|
||||
|
||||
$url = $this->get_gitea_url($host, $repo, '/raw/master/style.css');
|
||||
$url = $this->get_url($host, $repo, '/raw/master/style.css');
|
||||
if ($url != false) {
|
||||
$new_version = $this->get_gitea_version($url, 'plugin');
|
||||
$new_version = $this->get_version($url, 'plugin');
|
||||
$new_version = $new_version ? $new_version : $local_version;
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +150,7 @@ class Gitea_Updater {
|
|||
'url' => $theme->get('AuthorURI'),//$host.$repo,
|
||||
'local_version' => $local_version,
|
||||
'new_version' => $new_version,
|
||||
'package' => $this->get_gitea_url($host, $repo, '/archive/master.zip'),
|
||||
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
|
||||
);
|
||||
|
||||
$this->themes[$slug] = $gitea;
|
||||
|
|
@ -156,11 +163,11 @@ class Gitea_Updater {
|
|||
|
||||
}
|
||||
|
||||
function get_gitea_host($host) {
|
||||
function get_host($host) {
|
||||
return rtrim($host, '/').'/';
|
||||
}
|
||||
|
||||
function get_gitea_token($host, $repo) {
|
||||
function get_token($host, $repo) {
|
||||
$options = Gitea_Options::get();
|
||||
$token = '';
|
||||
|
||||
|
|
@ -176,17 +183,17 @@ class Gitea_Updater {
|
|||
return !empty($token) ? $token : false;
|
||||
}
|
||||
|
||||
function get_gitea_url($host, $repo, $args = '', $access_token = false) {
|
||||
function get_url($host, $repo, $args = '', $access_token = false) {
|
||||
|
||||
if ($access_token === false) {
|
||||
$access_token = $this->get_gitea_token($host, $repo);
|
||||
$access_token = $this->get_token($host, $repo);
|
||||
if (!$access_token) return false;
|
||||
}
|
||||
|
||||
return $host.'api/v1/repos/'.$repo.$args.'?access_token='.$access_token;
|
||||
}
|
||||
|
||||
function get_gitea_file($url) {
|
||||
function get_file($url) {
|
||||
$request = wp_remote_get($url);
|
||||
|
||||
if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
|
||||
|
|
@ -197,9 +204,9 @@ class Gitea_Updater {
|
|||
return $request;
|
||||
}
|
||||
|
||||
function get_gitea_version($url, $type) {
|
||||
function get_version($url, $type) {
|
||||
|
||||
$request = $this->get_gitea_file($url);
|
||||
$request = $this->get_file($url);
|
||||
|
||||
if (!$request) return false;
|
||||
|
||||
|
|
@ -236,7 +243,7 @@ class Gitea_Updater {
|
|||
function pre_set_site_transient_update_plugins($transient) {
|
||||
// check if some plugin needs update
|
||||
|
||||
$this->get_gitea_plugins();
|
||||
$this->get_plugins();
|
||||
|
||||
foreach ($this->plugins as $plugin => $git_plugin) {
|
||||
|
||||
|
|
@ -254,7 +261,7 @@ class Gitea_Updater {
|
|||
function pre_set_site_transient_update_themes($transient) {
|
||||
// check if some theme needs update
|
||||
|
||||
$this->get_gitea_themes();
|
||||
$this->get_themes();
|
||||
|
||||
foreach ($this->themes as $theme => $git_theme) {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue