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,56 +172,56 @@ 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;
continue; continue;
}
$host = $this->get_host($theme->get('Gitea Host'));
$repo = $theme->get('Gitea URI');
$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;
}
// 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'),
);
$this->themes[$slug] = $gitea;
} }
$host = $this->get_host($headers['Gitea Host']);
$repo = $headers['Gitea URI'];
$url = $this->get_url($host, $repo, '/raw/master/style.css');
$new_version = $local_version;
if ($url != false) {
$new_version = $this->get_version($url, 'theme');
$new_version = $new_version ? $new_version : $local_version;
}
// here we have the remote version from gitea/repo/style.css
// building the theme data
$gitea = array(
'slug' => $slug,
'name' => $headers['Name'],
'gitea_host' => $host,
'gitea_repo' => $repo,
'description' => $headers['Description'],
'author' => $headers['Author'],
'url' => $headers['AuthorURI'],
'local_version' => $local_version,
'new_version' => $new_version,
'package' => $this->get_url($host, $repo, '/archive/master.zip'),
);
$this->themes[$slug] = $gitea;
} }
update_option('gitea_themes', $this->themes); update_option('gitea_themes', $this->themes);
@ -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);