mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Move getPluginManifest() to PluginInstaller class
This commit is contained in:
parent
ee38614334
commit
6785cc1104
@ -161,7 +161,7 @@ function getUserPlugins()
|
|||||||
$plugins = [];
|
$plugins = [];
|
||||||
foreach ($submodules as $submodule) {
|
foreach ($submodules as $submodule) {
|
||||||
$manifestUrl = $submodule['url'] .'/blob/master/manifest.json?raw=true';
|
$manifestUrl = $submodule['url'] .'/blob/master/manifest.json?raw=true';
|
||||||
$manifest = getPluginManifest($manifestUrl);
|
$manifest = $pluginInstaller->getPluginManifest($manifestUrl);
|
||||||
|
|
||||||
if ($manifest) {
|
if ($manifest) {
|
||||||
$namespace = $manifest['namespace'] ?? '';
|
$namespace = $manifest['namespace'] ?? '';
|
||||||
@ -232,36 +232,6 @@ function getSubmodules(string $repoUrl): array
|
|||||||
return $submodules;
|
return $submodules;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Decodes a plugin's associated manifest JSON.
|
|
||||||
* Returns an array of key-value pairs
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
* @return array $json
|
|
||||||
*/
|
|
||||||
function getPluginManifest(string $url): ?array
|
|
||||||
{
|
|
||||||
$options = [
|
|
||||||
'http' => [
|
|
||||||
'method' => 'GET',
|
|
||||||
'follow_location' => 1,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$context = stream_context_create($options);
|
|
||||||
$content = file_get_contents($url, false, $context);
|
|
||||||
|
|
||||||
if ($content === false) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$json = json_decode($content, true);
|
|
||||||
|
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $json;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of available plugins formatted as an HTML table
|
* Returns a list of available plugins formatted as an HTML table
|
||||||
*
|
*
|
||||||
@ -284,8 +254,8 @@ function getHTMLPluginsTable(array $plugins): string
|
|||||||
$status = 'Installed';
|
$status = 'Installed';
|
||||||
} else {
|
} else {
|
||||||
$status = '<button type="button" class="btn btn-outline btn-primary btn-sm text-nowrap"
|
$status = '<button type="button" class="btn btn-outline btn-primary btn-sm text-nowrap"
|
||||||
name="install-plugin" data-bs-toggle="modal" data-bs-target="#installPlugin" />'
|
name="install-plugin" data-bs-toggle="modal" data-bs-target="#install-user-plugin"
|
||||||
. _("Install now") .'</button>';
|
data-record-id="'.htmlspecialchars($plugin['plugin_uri']).'" />' . _("Install now") .'</button>';
|
||||||
}
|
}
|
||||||
$name = '<i class="' . htmlspecialchars($plugin['fa-icon']) . ' link-secondary me-2"></i><a href="'
|
$name = '<i class="' . htmlspecialchars($plugin['fa-icon']) . ' link-secondary me-2"></i><a href="'
|
||||||
. htmlspecialchars($plugin['plugin_uri'])
|
. htmlspecialchars($plugin['plugin_uri'])
|
||||||
|
@ -30,6 +30,40 @@ class PluginInstaller
|
|||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a plugin's associated manifest JSON.
|
||||||
|
* Returns an array of key-value pairs
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @return array $json
|
||||||
|
*/
|
||||||
|
public function getPluginManifest(string $url): ?array
|
||||||
|
{
|
||||||
|
$options = [
|
||||||
|
'http' => [
|
||||||
|
'method' => 'GET',
|
||||||
|
'follow_location' => 1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$context = stream_context_create($options);
|
||||||
|
$content = file_get_contents($url, false, $context);
|
||||||
|
|
||||||
|
if ($content === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$json = json_decode($content, true);
|
||||||
|
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns an array of installed plugins in pluginPath
|
||||||
|
*
|
||||||
|
* @return array $plugins
|
||||||
|
*/
|
||||||
public function getPlugins(): array
|
public function getPlugins(): array
|
||||||
{
|
{
|
||||||
$plugins = [];
|
$plugins = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user