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
|
|
|
|
2020-06-12 19:31:10 +00:00
|
|
|
use App\Entities\Podcast;
|
2020-05-31 19:15:52 +00:00
|
|
|
use App\Models\CategoryModel;
|
2020-06-10 15:00:12 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2020-05-31 19:15:52 +00:00
|
|
|
use App\Models\LanguageModel;
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
|
2020-06-01 21:23:14 +00:00
|
|
|
class Podcasts extends BaseController
|
2020-05-31 19:15:52 +00:00
|
|
|
{
|
|
|
|
public function create()
|
|
|
|
{
|
2020-06-12 19:31:10 +00:00
|
|
|
helper(['form', 'database', 'media', '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',
|
|
|
|
'name' => 'required|regex_match[^[a-z0-9\_]{1,191}$]',
|
|
|
|
'description' => 'required|max_length[4000]',
|
|
|
|
'image' =>
|
|
|
|
'uploaded[image]|is_image[image]|ext_in[image,jpg,png]|max_dims[image,3000,3000]',
|
|
|
|
'owner_email' => 'required|valid_email|permit_empty',
|
|
|
|
'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')
|
|
|
|
),
|
|
|
|
'podcast_types' => field_enums(
|
|
|
|
$podcast_model->prefixTable('podcasts'),
|
|
|
|
'type'
|
|
|
|
),
|
2020-05-31 19:15:52 +00:00
|
|
|
];
|
|
|
|
|
2020-06-01 21:23:14 +00:00
|
|
|
echo view('podcasts/create', $data);
|
2020-05-31 19:15:52 +00:00
|
|
|
} else {
|
|
|
|
$image = $this->request->getFile('image');
|
2020-06-01 21:23:14 +00:00
|
|
|
$podcast_name = $this->request->getVar('name');
|
2020-06-12 19:31:10 +00:00
|
|
|
$image_path = save_podcast_media($image, $podcast_name, 'cover');
|
2020-05-31 19:15:52 +00:00
|
|
|
|
2020-06-12 19:31:10 +00:00
|
|
|
$podcast = new Podcast([
|
2020-05-31 19:15:52 +00:00
|
|
|
'title' => $this->request->getVar('title'),
|
2020-06-01 21:23:14 +00:00
|
|
|
'name' => $podcast_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'
|
|
|
|
),
|
|
|
|
'image' => $image_path,
|
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,
|
|
|
|
'author' => $this->request->getVar('author'),
|
|
|
|
'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(
|
|
|
|
base_url(route_to('podcasts_view', '@' . $podcast_name))
|
|
|
|
);
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-01 21:23:14 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
public function view($slug)
|
2020-06-01 21:23:14 +00:00
|
|
|
{
|
2020-06-10 15:00:12 +00:00
|
|
|
$podcast_model = new PodcastModel();
|
|
|
|
$episode_model = new EpisodeModel();
|
2020-06-01 21:23:14 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
$podcast_name = substr($slug, 1);
|
2020-06-01 21:23:14 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
$podcast = $podcast_model->where('name', $podcast_name)->first();
|
|
|
|
$data = [
|
|
|
|
'podcast' => $podcast,
|
|
|
|
'episodes' => $episode_model
|
|
|
|
->where('podcast_id', $podcast->id)
|
|
|
|
->findAll(),
|
|
|
|
];
|
2020-06-01 21:23:14 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
return view('podcasts/view', $data);
|
2020-06-01 21:23:14 +00:00
|
|
|
}
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|