diff --git a/app/Views/Components/Button.php b/app/Views/Components/Button.php index ad6e25a7083253a1e8444feaeb4f5e00b7f4e9d3..def8c33fad9c966b30567be1db1347a09806e06d 100644 --- a/app/Views/Components/Button.php +++ b/app/Views/Components/Button.php @@ -39,7 +39,6 @@ class Button extends Component 'warning' => 'shadow-sm text-black bg-yellow-500 hover:bg-yellow-600', 'info' => 'shadow-sm text-white bg-blue-500 hover:bg-blue-600', 'disabled' => 'shadow-sm text-black bg-gray-300 cursor-not-allowed', - 'link' => 'text-accent-base bg-transparent underline hover:no-underline', ]; $sizeClass = [ diff --git a/modules/Platforms/Config/Services.php b/modules/Platforms/Config/Services.php new file mode 100644 index 0000000000000000000000000000000000000000..c9912c0cac2f1e6c0915eb7d70015671e159c6f6 --- /dev/null +++ b/modules/Platforms/Config/Services.php @@ -0,0 +1,20 @@ +<?php + +declare(strict_types=1); + +namespace Modules\Platforms\Config; + +use CodeIgniter\Config\BaseService; +use Modules\Platforms\Platforms; + +class Services extends BaseService +{ + public static function platforms(bool $getShared = true): Platforms + { + if ($getShared) { + return self::getSharedInstance('platforms'); + } + + return new Platforms(); + } +} diff --git a/modules/Platforms/Models/PlatformModel.php b/modules/Platforms/Models/PlatformModel.php index c71e6c8f8f248e37af44f7e2324d84c9c2cdec88..75ce5ef1658c347243a7de81f0c21fadc7b6d02a 100644 --- a/modules/Platforms/Models/PlatformModel.php +++ b/modules/Platforms/Models/PlatformModel.php @@ -14,7 +14,6 @@ namespace Modules\Platforms\Models; use CodeIgniter\Model; use Modules\Platforms\Entities\Platform; -use Modules\Platforms\Platforms; class PlatformModel extends Model { @@ -55,7 +54,7 @@ class PlatformModel extends Model { $cacheName = "podcast#{$podcastId}_platforms_{$platformType}_withData"; if (! ($found = cache($cacheName))) { - $platforms = new Platforms(); + $platforms = service('platforms'); $found = $this->getPlatforms($podcastId, $platformType); $platformsData = $platforms->getPlatformsByType($platformType); @@ -95,7 +94,7 @@ class PlatformModel extends Model { $cacheName = "podcast#{$podcastId}_platforms_{$platformType}"; if (! ($found = cache($cacheName))) { - $platforms = new Platforms(); + $platforms = service('platforms'); /** @var Platform[] $found */ $found = $this @@ -134,7 +133,7 @@ class PlatformModel extends Model { $this->clearCache($podcastId); - $platforms = new Platforms(); + $platforms = service('platforms'); $platformsData = $platforms->getPlatformsByType($platformType); diff --git a/modules/PodcastImport/Commands/PodcastImport.php b/modules/PodcastImport/Commands/PodcastImport.php index 4e2cbe5850ebe0e939f2899c76f6444a583c8ca5..ffac62d3067088842beb17856fb56a4aa461ff43 100644 --- a/modules/PodcastImport/Commands/PodcastImport.php +++ b/modules/PodcastImport/Commands/PodcastImport.php @@ -22,7 +22,6 @@ use League\HTMLToMarkdown\HtmlConverter; use Modules\Auth\Config\AuthGroups; use Modules\Auth\Models\UserModel; use Modules\Platforms\Models\PlatformModel; -use Modules\Platforms\Platforms; use Modules\PodcastImport\Entities\PodcastImportTask; use Modules\PodcastImport\Entities\TaskStatus; use PodcastFeed\PodcastFeed; @@ -390,7 +389,7 @@ class PodcastImport extends BaseCommand ], ]; - $platforms = new Platforms(); + $platforms = service('platforms'); $platformModel = new PlatformModel(); foreach ($platformTypes as $platformType) { $platformsData = []; diff --git a/phpstan.neon b/phpstan.neon index 06c2565ca83fd6728c2efd0ac0c01b2316a9daaa..c1e8feeceba269810a4333b6d060e4412416e6cd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -39,9 +39,10 @@ parameters: - Modules\PremiumPodcasts\Models\ additionalServices: - CodeIgniter\Settings\Config\Services + - CodeIgniter\Shield\Config\Services - Michalsn\Uuid\Config\Services - Modules\PremiumPodcasts\Config\Services - Modules\Media\Config\Services - - CodeIgniter\Shield\Config\Services + - Modules\Platforms\Config\Services ignoreErrors: - '#^Call to an undefined method CodeIgniter\\Cache\\CacheInterface\:\:deleteMatching\(\)#' diff --git a/themes/cp_admin/podcast/_platform.php b/themes/cp_admin/podcast/_platform.php new file mode 100644 index 0000000000000000000000000000000000000000..ffd6e0caad32be67b9454f9faa0af2695a20a657 --- /dev/null +++ b/themes/cp_admin/podcast/_platform.php @@ -0,0 +1,61 @@ +<article class="relative flex-col items-start p-4 rounded-lg bg-elevated border-3 <?= $platform->link_url ? 'border-accent-base' : 'border-subtle' ?>"> + <?= $platform->link_url ? anchor( + route_to( + 'podcast-platform-remove', + $platform->podcast_id, + $platform->type, + $platform->slug, + ), + icon('delete-bin', 'mx-auto'), + [ + 'class' => 'absolute right-0 top-0 -mt-4 -mr-4 p-2 border-red-700 border-2 bg-red-100 rounded-full text-red-700 hover:text-red-900', + 'data-tooltip' => 'bottom', + 'title' => lang('Platforms.remove', [ + 'platformName' => $platform->label, + ]), + ], + ) + : '' ?> + <div class="flex items-center gap-x-2"> + <?= icon( + esc($platform->slug), + 'text-skin-muted text-4xl', + $platform->type + ) ?> + <h2 class="text-xl font-semibold"><?= $platform->label ?></h2> + </div> + <div class="flex flex-col flex-1 mt-4"> + <div class="inline-flex ml-8 -mt-6 gap-x-1"> + <a + href="<?= $platform->home_url ?>" class="px-3 py-1 text-xs font-semibold leading-6 underline rounded-full focus:ring-accent text-accent-base hover:no-underline" + target="_blank" rel="noopener noreferrer" title="<?= lang('Platforms.home_url', [ + 'platformName' => $platform->label, + ]) ?>" data-tooltip="bottom"><?= lang('Platforms.website') ?></a> + <?php if ($platform->submit_url !== null): ?> + <a + href="<?= $platform->submit_url ?>" class="px-3 py-1 text-xs font-semibold leading-6 underline rounded-full focus:ring-accent text-accent-base hover:no-underline" + target="_blank" rel="noopener noreferrer" title="<?= lang('Platforms.submit_url', [ + 'platformName' => $platform->label, + ]) ?>" data-tooltip="bottom"><?= lang('Platforms.register') ?></a> + <?php endif; ?> + </div> + <fieldset> + <Forms.Field + label="<?= esc(lang('Platforms.your_link')) ?>" + class="w-full mt-4" + id="<?= esc($platform->slug) . '_link_url' ?>" + name="<?= 'platforms[' . esc($platform->slug) . '][url]' ?>" + value="<?= esc($platform->link_url) ?>" + type="url" + placeholder="https://…" /> + <Forms.Field + label="<?= esc(lang("Platforms.your_id.{$platform->type}")) ?>" + class="w-full mt-2" + id="<?= esc($platform->slug) . '_account_id' ?>" + name="<?= 'platforms[' . esc($platform->slug) . '][account_id]' ?>" + value="<?= esc($platform->account_id) ?>" + placeholder="<?= lang("Platforms.description.{$platform->type}") ?>" /> + <Forms.Toggler size="small" class="mt-4 text-sm" id="<?= esc($platform->slug) . '_visible' ?>" name="<?= 'platforms[' . esc($platform->slug) . '][visible]'?>" value="yes" checked="<?= old(esc($platform->slug) . '_visible', $platform->is_visible ? 'true' : 'false') ?>"><?= lang('Platforms.visible') ?></Forms.Toggler> + </fieldset> + </div> +</article> diff --git a/themes/cp_admin/podcast/platforms.php b/themes/cp_admin/podcast/platforms.php index e06a2d0fb7dd5d333b4c5663a810b6bbd8e8752e..e65facde1d52269124cf0a776b61e6ae26653ab0 100644 --- a/themes/cp_admin/podcast/platforms.php +++ b/themes/cp_admin/podcast/platforms.php @@ -18,67 +18,11 @@ <?= csrf_field() ?> -<?php foreach ($platforms as $platform): ?> - -<div class="relative flex-col items-start p-4 rounded-lg bg-elevated border-3 <?= $platform->link_url ? 'border-accent-base' : 'border-subtle' ?>"> - <?= $platform->link_url ? anchor( - route_to( - 'podcast-platform-remove', - $podcast->id, - $platform->type, - $platform->slug, - ), - icon('delete-bin', 'mx-auto'), - [ - 'class' => 'absolute right-0 top-0 -mt-4 -mr-4 p-2 border-red-700 border-2 bg-red-100 rounded-full text-red-700 hover:text-red-900', - 'data-tooltip' => 'bottom', - 'title' => lang('Platforms.remove', [ - 'platformName' => $platform->label, - ]), - ], - ) - : '' ?> - <div class="flex items-center gap-x-2"> - <?= icon( - esc($platform->slug), - 'text-skin-muted text-4xl', - $platform->type - ) ?> - <h2 class="text-xl font-semibold"><?= $platform->label ?></h2> - </div> - <div class="flex flex-col flex-1 mt-4"> - <div class="inline-flex ml-8 -mt-6 gap-x-1"> - <Button uri="<?= $platform->home_url ?>" variant="link" size="small" target="_blank" rel="noopener noreferrer" title="<?= lang('Platforms.home_url', [ - 'platformName' => $platform->label, - ]) ?>" data-tooltip="bottom"><?= lang('Platforms.website') ?></Button> - <?php if ($platform->submit_url !== null): ?> - <Button uri="<?= $platform->submit_url ?>" variant="link" size="small" target="_blank" rel="noopener noreferrer" title="<?= lang('Platforms.submit_url', [ - 'platformName' => $platform->label, - ]) ?>" data-tooltip="bottom"><?= lang('Platforms.register') ?></Button> - <?php endif; ?> - </div> - <fieldset> - <Forms.Field - label="<?= esc(lang('Platforms.your_link')) ?>" - class="w-full mt-4" - id="<?= esc($platform->slug) . '_link_url' ?>" - name="<?= 'platforms[' . esc($platform->slug) . '][url]' ?>" - value="<?= esc($platform->link_url) ?>" - type="url" - placeholder="https://…" /> - <Forms.Field - label="<?= esc(lang("Platforms.your_id.{$platform->type}")) ?>" - class="w-full mt-2" - id="<?= esc($platform->slug) . '_account_id' ?>" - name="<?= 'platforms[' . esc($platform->slug) . '][account_id]' ?>" - value="<?= esc($platform->account_id) ?>" - placeholder="<?= lang("Platforms.description.{$platform->type}") ?>" /> - <Forms.Toggler size="small" class="mt-4 text-sm" id="<?= esc($platform->slug) . '_visible' ?>" name="<?= 'platforms[' . esc($platform->slug) . '][visible]'?>" value="yes" checked="<?= old(esc($platform->slug) . '_visible', $platform->is_visible ? 'true' : 'false') ?>"><?= lang('Platforms.visible') ?></Forms.Toggler> - </fieldset> - </div> -</div> - -<?php endforeach; ?> +<?php foreach ($platforms as $platform) { + echo view('podcast/_platform', [ + 'platform' => $platform, + ]); +} ?> </form>