init
This commit is contained in:
52
site/snippets/blocks/embed.php
Normal file
52
site/snippets/blocks/embed.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php if ($embed = $data->embed()->toEmbed()): ?>
|
||||
<?php
|
||||
$biggestImage = $embed->image()->value();
|
||||
$biggestImageSize = 0;
|
||||
|
||||
$images = $embed->images()->value();
|
||||
|
||||
if ($images) {
|
||||
foreach ($images as $image) {
|
||||
$size = $image['width'] * $image['height'];
|
||||
if ($biggestImageSize < $size) {
|
||||
$biggestImageSize = $size;
|
||||
$biggestImage = $image['url'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$iframe = str_replace('src="', 'data-src="', $embed->code()->value());
|
||||
|
||||
if (
|
||||
$data->loop()->toBool() === true || true
|
||||
) {
|
||||
preg_match('/\?v=(.*)/', $embed->url()->value(), $m);
|
||||
if ($m) {
|
||||
$iframe = preg_replace('/data-src="(.+?)"/', "data-src=\"\$1&playlist={$m[1]}&loop=1\"", $iframe);
|
||||
}
|
||||
}
|
||||
|
||||
$btnClass = $embed->providerName()->value() === 'YouTube' ? 'yt' : '';
|
||||
?>
|
||||
|
||||
<?php if ($embed->providerName()->value() === 'thealit'): ?>
|
||||
<div class="embed">
|
||||
<?= $embed->code() ?>
|
||||
</div>
|
||||
<?php elseif ($embed->providerName()->value() === 'Mixcloud'): ?>
|
||||
<?= $embed->code()->value() ?>
|
||||
<?php else: ?>
|
||||
<div class="embed">
|
||||
<div class="iframe"><?= $iframe ?></div>
|
||||
|
||||
<div>
|
||||
<img src="<?= $biggestImage ?>" loading="lazy">
|
||||
<div class="embed-btn <?= $btnClass ?>"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($data->text()->isNotEmpty()): ?>
|
||||
<div class="text-10"><?= $data->text()->html() ?></div>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
Reference in New Issue
Block a user