2020-06-10 15:00:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
namespace App\Controllers;
|
2020-05-31 19:15:52 +00:00
|
|
|
|
|
|
|
use App\Models\CategoryModel;
|
|
|
|
use App\Models\LanguageModel;
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
|
2020-06-26 14:34:52 +00:00
|
|
|
class Podcast extends BaseController
|
2020-05-31 19:15:52 +00:00
|
|
|
{
|
2020-06-30 18:17:41 +02:00
|
|
|
protected ?\App\Entities\Podcast $podcast;
|
|
|
|
|
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
|
|
|
if (count($params) > 0) {
|
|
|
|
$podcast_model = new PodcastModel();
|
2020-07-02 10:08:32 +00:00
|
|
|
if (
|
|
|
|
!($podcast = $podcast_model->where('name', $params[0])->first())
|
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
$this->podcast = $podcast;
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->$method();
|
|
|
|
}
|
|
|
|
|
2020-05-31 19:15:52 +00:00
|
|
|
public function create()
|
|
|
|
{
|
2020-06-30 18:17:41 +02:00
|
|
|
helper(['form', 'misc']);
|
2020-06-10 15:00:12 +00:00
|
|
|
$podcast_model = new PodcastModel();
|
2020-05-31 19:15:52 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
if (
|
|
|
|
!$this->validate([
|
|
|
|
'title' => 'required',
|
2020-07-02 10:08:32 +00:00
|
|
|
'name' => 'required|regex_match[[a-zA-Z0-9\_]{1,191}]',
|
2020-06-10 15:00:12 +00:00
|
|
|
'description' => 'required|max_length[4000]',
|
|
|
|
'image' =>
|
2020-06-30 18:17:41 +02:00
|
|
|
'uploaded[image]|is_image[image]|ext_in[image,jpg,png]',
|
|
|
|
'owner_email' => 'required|valid_email',
|
2020-06-10 15:00:12 +00:00
|
|
|
'type' => 'required',
|
|
|
|
])
|
|
|
|
) {
|
2020-05-31 19:15:52 +00:00
|
|
|
$languageModel = new LanguageModel();
|
|
|
|
$categoryModel = new CategoryModel();
|
|
|
|
$data = [
|
|
|
|
'languages' => $languageModel->findAll(),
|
|
|
|
'categories' => $categoryModel->findAll(),
|
2020-06-10 15:00:12 +00:00
|
|
|
'browser_lang' => get_browser_language(
|
|
|
|
$this->request->getServer('HTTP_ACCEPT_LANGUAGE')
|
|
|
|
),
|
2020-05-31 19:15:52 +00:00
|
|
|
];
|
|
|
|
|
2020-06-26 14:34:52 +00:00
|
|
|
echo view('podcast/create', $data);
|
2020-05-31 19:15:52 +00:00
|
|
|
} else {
|
2020-06-26 14:34:52 +00:00
|
|
|
$podcast = new \App\Entities\Podcast([
|
2020-05-31 19:15:52 +00:00
|
|
|
'title' => $this->request->getVar('title'),
|
2020-06-30 18:17:41 +02:00
|
|
|
'name' => $this->request->getVar('name'),
|
2020-05-31 19:15:52 +00:00
|
|
|
'description' => $this->request->getVar('description'),
|
2020-06-10 15:00:12 +00:00
|
|
|
'episode_description_footer' => $this->request->getVar(
|
|
|
|
'episode_description_footer'
|
|
|
|
),
|
2020-06-30 18:17:41 +02:00
|
|
|
'image' => $this->request->getFile('image'),
|
2020-05-31 19:15:52 +00:00
|
|
|
'language' => $this->request->getVar('language'),
|
|
|
|
'category' => $this->request->getVar('category'),
|
|
|
|
'explicit' => $this->request->getVar('explicit') or false,
|
2020-06-26 14:34:52 +00:00
|
|
|
'author_name' => $this->request->getVar('author_name'),
|
|
|
|
'author_email' => $this->request->getVar('author_email'),
|
2020-05-31 19:15:52 +00:00
|
|
|
'owner_name' => $this->request->getVar('owner_name'),
|
|
|
|
'owner_email' => $this->request->getVar('owner_email'),
|
|
|
|
'type' => $this->request->getVar('type'),
|
|
|
|
'copyright' => $this->request->getVar('copyright'),
|
|
|
|
'block' => $this->request->getVar('block') or false,
|
|
|
|
'complete' => $this->request->getVar('complete') or false,
|
2020-06-10 15:00:12 +00:00
|
|
|
'custom_html_head' => $this->request->getVar(
|
|
|
|
'custom_html_head'
|
|
|
|
),
|
2020-05-31 19:15:52 +00:00
|
|
|
]);
|
|
|
|
|
2020-06-12 19:31:10 +00:00
|
|
|
$podcast_model->save($podcast);
|
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
return redirect()->to(
|
2020-06-26 14:34:52 +00:00
|
|
|
base_url(route_to('podcast_view', $podcast->name))
|
2020-06-10 15:00:12 +00:00
|
|
|
);
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-01 21:23:14 +00:00
|
|
|
|
2020-06-30 18:17:41 +02:00
|
|
|
public function edit()
|
2020-06-01 21:23:14 +00:00
|
|
|
{
|
2020-06-30 18:17:41 +02:00
|
|
|
helper(['form', 'misc']);
|
|
|
|
|
|
|
|
if (
|
|
|
|
!$this->validate([
|
|
|
|
'title' => 'required',
|
2020-07-02 10:08:32 +00:00
|
|
|
'name' => 'required|regex_match[[a-zA-Z0-9\_]{1,191}]',
|
2020-06-30 18:17:41 +02:00
|
|
|
'description' => 'required|max_length[4000]',
|
|
|
|
'image' =>
|
|
|
|
'uploaded[image]|is_image[image]|ext_in[image,jpg,png]|permit_empty',
|
|
|
|
'owner_email' => 'required|valid_email',
|
|
|
|
'type' => 'required',
|
|
|
|
])
|
|
|
|
) {
|
|
|
|
$languageModel = new LanguageModel();
|
|
|
|
$categoryModel = new CategoryModel();
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'languages' => $languageModel->findAll(),
|
|
|
|
'categories' => $categoryModel->findAll(),
|
|
|
|
];
|
|
|
|
|
|
|
|
echo view('podcast/edit', $data);
|
|
|
|
} else {
|
|
|
|
$this->podcast->title = $this->request->getVar('title');
|
|
|
|
$this->podcast->name = $this->request->getVar('name');
|
|
|
|
$this->podcast->description = $this->request->getVar('description');
|
|
|
|
$this->podcast->episode_description_footer = $this->request->getVar(
|
|
|
|
'episode_description_footer'
|
|
|
|
);
|
|
|
|
|
|
|
|
$image = $this->request->getFile('image');
|
|
|
|
if ($image->isValid()) {
|
|
|
|
$this->podcast->image = $this->request->getFile('image');
|
|
|
|
}
|
|
|
|
$this->podcast->language = $this->request->getVar('language');
|
|
|
|
$this->podcast->category = $this->request->getVar('category');
|
|
|
|
$this->podcast->explicit =
|
|
|
|
($this->request->getVar('explicit') or false);
|
|
|
|
$this->podcast->author_name = $this->request->getVar('author_name');
|
|
|
|
$this->podcast->author_email = $this->request->getVar(
|
|
|
|
'author_email'
|
|
|
|
);
|
|
|
|
$this->podcast->owner_name = $this->request->getVar('owner_name');
|
|
|
|
$this->podcast->owner_email = $this->request->getVar('owner_email');
|
|
|
|
$this->podcast->type = $this->request->getVar('type');
|
|
|
|
$this->podcast->copyright = $this->request->getVar('copyright');
|
|
|
|
$this->podcast->block = ($this->request->getVar('block') or false);
|
|
|
|
$this->podcast->complete =
|
|
|
|
($this->request->getVar('complete') or false);
|
|
|
|
$this->podcast->custom_html_head = $this->request->getVar(
|
|
|
|
'custom_html_head'
|
|
|
|
);
|
|
|
|
|
|
|
|
$podcast_model = new PodcastModel();
|
|
|
|
$podcast_model->save($this->podcast);
|
|
|
|
|
|
|
|
return redirect()->to(
|
|
|
|
base_url(route_to('podcast_view', $this->podcast->name))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function view()
|
|
|
|
{
|
2020-07-02 10:08:32 +00:00
|
|
|
// The page cache is set to a decade so it is deleted manually upon podcast update
|
|
|
|
$this->cachePage(DECADE);
|
|
|
|
|
2020-06-30 18:17:41 +02:00
|
|
|
self::triggerWebpageHit($this->podcast->id);
|
2020-06-01 21:23:14 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
$data = [
|
2020-06-30 18:17:41 +02:00
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episodes' => $this->podcast->episodes,
|
2020-06-10 15:00:12 +00:00
|
|
|
];
|
2020-06-26 14:34:52 +00:00
|
|
|
return view('podcast/view', $data);
|
2020-06-01 21:23:14 +00:00
|
|
|
}
|
2020-06-30 18:17:41 +02:00
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$podcast_model = new PodcastModel();
|
|
|
|
$podcast_model->delete($this->podcast->id);
|
|
|
|
|
|
|
|
return redirect()->to(base_url(route_to('home')));
|
|
|
|
}
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|