Skip to content

Commit

Permalink
Feature/hantera embed urls i municipio istllet fr komponenten iframe …
Browse files Browse the repository at this point in the history
…cu 8693h2a8z (#367)

* refact: Moving handling of generated urls to Municipio

* feat: Added Spotify and SoundCloud as named suppliers to the Acceptance component

* Removed commented line of code
  • Loading branch information
Anna authored Jan 22, 2024
1 parent 7c348c1 commit cf54d6f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 73 deletions.
18 changes: 16 additions & 2 deletions source/php/Component/Acceptance/Acceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,21 @@ public function getSuppliers()
'https://twoday.se/privacy-policy',
false,
'login'
)
),
new Supplier(
'Spotify',
array('www.spotify.com', 'open.spotify.com', 'spotify.com'),
'https://www.spotify.com/se/legal/privacy-policy/',
true,
'music'
),
new Supplier(
'Soundcloud',
array('www.soundcloud.com', 'w.soundcloud.com', 'soundcloud.com'),
'https://soundcloud.com/pages/privacy',
true,
'music'
),
);

if (function_exists('apply_filters')) {
Expand Down Expand Up @@ -250,4 +264,4 @@ public function __construct(
$this->requiresAccept = $requiresAccept;
$this->systemType = $systemType;
}
}
}
73 changes: 2 additions & 71 deletions source/php/Component/Iframe/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function init()
}

if (isset($src)) {
$url = $this->buildEmbedUrl($src);
$this->data['attributeList']['src'] = $url;
$this->data['attributeList']['src'] = $src;

if (empty($poster) && function_exists('apply_filters')) {
$this->data['poster'] = apply_filters('ComponentLibrary/Iframe/Poster', $url);
Expand All @@ -57,75 +56,7 @@ public function init()

$this->data['embeddedDomain'] = $this->getDomainFromUrl($src);
}
/**
* Build embed url
*
* @param string $src Arbitrary embed url
* @return string $src Correct embed url
*/
private function buildEmbedUrl($src)
{
$srcParsed = parse_url($src);

$ytParams = 'autoplay=1&showinfo=0&rel=0&mute=1&modestbranding=1&cc_load_policy=1';

switch ($srcParsed['host']) {
case 'youtube.com':
case 'www.youtube.com':
/*
Replacing the path with /embed/ and then
adding the v query parameter to the path
and removing the v parameter from the
query string.
*/
$srcParsed['host'] = 'youtube.com';
$srcParsed['path'] = '/embed/';

if (isset($srcParsed['query'])) {
parse_str($srcParsed['query'], $query);
if (isset($query['v'])) {
$srcParsed['path'] .= $query['v'];
$srcParsed['query'] = $ytParams;
}
}
break;
case 'youtu.be':
$srcParsed['host'] = 'youtube.com';
if (isset($srcParsed['path'])) {
$srcParsed['path'] = '/embed/' . $srcParsed['path'];
$srcParsed['query'] = $ytParams;
}
break;
case 'vimeo.com':
case 'www.vimeo.com':
$srcParsed['host'] = 'player.vimeo.com';
if (isset($srcParsed['path'])) {
$srcParsed['path'] = '/video' . $srcParsed['path'] . "?autoplay=1&autopause=0&muted=1";
}
break;
case 'spotify.com':
case 'www.spotify.com':
case 'open.spotify.com':
$srcParsed['host'] = 'open.spotify.com';
$srcParsed['path'] = '/embed' . $srcParsed['path'];
$srcParsed['query'] = 'utm_source=oembed';
break;
default:
break;
}

$scheme = $srcParsed['scheme'] ?? 'https';
$embedUrl = $scheme . '://' . strtolower($srcParsed['host']);

if (isset($srcParsed['path'])) {
$embedUrl .= $srcParsed['path'];
}
if (isset($srcParsed['query'])) {
$embedUrl .= '?' . $srcParsed['query'];
}

return $embedUrl;
}


/**
* Gets the domain from a given URL.
Expand Down

0 comments on commit cf54d6f

Please sign in to comment.