mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-11 10:46:43 +02:00
feat(plugins): add settings page for podcast and episode if defined in the plugin's manifest
- rename options to settings
This commit is contained in:
parent
3d8aedf9c3
commit
89ac92fb41
19 changed files with 450 additions and 146 deletions
193
modules/Plugins/Controllers/PluginController.php
Normal file
193
modules/Plugins/Controllers/PluginController.php
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Plugins\Controllers;
|
||||
|
||||
use App\Entities\Episode;
|
||||
use App\Entities\Podcast;
|
||||
use App\Models\EpisodeModel;
|
||||
use App\Models\PodcastModel;
|
||||
use CodeIgniter\Exceptions\PageNotFoundException;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use Modules\Admin\Controllers\BaseController;
|
||||
use Modules\Plugins\Plugins;
|
||||
|
||||
class PluginController extends BaseController
|
||||
{
|
||||
public function installed(): string
|
||||
{
|
||||
/** @var Plugins $plugins */
|
||||
$plugins = service('plugins');
|
||||
|
||||
$pager = service('pager');
|
||||
|
||||
$page = (int) ($this->request->getGet('page') ?? 1);
|
||||
$perPage = 10;
|
||||
$total = $plugins->getInstalledCount();
|
||||
|
||||
$pager_links = $pager->makeLinks($page, $perPage, $total);
|
||||
|
||||
return view('plugins/installed', [
|
||||
'total' => $total,
|
||||
'plugins' => $plugins->getPlugins($page, $perPage),
|
||||
'pager_links' => $pager_links,
|
||||
]);
|
||||
}
|
||||
|
||||
public function generalSettings(string $pluginKey): string
|
||||
{
|
||||
/** @var Plugins $plugins */
|
||||
$plugins = service('plugins');
|
||||
|
||||
$plugin = $plugins->getPlugin($pluginKey);
|
||||
|
||||
if ($plugin === null) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
helper('form');
|
||||
return view('plugins/settings_general', [
|
||||
'plugin' => $plugin,
|
||||
]);
|
||||
}
|
||||
|
||||
public function generalSettingsAction(string $pluginKey): RedirectResponse
|
||||
{
|
||||
/** @var Plugins $plugins */
|
||||
$plugins = service('plugins');
|
||||
|
||||
$plugin = $plugins->getPlugin($pluginKey);
|
||||
|
||||
if ($plugin === null) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
foreach ($plugin->settings['general'] as $option) {
|
||||
$optionKey = $option['key'];
|
||||
$optionValue = $this->request->getPost($optionKey);
|
||||
$plugins->setOption($pluginKey, $optionKey, $optionValue);
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('message', lang('Plugins.messages.saveSettingsSuccess', [
|
||||
'pluginName' => $plugin->getName(),
|
||||
]));
|
||||
}
|
||||
|
||||
public function podcastSettings(string $podcastId, string $pluginKey): string
|
||||
{
|
||||
$podcast = (new PodcastModel())->getPodcastById((int) $podcastId);
|
||||
|
||||
if (! $podcast instanceof Podcast) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
/** @var Plugins $plugins */
|
||||
$plugins = service('plugins');
|
||||
|
||||
$plugin = $plugins->getPlugin($pluginKey);
|
||||
|
||||
if ($plugin === null) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
helper('form');
|
||||
replace_breadcrumb_params([
|
||||
0 => $podcast->handle,
|
||||
]);
|
||||
return view('plugins/settings_podcast', [
|
||||
'podcast' => $podcast,
|
||||
'plugin' => $plugin,
|
||||
]);
|
||||
}
|
||||
|
||||
public function podcastSettingsAction(string $podcastId, string $pluginKey): RedirectResponse
|
||||
{
|
||||
/** @var Plugins $plugins */
|
||||
$plugins = service('plugins');
|
||||
|
||||
$plugin = $plugins->getPlugin($pluginKey);
|
||||
|
||||
if ($plugin === null) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
foreach ($plugin->settings['podcast'] as $setting) {
|
||||
$settingKey = $setting['key'];
|
||||
$settingValue = $this->request->getPost($settingKey);
|
||||
$plugins->setOption($pluginKey, $settingKey, $settingValue, ['podcast', (int) $podcastId]);
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('message', lang('Plugins.messages.saveSettingsSuccess', [
|
||||
'pluginName' => $plugin->getName(),
|
||||
]));
|
||||
}
|
||||
|
||||
public function episodeSettings(string $podcastId, string $episodeId, string $pluginKey): string
|
||||
{
|
||||
$episode = (new EpisodeModel())->getEpisodeById((int) $episodeId);
|
||||
|
||||
if (! $episode instanceof Episode) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
/** @var Plugins $plugins */
|
||||
$plugins = service('plugins');
|
||||
|
||||
$plugin = $plugins->getPlugin($pluginKey);
|
||||
|
||||
if ($plugin === null) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
helper('form');
|
||||
replace_breadcrumb_params([
|
||||
0 => $episode->podcast->handle,
|
||||
1 => $episode->title,
|
||||
]);
|
||||
return view('plugins/settings_episode', [
|
||||
'podcast' => $episode->podcast,
|
||||
'episode' => $episode,
|
||||
'plugin' => $plugin,
|
||||
]);
|
||||
}
|
||||
|
||||
public function episodeSettingsAction(string $podcastId, string $episodeId, string $pluginKey): RedirectResponse
|
||||
{
|
||||
/** @var Plugins $plugins */
|
||||
$plugins = service('plugins');
|
||||
|
||||
$plugin = $plugins->getPlugin($pluginKey);
|
||||
|
||||
if ($plugin === null) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
foreach ($plugin->settings['episode'] as $setting) {
|
||||
$settingKey = $setting['key'];
|
||||
$settingValue = $this->request->getPost($settingKey);
|
||||
$plugins->setOption($pluginKey, $settingKey, $settingValue, ['episode', (int) $episodeId]);
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('message', lang('Plugins.messages.saveSettingsSuccess', [
|
||||
'pluginName' => $plugin->getName(),
|
||||
]));
|
||||
}
|
||||
|
||||
public function activate(string $pluginKey): RedirectResponse
|
||||
{
|
||||
service('plugins')->activate($pluginKey);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function deactivate(string $pluginKey): RedirectResponse
|
||||
{
|
||||
service('plugins')->deactivate($pluginKey);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue