Skip to content

Commit

Permalink
Code optimizations and better validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopetkov committed Nov 22, 2020
1 parent 627eb37 commit 8ae9a3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions components/embedElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use BearFramework\App;

$app = App::get();
$context = $app->contexts->get(__FILE__);
$context = $app->contexts->get(__DIR__);

$allowedHosts = [
'skydrive.live.com',
Expand Down Expand Up @@ -114,7 +114,17 @@
$aspectRatioParts = explode(':', $aspectRatio);
$paddingBottom = '75%';
if (sizeof($aspectRatioParts) === 2 && is_numeric($aspectRatioParts[0]) && is_numeric($aspectRatioParts[1])) {
$paddingBottom = ((float) $aspectRatioParts[1] / (float) $aspectRatioParts[0] * 100) . '%';
$widthRatio = (float) $aspectRatioParts[0];
$heightRatio = (float) $aspectRatioParts[1];
if ($widthRatio > 0 && $heightRatio > 0) {
if ($heightRatio / $widthRatio > 10) { // prevent super tall element
$heightRatio = $widthRatio * 10;
}
$paddingBottomValue = ($heightRatio / $widthRatio * 100);
if ($paddingBottomValue >= 0) {
$paddingBottom = $paddingBottomValue . '%';
}
}
}
$containerStyle = 'padding-bottom:' . $paddingBottom . ';';
} else {
Expand All @@ -134,8 +144,11 @@
}
}
?><html>
<head>
<link rel="client-packages-embed" name="-bearcms-embed-element-responsively-lazy">
</head>
<body><?= $content ?></body>

<head>
<link rel="client-packages-embed" name="-bearcms-embed-element-responsively-lazy">
</head>

<body><?= $content ?></body>

</html>
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$app->bearCMS->addons
->register('bearcms/embed-element-addon', function(\BearCMS\Addons\Addon $addon) use ($app) {
$addon->initialize = function() use ($app) {
$context = $app->contexts->get(__FILE__);
$context = $app->contexts->get(__DIR__);

$context->assets->addDir('assets');

Expand Down

0 comments on commit 8ae9a3b

Please sign in to comment.