2020-10-08 16:38:30 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-05-06 14:00:48 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
use CodeIgniter\HTTP\URI;
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('host_url')) {
|
2020-10-08 16:38:30 +00:00
|
|
|
/**
|
|
|
|
* Return the host URL to use in views
|
|
|
|
*/
|
2021-05-12 14:00:25 +00:00
|
|
|
function host_url(): ?string
|
2020-10-08 16:38:30 +00:00
|
|
|
{
|
2023-08-29 12:58:20 +00:00
|
|
|
$superglobals = service('superglobals');
|
|
|
|
if ($superglobals->server('HTTP_HOST') !== null) {
|
2020-10-08 16:38:30 +00:00
|
|
|
$protocol =
|
2023-08-29 12:58:20 +00:00
|
|
|
($superglobals->server('HTTPS') !== null && $superglobals->server('HTTPS') !== 'off') ||
|
|
|
|
(int) $superglobals->server('SERVER_PORT') === 443
|
2020-10-08 16:38:30 +00:00
|
|
|
? 'https://'
|
|
|
|
: 'http://';
|
2023-08-29 12:58:20 +00:00
|
|
|
return $protocol . $superglobals->server('HTTP_HOST') . '/';
|
2020-10-08 16:38:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return null;
|
2020-10-08 16:38:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-04 17:03:20 +00:00
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
2022-09-28 15:02:09 +00:00
|
|
|
/**
|
|
|
|
* Return the host URL to use in views
|
|
|
|
*/
|
|
|
|
if (! function_exists('current_domain')) {
|
|
|
|
/**
|
|
|
|
* Returns instance's domain name
|
|
|
|
*/
|
|
|
|
function current_domain(): string
|
|
|
|
{
|
2023-06-13 16:05:02 +00:00
|
|
|
/** @var URI $uri */
|
2022-09-28 15:02:09 +00:00
|
|
|
$uri = current_url(true);
|
2023-06-13 16:05:02 +00:00
|
|
|
|
2022-09-28 15:02:09 +00:00
|
|
|
return $uri->getHost() . ($uri->getPort() ? ':' . $uri->getPort() : '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('extract_params_from_episode_uri')) {
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2021-05-14 17:59:35 +00:00
|
|
|
* Returns podcast name and episode slug from episode string
|
|
|
|
*
|
|
|
|
* @return array<string, string>|null
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
2021-05-12 14:00:25 +00:00
|
|
|
function extract_params_from_episode_uri(URI $episodeUri): ?array
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
preg_match(
|
2021-08-13 11:07:29 +00:00
|
|
|
'~@(?P<podcastHandle>[a-zA-Z0-9\_]{1,32})\/episodes\/(?P<episodeSlug>[a-zA-Z0-9\-]{1,128})~',
|
2021-04-02 17:20:02 +00:00
|
|
|
$episodeUri->getPath(),
|
2021-04-14 15:58:40 +00:00
|
|
|
$matches,
|
2021-04-02 17:20:02 +00:00
|
|
|
);
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
if ($matches === []) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
if (
|
2021-07-26 13:10:46 +00:00
|
|
|
! array_key_exists('podcastHandle', $matches) ||
|
2021-05-19 16:35:13 +00:00
|
|
|
! array_key_exists('episodeSlug', $matches)
|
2021-04-02 17:20:02 +00:00
|
|
|
) {
|
2021-05-06 14:00:48 +00:00
|
|
|
return null;
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
return [
|
2021-07-26 13:10:46 +00:00
|
|
|
'podcastHandle' => $matches['podcastHandle'],
|
2023-06-12 14:47:38 +00:00
|
|
|
'episodeSlug' => $matches['episodeSlug'],
|
2021-05-06 14:00:48 +00:00
|
|
|
];
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
}
|