fix themes

This commit is contained in:
Pau Capó 2022-02-02 20:38:08 +01:00
parent bd854a504f
commit fd736b5acd

View file

@ -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.3.7 * Version: 0.3.8
* Author: Pau Capó * Author: Pau Capó
* Author URI: http://www.paucapo.com * Author URI: http://www.paucapo.com
* Text Domain: gitea * Text Domain: gitea
@ -172,21 +172,21 @@ class Gitea_Updater
function get_themes() function get_themes()
{ {
$this->themes = get_option('gitea_themes');
if (!is_array($this->themes)) {
$this->themes = array();
}
$this->themes = array(); $this->themes = array();
$themes = wp_get_themes(); $themes = wp_get_themes();
foreach ($themes as $theme) { foreach ($themes as $theme) {
if ($theme->get('Gitea Host') != '' && $theme->get('Gitea URI')) { $headers = $this->get_file_headers(file_get_contents($theme->get_template_directory().'/style.css'), 'theme');
var_dump($headers);
if (empty($headers['Gitea Host']) || empty($headers['Gitea URI'])) {
continue;
}
// this is a gitea theme // this is a gitea theme
$slug = $theme->stylesheet; $slug = $theme->get_stylesheet();
$local_version = strtolower($theme->get('Version')); var_dump($slug);
$local_version = strtolower($headers['Version']);
if (isset($this->themes[$slug]) && !$this->update('themes')) { if (isset($this->themes[$slug]) && !$this->update('themes')) {
$this->themes[$slug]['local_version'] = $local_version; $this->themes[$slug]['local_version'] = $local_version;
@ -194,12 +194,13 @@ class Gitea_Updater
} }
$host = $this->get_host($theme->get('Gitea Host')); $host = $this->get_host($headers['Gitea Host']);
$repo = $theme->get('Gitea URI'); $repo = $headers['Gitea URI'];
$url = $this->get_url($host, $repo, '/raw/master/style.css'); $url = $this->get_url($host, $repo, '/raw/master/style.css');
$new_version = $local_version;
if ($url != false) { if ($url != false) {
$new_version = $this->get_version($url, 'plugin'); $new_version = $this->get_version($url, 'theme');
$new_version = $new_version ? $new_version : $local_version; $new_version = $new_version ? $new_version : $local_version;
} }
@ -208,19 +209,18 @@ class Gitea_Updater
// building the theme data // building the theme data
$gitea = array( $gitea = array(
'slug' => $slug, 'slug' => $slug,
'name' => $theme->get('Name'), 'name' => $headers['Name'],
'gitea_host' => $host, 'gitea_host' => $host,
'gitea_repo' => $repo, 'gitea_repo' => $repo,
'description' => $theme->get('Description'), 'description' => $headers['Description'],
'author' => $theme->get('Author'), 'author' => $headers['Author'],
'url' => $theme->get('AuthorURI'),//$host.$repo, 'url' => $headers['AuthorURI'],
'local_version' => $local_version, 'local_version' => $local_version,
'new_version' => $new_version, 'new_version' => $new_version,
'package' => $this->get_url($host, $repo, '/archive/master.zip'), 'package' => $this->get_url($host, $repo, '/archive/master.zip'),
); );
$this->themes[$slug] = $gitea; $this->themes[$slug] = $gitea;
}
} }
@ -395,10 +395,12 @@ class Gitea_Updater
if (false !== strpos($type, 'plugin')) { if (false !== strpos($type, 'plugin')) {
$all_headers = $default_plugin_headers; $all_headers = $default_plugin_headers;
} }
else if (false !== strpos($type, 'theme')) {
if (false !== strpos($type, 'theme')) {
$all_headers = $default_theme_headers; $all_headers = $default_theme_headers;
} }
else {
return [];
}
$file_data = str_replace("\r", "\n", $contents); $file_data = str_replace("\r", "\n", $contents);