Skip to content

Commit

Permalink
Clean up iframe attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Jun 7, 2024
1 parent 151d799 commit 2d77a28
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
Unreleased
---------------------
- Fix #328: Missing Iframe attributes in snippet
- Fix #332: Clean up iframe attributes

1.10.3 (May 15, 2024)
---------------------
Expand Down
9 changes: 9 additions & 0 deletions models/CustomContentContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,13 @@ public function afterDelete()
public function fixVisibility()
{
}

public function getIframeAttrs(): string
{
if (empty($this->iframe_attrs)) {
return '';
}

return preg_replace('/(^|\s)srcdoc\s*=\s*("|\').+?\2/i', '', $this->iframe_attrs);
}
}
6 changes: 5 additions & 1 deletion views/container/iframe.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

use humhub\libs\Html;
use humhub\modules\custom_pages\models\CustomContentContainer;

/* @var CustomContentContainer $page */
/* @var string $url */

$cssClass = ($page->hasAttribute('cssClass') && !empty($page->cssClass)) ? $page->cssClass : 'custom-pages-page';
?>

<iframe class="<?= Html::encode($cssClass) ?>" id="iframepage" <?= $page->iframe_attrs ?? '' ?>
<iframe class="<?= Html::encode($cssClass) ?>" id="iframepage" <?= $page->getIframeAttrs() ?>
style="width:100%; height: 100%; min-height: 400px;"
src="<?= Html::encode($url); ?>"></iframe>

Expand Down
7 changes: 6 additions & 1 deletion views/global/iframe.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?php

use humhub\libs\Html;
use humhub\modules\custom_pages\models\CustomContentContainer;
use humhub\modules\custom_pages\models\Page;

/* @var CustomContentContainer $page */
/* @var string $url */
/* @var string $navigationClass */

$cssClass = ($page->hasAttribute('cssClass') && !empty($page->cssClass)) ? $page->cssClass : 'custom-pages-page';
$margin = $navigationClass == Page::NAV_CLASS_TOPNAV ? -15 : 0;
?>
Expand All @@ -14,7 +19,7 @@
}
</style>

<iframe class="<?= Html::encode($cssClass) ?>" id="iframepage" <?= $page->iframe_attrs ?? '' ?>
<iframe class="<?= Html::encode($cssClass) ?>" id="iframepage" <?= $page->getIframeAttrs() ?>
style="width:100%;height: 100%" src="<?= Html::encode($url) ?>"></iframe>

<?= Html::script(<<<JS
Expand Down
2 changes: 1 addition & 1 deletion widgets/views/snippet_iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<?=
SnippetContent::widget([
'model' => $model,
'content' => '<iframe id="' . $iframeId . '" style="border:0px;width:100%;" src="' . \yii\helpers\Html::encode($model->getPageContent()) . '"' . ($model->iframe_attrs ? ' ' . $model->iframe_attrs : '') . '></iframe>',
'content' => '<iframe id="' . $iframeId . '" style="border:0px;width:100%;" src="' . \yii\helpers\Html::encode($model->getPageContent()) . '" ' . $model->getIframeAttrs() . '></iframe>',
'navigation' => $navigation
]);
?>
Expand Down

0 comments on commit 2d77a28

Please sign in to comment.