2024-05-01 14:48:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-05-06 16:00:47 +00:00
|
|
|
use Modules\Plugins\Core\Plugins;
|
2024-05-02 15:32:27 +00:00
|
|
|
|
|
|
|
if (! function_exists('plugins')) {
|
|
|
|
function plugins(): Plugins
|
|
|
|
{
|
|
|
|
return service('plugins');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-04 13:10:56 +00:00
|
|
|
if (! function_exists('get_plugin_setting')) {
|
2024-05-02 15:32:27 +00:00
|
|
|
/**
|
|
|
|
* @param ?array{'podcast'|'episode',int} $additionalContext
|
|
|
|
*/
|
2024-06-04 13:10:56 +00:00
|
|
|
function get_plugin_setting(string $pluginKey, string $option, array $additionalContext = null): mixed
|
2024-05-01 14:48:05 +00:00
|
|
|
{
|
|
|
|
$key = sprintf('Plugins.%s', $option);
|
|
|
|
$context = sprintf('plugin:%s', $pluginKey);
|
|
|
|
|
2024-05-02 15:32:27 +00:00
|
|
|
if ($additionalContext !== null) {
|
|
|
|
$context .= sprintf('+%s:%d', ...$additionalContext);
|
|
|
|
}
|
|
|
|
|
2024-05-01 14:48:05 +00:00
|
|
|
return setting()->get($key, $context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-04 13:10:56 +00:00
|
|
|
if (! function_exists('set_plugin_setting')) {
|
2024-05-02 15:32:27 +00:00
|
|
|
/**
|
|
|
|
* @param ?array{'podcast'|'episode',int} $additionalContext
|
|
|
|
*/
|
2024-06-04 13:10:56 +00:00
|
|
|
function set_plugin_setting(
|
2024-05-02 15:32:27 +00:00
|
|
|
string $pluginKey,
|
|
|
|
string $option,
|
|
|
|
mixed $value = null,
|
|
|
|
array $additionalContext = null
|
|
|
|
): void {
|
2024-05-01 14:48:05 +00:00
|
|
|
$key = sprintf('Plugins.%s', $option);
|
|
|
|
$context = sprintf('plugin:%s', $pluginKey);
|
|
|
|
|
2024-05-02 15:32:27 +00:00
|
|
|
if ($additionalContext !== null) {
|
|
|
|
$context .= sprintf('+%s:%d', ...$additionalContext);
|
|
|
|
}
|
|
|
|
|
2024-05-01 14:48:05 +00:00
|
|
|
setting()
|
|
|
|
->set($key, $value, $context);
|
|
|
|
}
|
|
|
|
}
|
2024-06-03 14:32:42 +00:00
|
|
|
|
|
|
|
if (! function_exists('load_plugins_translations')) {
|
|
|
|
/**
|
|
|
|
* @return array<mixed>
|
|
|
|
*/
|
|
|
|
function load_plugins_translations(string $locale): array
|
|
|
|
{
|
|
|
|
$allPlugins = plugins()
|
|
|
|
->getAllPlugins();
|
|
|
|
|
|
|
|
$translations = [];
|
|
|
|
foreach ($allPlugins as $plugin) {
|
|
|
|
$file = $plugin->getDirectory() . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . $locale . '.json';
|
|
|
|
|
|
|
|
$jsonContents = @file_get_contents($file);
|
|
|
|
|
|
|
|
if (! $jsonContents) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$contents = json_decode($jsonContents, true);
|
|
|
|
|
|
|
|
if (! $contents) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$translations[$plugin->getKey()] = $contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $translations;
|
|
|
|
}
|
|
|
|
}
|