mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-06 18:31:05 +00:00
fix: set episode numbers during import + remove all custom form_helpers + minor ui issues
This commit is contained in:
parent
b05d177f1b
commit
99a3b8d33e
@ -1,81 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @copyright 2020 Podlibre
|
|
||||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
||||||
* @link https://castopod.org/
|
|
||||||
*/
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
|
||||||
|
|
||||||
if (! function_exists('form_dropdown')) {
|
|
||||||
/**
|
|
||||||
* Drop-down Menu (based on html select tag)
|
|
||||||
*
|
|
||||||
* @param array<string, mixed> $options
|
|
||||||
* @param array<string|int> $selected
|
|
||||||
* @param array<string, mixed> $customExtra
|
|
||||||
*/
|
|
||||||
function form_dropdown(
|
|
||||||
string $name = '',
|
|
||||||
array $options = [],
|
|
||||||
array $selected = [],
|
|
||||||
array $customExtra = []
|
|
||||||
): string {
|
|
||||||
$defaultExtra = [
|
|
||||||
'data-select-text' => lang('Common.forms.multiSelect.selectText'),
|
|
||||||
'data-loading-text' => lang('Common.forms.multiSelect.loadingText'),
|
|
||||||
'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'),
|
|
||||||
'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'),
|
|
||||||
'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'),
|
|
||||||
];
|
|
||||||
$extra = array_merge($defaultExtra, $customExtra);
|
|
||||||
$defaults = [
|
|
||||||
'name' => $name,
|
|
||||||
];
|
|
||||||
|
|
||||||
// standardize selected as strings, like the option keys will be.
|
|
||||||
foreach ($selected as $key => $item) {
|
|
||||||
$selected[$key] = $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
$placeholderOption = '';
|
|
||||||
if (isset($extra['placeholder'])) {
|
|
||||||
$placeholderOption = '<option value="" disabled="disabled" hidden="hidden"' . (in_array(
|
|
||||||
'',
|
|
||||||
$selected,
|
|
||||||
true
|
|
||||||
) ? ' selected="selected"' : '') . '>' . $extra['placeholder'] . '</option>';
|
|
||||||
unset($extra['placeholder']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$extra = stringify_attributes($extra);
|
|
||||||
$multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : '';
|
|
||||||
$form = '<select ' . rtrim(parse_form_attributes($name, $defaults)) . $extra . $multiple . ">\n";
|
|
||||||
$form .= $placeholderOption;
|
|
||||||
|
|
||||||
foreach ($options as $key => $val) {
|
|
||||||
if (is_array($val)) {
|
|
||||||
if ($val === []) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$form .= '<optgroup label="' . $key . "\">\n";
|
|
||||||
foreach ($val as $optgroupKey => $optgroupVal) {
|
|
||||||
$sel = in_array($optgroupKey, $selected, true) ? ' selected="selected"' : '';
|
|
||||||
$form .= '<option value="' . htmlspecialchars($optgroupKey) . '"' . $sel . '>'
|
|
||||||
. $optgroupVal . "</option>\n";
|
|
||||||
}
|
|
||||||
$form .= "</optgroup>\n";
|
|
||||||
} else {
|
|
||||||
/** @noRector RecastingRemovalRector */
|
|
||||||
$form .= '<option value="' . htmlspecialchars((string) $key) . '"'
|
|
||||||
. (in_array($key, $selected, true) ? ' selected="selected"' : '') . '>'
|
|
||||||
. $val . "</option>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $form . "</select>\n";
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,7 +23,7 @@ class Checkbox extends FormComponent
|
|||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'class' => 'form-checkbox text-pine-500 border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 w-6 h-6',
|
'class' => 'form-checkbox text-pine-500 border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 w-6 h-6',
|
||||||
],
|
],
|
||||||
$this->value,
|
'yes',
|
||||||
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
|
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -10,16 +10,7 @@ class Input extends FormComponent
|
|||||||
|
|
||||||
public function render(): string
|
public function render(): string
|
||||||
{
|
{
|
||||||
$class = 'px-3 py-2 bg-white rounded-lg border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class;
|
$class = 'px-3 py-2 bg-white border-black rounded-lg focus:border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class;
|
||||||
|
|
||||||
if (session()->has('errors')) {
|
|
||||||
$error = session('errors')[$this->name];
|
|
||||||
if ($error) {
|
|
||||||
$class .= ' border-red';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$class .= ' border-black focus:border-black';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->attributes['class'] = $class;
|
$this->attributes['class'] = $class;
|
||||||
|
|
||||||
|
@ -31,6 +31,11 @@ class MultiSelect extends FormComponent
|
|||||||
$defaultAttributes = [
|
$defaultAttributes = [
|
||||||
'data-class' => $this->attributes['class'],
|
'data-class' => $this->attributes['class'],
|
||||||
'multiple' => 'multiple',
|
'multiple' => 'multiple',
|
||||||
|
'data-select-text' => lang('Common.forms.multiSelect.selectText'),
|
||||||
|
'data-loading-text' => lang('Common.forms.multiSelect.loadingText'),
|
||||||
|
'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'),
|
||||||
|
'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'),
|
||||||
|
'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'),
|
||||||
];
|
];
|
||||||
$extra = array_merge($defaultAttributes, $this->attributes);
|
$extra = array_merge($defaultAttributes, $this->attributes);
|
||||||
|
|
||||||
|
@ -23,6 +23,11 @@ class Select extends FormComponent
|
|||||||
$defaultAttributes = [
|
$defaultAttributes = [
|
||||||
'class' => 'focus:border-black focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 border-3 rounded-lg border-black ' . $this->class,
|
'class' => 'focus:border-black focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 border-3 rounded-lg border-black ' . $this->class,
|
||||||
'data-class' => $this->class,
|
'data-class' => $this->class,
|
||||||
|
'data-select-text' => lang('Common.forms.multiSelect.selectText'),
|
||||||
|
'data-loading-text' => lang('Common.forms.multiSelect.loadingText'),
|
||||||
|
'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'),
|
||||||
|
'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'),
|
||||||
|
'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'),
|
||||||
];
|
];
|
||||||
$extra = array_merge($this->attributes, $defaultAttributes);
|
$extra = array_merge($this->attributes, $defaultAttributes);
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ $pager->setSurroundCount(2);
|
|||||||
<?php foreach ($pager->links() as $link): ?>
|
<?php foreach ($pager->links() as $link): ?>
|
||||||
<li>
|
<li>
|
||||||
<?php if ($link['active']): ?>
|
<?php if ($link['active']): ?>
|
||||||
<span class="block px-4 py-2 font-semibold text-white rounded-full bg-pine-600">
|
<span class="block px-4 py-2 font-semibold text-white rounded-full bg-pine-500">
|
||||||
<?= $link['title'] ?>
|
<?= $link['title'] ?>
|
||||||
</span>
|
</span>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
|
@ -285,17 +285,17 @@ class PodcastImportController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$numberItems = $feed->channel[0]->item->count();
|
$itemsCount = $feed->channel[0]->item->count();
|
||||||
|
|
||||||
$lastItem =
|
$lastItem =
|
||||||
$this->request->getPost('max_episodes') !== '' &&
|
$this->request->getPost('max_episodes') !== '' &&
|
||||||
$this->request->getPost('max_episodes') < $numberItems
|
$this->request->getPost('max_episodes') < $itemsCount
|
||||||
? (int) $this->request->getPost('max_episodes')
|
? (int) $this->request->getPost('max_episodes')
|
||||||
: $numberItems;
|
: $itemsCount;
|
||||||
|
|
||||||
$slugs = [];
|
$slugs = [];
|
||||||
for ($itemNumber = 1; $itemNumber <= $lastItem; ++$itemNumber) {
|
for ($itemNumber = 1; $itemNumber <= $lastItem; ++$itemNumber) {
|
||||||
$item = $feed->channel[0]->item[$numberItems - $itemNumber];
|
$item = $feed->channel[0]->item[$itemsCount - $itemNumber];
|
||||||
|
|
||||||
$nsItunes = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
|
$nsItunes = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
|
||||||
$nsPodcast = $item->children(
|
$nsPodcast = $item->children(
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
if (session()->has('message')): ?>
|
if (session()->has('message')): ?>
|
||||||
<Alert variant="success"><?= session('message') ?></Alert>
|
<Alert variant="success" class="mb-4"><?= session('message') ?></Alert>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (session()->has('error')): ?>
|
<?php if (session()->has('error')): ?>
|
||||||
<Alert variant="danger"><?= session('error') ?></Alert>
|
<Alert variant="danger" class="mb-4"><?= session('error') ?></Alert>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (session()->has('errors')): ?>
|
<?php if (session()->has('errors')): ?>
|
||||||
<Alert variant="danger">
|
<Alert variant="danger" class="mb-4">
|
||||||
<ul>
|
<ul>
|
||||||
<?php foreach (session('errors') as $error): ?>
|
<?php foreach (session('errors') as $error): ?>
|
||||||
<li><?= $error ?></li>
|
<li><?= $error ?></li>
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
$podcast->id,
|
$podcast->id,
|
||||||
$episode->id,
|
$episode->id,
|
||||||
) . '">' . lang(
|
) . '">' . lang(
|
||||||
'Episode.embeddable_player.add',
|
'Episode.embeddable_player.title',
|
||||||
) . '</a>' .
|
) . '</a>' .
|
||||||
'<a class="px-4 py-1 hover:bg-gray-100" href="' . route_to(
|
'<a class="px-4 py-1 hover:bg-gray-100" href="' . route_to(
|
||||||
'episode-persons-manage',
|
'episode-persons-manage',
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
[
|
[
|
||||||
'header' => lang('Common.actions'),
|
'header' => lang('Common.actions'),
|
||||||
'cell' => function ($person): string {
|
'cell' => function ($person): string {
|
||||||
return '<Button uri="' . route_to('episode-person-remove', $person->podcast_id, $person->episode_id, $person->id) . '" variant="danger" size="small">' . lang('Person.episode_form.remove') . '</Button>';
|
return '<Button uri="' . route_to('episode-person-remove', $person->podcast_id, $person->episode_id, $person->id) . '" variant="danger" size="small" iconLeft="delete-bin">' . lang('Person.episode_form.remove') . '</Button>';
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@ -58,7 +58,7 @@
|
|||||||
'max-w-xl'
|
'max-w-xl'
|
||||||
) ?>
|
) ?>
|
||||||
|
|
||||||
<form action="<?= route_to('episode-persons-manage', $episode->id) ?>" method="POST" class="mt-6">
|
<form action="<?= route_to('episode-persons-manage', $podcast->id, $episode->id) ?>" method="POST" class="mt-6">
|
||||||
<?= csrf_field() ?>
|
<?= csrf_field() ?>
|
||||||
|
|
||||||
<Forms.Section
|
<Forms.Section
|
||||||
|
@ -68,7 +68,7 @@
|
|||||||
$podcast->id,
|
$podcast->id,
|
||||||
$episode->id,
|
$episode->id,
|
||||||
) ?>"><?= lang(
|
) ?>"><?= lang(
|
||||||
'Episode.embeddable_player.add',
|
'Episode.embeddable_player.title',
|
||||||
) ?></a>
|
) ?></a>
|
||||||
<a class="px-4 py-1 hover:bg-gray-100" href="<?= route_to(
|
<a class="px-4 py-1 hover:bg-gray-100" href="<?= route_to(
|
||||||
'episode-persons-manage',
|
'episode-persons-manage',
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
if (session()->has('message')): ?>
|
if (session()->has('message')): ?>
|
||||||
<Alert variant="success"><?= session('message') ?></Alert>
|
<Alert variant="success" class="mb-4"><?= session('message') ?></Alert>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (session()->has('error')): ?>
|
<?php if (session()->has('error')): ?>
|
||||||
<Alert variant="danger"><?= session('error') ?></Alert>
|
<Alert variant="danger" class="mb-4"><?= session('error') ?></Alert>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (session()->has('errors')): ?>
|
<?php if (session()->has('errors')): ?>
|
||||||
<Alert variant="danger">
|
<Alert variant="danger" class="mb-4">
|
||||||
<ul>
|
<ul>
|
||||||
<?php foreach (session('errors') as $error): ?>
|
<?php foreach (session('errors') as $error): ?>
|
||||||
<li><?= $error ?></li>
|
<li><?= $error ?></li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user