Newer
Older

Yassine Doghri
committed
<?php
declare(strict_types=1);
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace App\Controllers;

Yassine Doghri
committed
use App\Models\PodcastModel;

Yassine Doghri
committed
use CodeIgniter\Controller;

Yassine Doghri
committed
use CodeIgniter\Exceptions\PageNotFoundException;

Yassine Doghri
committed
use CodeIgniter\HTTP\ResponseInterface;
class WebmanifestController extends Controller
{

Yassine Doghri
committed
/**
* @var array<string, string>
*/
public const THEME_COLORS = [
'pine' => [
'theme' => '#009486',
'background' => '#F0F9F8',
],
'lake' => [
'theme' => '#00ACE0',
'background' => '#F0F7F9',
],
'jacaranda' => [
'theme' => '#562CDD',
'background' => '#F2F0F9',
],
'crimson' => [
'theme' => '#F24562',
'background' => '#F9F0F2',
],
'amber' => [
'theme' => '#FF6224',
'background' => '#F9F3F0',
],
'onyx' => [
'theme' =>
'#040406',
'background' => '#F3F3F7',
],
];

Yassine Doghri
committed
public function index(): ResponseInterface
{
$webmanifest = [
'name' => service('settings')
->get('App.siteName'),
'description' => service('settings')
->get('App.siteDescription'),

Yassine Doghri
committed
'lang' => service('request')
->getLocale(),
'start_url' => base_url(),

Yassine Doghri
committed
'display' => 'minimal-ui',

Yassine Doghri
committed
'orientation' => 'portrait',
'theme_color' => self::THEME_COLORS[service('settings')->get('App.theme')]['theme'],
'background_color' => self::THEME_COLORS[service('settings')->get('App.theme')]['background'],

Yassine Doghri
committed
'icons' => [
[
'src' => service('settings')
->get('App.siteIcon')['192'],
'type' => 'image/png',
'sizes' => '192x192',
],
[
'src' => service('settings')
->get('App.siteIcon')['512'],
'type' => 'image/png',
'sizes' => '512x512',
],
],
];
return $this->response->setJSON($webmanifest);
}

Yassine Doghri
committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
public function podcastManifest(string $podcastHandle): ResponseInterface
{
if (
($podcast = (new PodcastModel())->getPodcastByHandle($podcastHandle)) === null
) {
throw PageNotFoundException::forPageNotFound();
}
$webmanifest = [
'name' => $podcast->title,
'short_name' => '@' . $podcast->handle,
'description' => $podcast->description,
'lang' => $podcast->language_code,
'start_url' => $podcast->link,
'display' => 'minimal-ui',
'orientation' => 'portrait',
'theme_color' => self::THEME_COLORS[service('settings')->get('App.theme')]['theme'],
'background_color' => self::THEME_COLORS[service('settings')->get('App.theme')]['background'],
'icons' => [
[
'src' => $podcast->cover->webmanifest192_url,
'type' => $podcast->cover->webmanifest192_mimetype,
'sizes' => '192x192',
],
[
'src' => $podcast->cover->webmanifest512_url,
'type' => $podcast->cover->webmanifest512_mimetype,
'sizes' => '512x512',
],
],
];
return $this->response->setJSON($webmanifest);
}