2020-10-08 16:38:30 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @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;
|
|
|
|
|
2020-10-08 16:38:30 +00:00
|
|
|
if (!function_exists('host_url')) {
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
{
|
2020-10-19 16:47:22 +00:00
|
|
|
if (isset($_SERVER['HTTP_HOST'])) {
|
2020-10-08 16:38:30 +00:00
|
|
|
$protocol =
|
|
|
|
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
|
|
|
|
$_SERVER['SERVER_PORT'] == 443
|
|
|
|
? 'https://'
|
|
|
|
: 'http://';
|
2020-10-19 16:47:22 +00:00
|
|
|
return $protocol . $_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
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
|
|
if (!function_exists('extract_params_from_episode_uri')) {
|
|
|
|
/**
|
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-05-06 14:00:48 +00:00
|
|
|
'~@(?P<podcastName>[a-zA-Z0-9\_]{1,32})\/episodes\/(?P<episodeSlug>[a-zA-Z0-9\-]{1,191})~',
|
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-05-06 14:00:48 +00:00
|
|
|
!array_key_exists('podcastName', $matches) ||
|
|
|
|
!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 [
|
|
|
|
'podcastName' => $matches['podcastName'],
|
|
|
|
'episodeSlug' => $matches['episodeSlug'],
|
|
|
|
];
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
}
|