2021-10-26 15:54:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-10-26 15:54:56 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
2023-04-14 11:11:53 +00:00
|
|
|
use App\Entities\Podcast;
|
2021-11-23 11:54:34 +00:00
|
|
|
use App\Models\PodcastModel;
|
2021-10-26 15:54:56 +00:00
|
|
|
use CodeIgniter\Controller;
|
2021-11-23 11:54:34 +00:00
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
2021-10-26 15:54:56 +00:00
|
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
|
|
|
|
|
|
class WebmanifestController extends Controller
|
|
|
|
{
|
2021-11-23 11:54:34 +00:00
|
|
|
/**
|
2022-03-04 14:33:48 +00:00
|
|
|
* @var array<string, array<string, string>>
|
2021-11-23 11:54:34 +00:00
|
|
|
*/
|
2024-05-29 10:24:13 +00:00
|
|
|
final public const array THEME_COLORS = [
|
2021-11-23 11:54:34 +00:00
|
|
|
'pine' => [
|
2023-06-12 14:47:38 +00:00
|
|
|
'theme' => '#009486',
|
2021-11-23 11:54:34 +00:00
|
|
|
'background' => '#F0F9F8',
|
|
|
|
],
|
|
|
|
'lake' => [
|
2023-06-12 14:47:38 +00:00
|
|
|
'theme' => '#00ACE0',
|
2021-11-23 11:54:34 +00:00
|
|
|
'background' => '#F0F7F9',
|
|
|
|
],
|
|
|
|
'jacaranda' => [
|
2023-06-12 14:47:38 +00:00
|
|
|
'theme' => '#562CDD',
|
2021-11-23 11:54:34 +00:00
|
|
|
'background' => '#F2F0F9',
|
|
|
|
],
|
|
|
|
'crimson' => [
|
2023-06-12 14:47:38 +00:00
|
|
|
'theme' => '#F24562',
|
2021-11-23 11:54:34 +00:00
|
|
|
'background' => '#F9F0F2',
|
|
|
|
],
|
|
|
|
'amber' => [
|
2023-06-12 14:47:38 +00:00
|
|
|
'theme' => '#FF6224',
|
2021-11-23 11:54:34 +00:00
|
|
|
'background' => '#F9F3F0',
|
|
|
|
],
|
|
|
|
'onyx' => [
|
2023-06-12 14:47:38 +00:00
|
|
|
'theme' => '#040406',
|
2021-11-23 11:54:34 +00:00
|
|
|
'background' => '#F3F3F7',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2021-10-26 15:54:56 +00:00
|
|
|
public function index(): ResponseInterface
|
|
|
|
{
|
2023-06-05 09:28:32 +00:00
|
|
|
helper('misc');
|
|
|
|
|
2021-10-26 15:54:56 +00:00
|
|
|
$webmanifest = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'name' => esc(service('settings') ->get('App.siteName')),
|
2022-03-04 14:33:48 +00:00
|
|
|
'description' => esc(service('settings') ->get('App.siteDescription')),
|
2023-06-12 14:47:38 +00:00
|
|
|
'lang' => service('request')
|
2021-11-23 11:54:34 +00:00
|
|
|
->getLocale(),
|
2023-06-12 14:47:38 +00:00
|
|
|
'start_url' => base_url(),
|
|
|
|
'display' => 'standalone',
|
|
|
|
'orientation' => 'portrait',
|
|
|
|
'theme_color' => self::THEME_COLORS[service('settings')->get('App.theme')]['theme'],
|
2021-11-23 11:54:34 +00:00
|
|
|
'background_color' => self::THEME_COLORS[service('settings')->get('App.theme')]['background'],
|
2023-06-12 14:47:38 +00:00
|
|
|
'icons' => [
|
2021-10-26 15:54:56 +00:00
|
|
|
[
|
2023-06-12 14:47:38 +00:00
|
|
|
'src' => get_site_icon_url('192'),
|
|
|
|
'type' => 'image/png',
|
2021-10-26 15:54:56 +00:00
|
|
|
'sizes' => '192x192',
|
|
|
|
],
|
|
|
|
[
|
2023-06-12 14:47:38 +00:00
|
|
|
'src' => get_site_icon_url('512'),
|
|
|
|
'type' => 'image/png',
|
2021-10-26 15:54:56 +00:00
|
|
|
'sizes' => '512x512',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
return $this->response->setJSON($webmanifest);
|
|
|
|
}
|
2021-11-23 11:54:34 +00:00
|
|
|
|
|
|
|
public function podcastManifest(string $podcastHandle): ResponseInterface
|
|
|
|
{
|
|
|
|
if (
|
2023-04-14 11:11:53 +00:00
|
|
|
! ($podcast = (new PodcastModel())->getPodcastByHandle($podcastHandle)) instanceof Podcast
|
2021-11-23 11:54:34 +00:00
|
|
|
) {
|
|
|
|
throw PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
$webmanifest = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'name' => esc($podcast->title),
|
2023-06-21 16:17:11 +00:00
|
|
|
'short_name' => $podcast->at_handle,
|
2023-06-12 14:47:38 +00:00
|
|
|
'description' => $podcast->description,
|
|
|
|
'lang' => $podcast->language_code,
|
|
|
|
'start_url' => $podcast->link,
|
2023-06-21 16:17:11 +00:00
|
|
|
'scope' => '/' . $podcast->at_handle,
|
2023-06-12 14:47:38 +00:00
|
|
|
'display' => 'standalone',
|
|
|
|
'orientation' => 'portrait',
|
|
|
|
'theme_color' => self::THEME_COLORS[service('settings')->get('App.theme')]['theme'],
|
2021-11-23 11:54:34 +00:00
|
|
|
'background_color' => self::THEME_COLORS[service('settings')->get('App.theme')]['background'],
|
2023-06-12 14:47:38 +00:00
|
|
|
'icons' => [
|
2021-11-23 11:54:34 +00:00
|
|
|
[
|
2023-06-12 14:47:38 +00:00
|
|
|
'src' => $podcast->cover->webmanifest192_url,
|
|
|
|
'type' => $podcast->cover->webmanifest192_mimetype,
|
2021-11-23 11:54:34 +00:00
|
|
|
'sizes' => '192x192',
|
|
|
|
],
|
|
|
|
[
|
2023-06-12 14:47:38 +00:00
|
|
|
'src' => $podcast->cover->webmanifest512_url,
|
|
|
|
'type' => $podcast->cover->webmanifest512_mimetype,
|
2021-11-23 11:54:34 +00:00
|
|
|
'sizes' => '512x512',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
return $this->response->setJSON($webmanifest);
|
|
|
|
}
|
2021-10-26 15:54:56 +00:00
|
|
|
}
|