Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HeiseBridge] fix for embedded youtube-videos #4034

Merged
merged 3 commits into from Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion bridges/HeiseBridge.php
Expand Up @@ -160,7 +160,7 @@ private function addArticleToItem($item, $article)
$article = defaultLinkTo($article, $item['uri']);

// remove unwanted stuff
foreach ($article->find('figure.branding, a-ad, div.ho-text, a-img, .opt-in__content-container, .a-toc__list, a-collapse') as $element) {
foreach ($article->find('figure.branding, a-ad, div.ho-text, a-img, .a-toc__list, a-collapse, .opt-in__description, .opt-in__footnote') as $element) {
$element->remove();
}
// reload html, as remove() is buggy
Expand All @@ -179,6 +179,30 @@ private function addArticleToItem($item, $article)
}
}

//fix for embbedded youtube-videos
$oldlink = '';
foreach ($article->find('div.video__yt-container') as &$ytvideo) {
if (preg_match('/www.youtube.*?\"/', $ytvideo->innertext, $link) && $link[0] != $oldlink) {
//save link to prevent duplicates
$oldlink = $link[0];
$ytiframe = <<<EOT
<iframe width="560" height="315" src="https://$link[0] title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
EOT;
//check if video is in header or article for correct possitioning
if (strpos($header->innertext, $link[0])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str_contains

$item['content'] .= $ytiframe;
} else {
$ytvideo->innertext .= $ytiframe;
$reloadneeded = 1;
}
}
}
if (isset($reloadneeded)) {
$article = str_get_html($article->outertext);
}

$categories = $article->find('.article-footer__topics ul.topics li.topics__item a-topic a');
foreach ($categories as $category) {
$item['categories'][] = trim($category->plaintext);
Expand Down