Skip to content

Commit

Permalink
#4558 - Build-in API support (fix YouTube url processing)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Sep 25, 2024
1 parent d608912 commit f41f61f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions inc/classes/BxDolEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function addJsCss ()

public function getData ($sUrl, $sTheme)
{
$sUrl = $this->cleanYoutubeUrl($sUrl);
$sData = BxDolEmbedQuery::getLocal($sUrl, $sTheme, $this->_sTableName);
if(!$sData) {
$sData = $this->getDataFromApi($sUrl, $sTheme);
Expand All @@ -97,6 +98,26 @@ public function getDataFromApi ($sUrl, $sTheme)
{
// override this function in particular embed provider class
}

function cleanYoutubeUrl($url) {
$parsedUrl = parse_url($url);
if (isset($parsedUrl['host']) && $parsedUrl['host'] === 'youtu.be') {
if (isset($parsedUrl['query'])) {
parse_str($parsedUrl['query'], $queryParams);
if (isset($queryParams['si'])) {
unset($queryParams['si']);
}
$queryString = http_build_query($queryParams);
$cleanUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path'];
if (!empty($queryString)) {
$cleanUrl .= '?' . $queryString;
}
return $cleanUrl;
}
return $url;
}
return $url;
}
}

/** @} */

0 comments on commit f41f61f

Please sign in to comment.