Skip to content

Commit

Permalink
Merge pull request #333 from humhub/fix/267-iframe-src-saving
Browse files Browse the repository at this point in the history
Fix saving of iframe URL by space admin
  • Loading branch information
luke- committed Jun 19, 2024
2 parents 151d799 + 7a61a4d commit 2053154
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Changelog
=========

Unreleased
1.10.4 (Unreleased)
---------------------
- Fix #328: Missing Iframe attributes in snippet
- Fix #333: Fix saving of iframe URL by space admin

1.10.3 (May 15, 2024)
---------------------
Expand Down
44 changes: 24 additions & 20 deletions models/CustomContentContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
* Note: Subclasses may container global types not bound to any ContentContainerActiveRecord
*
* The followings are the available columns in table 'custom_pages_page':
* @property integer $id
* @property integer $type
* @property int $id
* @property int $type
* @property string $title
* @property string $icon
* @property string $page_content
* @property string $iframe_attrs
* @property integer $sort_order
* @property integer $admin_only
* @property integer $in_new_window
* @property int $sort_order
* @property int $admin_only
* @property int $in_new_window
* @property string $target
* @property string $cssClass
* @property string $url
Expand All @@ -41,9 +41,9 @@ abstract class CustomContentContainer extends ContentActiveRecord
use PhpPageContainer;
use TemplatePageContainer;

const VISIBILITY_ADMIN_ONLY = 3;
const VISIBILITY_PRIVATE = 0;
const VISIBILITY_PUBLIC = 1;
public const VISIBILITY_ADMIN_ONLY = 3;
public const VISIBILITY_PRIVATE = 0;
public const VISIBILITY_PUBLIC = 1;

/**
* @inheritdoc
Expand All @@ -56,7 +56,7 @@ abstract class CustomContentContainer extends ContentActiveRecord
private $_target;

/**
* @var integer special field for template based pages specifying the layout template id
* @var int special field for template based pages specifying the layout template id
*/
public $templateId;

Expand All @@ -71,7 +71,7 @@ public function afterFind()

if ($this->admin_only) {
$this->visibility = static::VISIBILITY_ADMIN_ONLY;
} else if ($this->content->isPublic()) {
} elseif ($this->content->isPublic()) {
$this->visibility = static::VISIBILITY_PUBLIC;
} else {
$this->visibility = static::VISIBILITY_PRIVATE;
Expand All @@ -81,7 +81,7 @@ public function afterFind()
/**
* Returns the database content field. Note this does not render the any content.
*/
public abstract function getPageContent();
abstract public function getPageContent();

/**
* Returns the database content field. Note this does not render the any content.
Expand All @@ -94,37 +94,37 @@ public function getPageContentProperty()
/**
* Returns all allowed templates for a page container class.
*/
public abstract function getAllowedTemplateSelection();
abstract public function getAllowedTemplateSelection();

/**
* Returns the page container class label.
* @return string
*/
public abstract function getLabel();
abstract public function getLabel();

/**
* Returns the view file path for PHP based content.
* @return string
*/
public abstract function getPhpViewPath();
abstract public function getPhpViewPath();

/**
* @return string
*/
public abstract function getEditUrl();
abstract public function getEditUrl();

/**
* @return string
*/
public abstract function getPageType();
abstract public function getPageType();

/**
* @return array
*/
public function getVisibilitySelection()
{
$result = [
static::VISIBILITY_ADMIN_ONLY => Yii::t('CustomPagesModule.visibility', 'Admin only')
static::VISIBILITY_ADMIN_ONLY => Yii::t('CustomPagesModule.visibility', 'Admin only'),
];

if ($this->isGuestAccessEnabled()) {
Expand All @@ -142,7 +142,7 @@ public function getVisibilitySelection()
/**
* Helper function can be replaced with AuthHelper::isGuestAccessEnabled() after min-version 1.4
*
* @return boolean
* @return bool
*/
protected function isGuestAccessEnabled()
{
Expand Down Expand Up @@ -174,7 +174,7 @@ public function defaultAttributeLabels()
'targetUrl' => Yii::t('CustomPagesModule.components_Container', 'Target Url'),
'templateId' => Yii::t('CustomPagesModule.components_Container', 'Template Layout'),
'admin_only' => Yii::t('CustomPagesModule.models_Page', 'Only visible for admins'),
'visibility' => Yii::t('CustomPagesModule.models_Page', 'Visibility')
'visibility' => Yii::t('CustomPagesModule.models_Page', 'Visibility'),
];
}

Expand Down Expand Up @@ -241,7 +241,11 @@ private function getRulesByContentType()
return $result;
}

if (PhpType::isType($type) || LinkType::isType($type) || HtmlType::isType($type) || MarkdownType::isType($type) || IframeType::isType($type)) {
if (PhpType::isType($type) ||
LinkType::isType($type) ||
HtmlType::isType($type) ||
MarkdownType::isType($type) ||
(IframeType::isType($type) && Yii::$app->user->isAdmin())) {
$result[] = ['page_content', 'required'];
}

Expand Down
30 changes: 14 additions & 16 deletions models/IframeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,26 @@

namespace humhub\modules\custom_pages\models;


use Yii;
use yii\widgets\ActiveForm;

class IframeType extends ContentType
{

const ID = 3;
public const ID = 3;

protected $hasContent = false;


function getId()
public function getId()
{
return static::ID;
}

function getLabel()
public function getLabel()
{
return Yii::t('CustomPagesModule.base', 'Iframe');
}

function getDescription()
public function getDescription()
{
return Yii::t('CustomPagesModule.base', 'Will embed the the result of a given url as an iframe element.');
}
Expand All @@ -47,18 +44,19 @@ public function getViewName()

public function renderFormField(ActiveForm $form, CustomContentContainer $page)
{
$targetUrlField = $form->field($page, $page->getPageContentProperty())->label($page->getAttributeLabel('targetUrl'));
if ($page->iframe_attrs && !Yii::$app->user->isAdmin()) {
$formField = $targetUrlField->textInput(['class' => 'form-control', 'disabled' => 'disabled'])->hint(Yii::t('CustomPagesModule.views_common_edit', 'You need to be a system administrator to edit this URL'));
} else {
$formField = $targetUrlField->textInput(['class' => 'form-control'])->hint(Yii::t('CustomPagesModule.views_common_edit', 'e.g. http://www.example.de'));
}
$targetUrlField = $form->field($page, $page->getPageContentProperty())
->label($page->getAttributeLabel('targetUrl'));

if (Yii::$app->user->isAdmin()) {
$formField .=
$form->field($page, 'iframe_attrs')->textInput(['class' => 'form-control'])->hint(Yii::t('CustomPagesModule.views_common_edit', 'e.g. allowfullscreen allow="camera; microphone"'));
$formField = $targetUrlField
->hint(Yii::t('CustomPagesModule.views_common_edit', 'e.g. http://www.example.de'));
$formField .= $form->field($page, 'iframe_attrs')
->hint(Yii::t('CustomPagesModule.views_common_edit', 'e.g. allowfullscreen allow="camera; microphone"'));
} else {
$formField = $targetUrlField->textInput(['disabled' => 'disabled'])
->hint(Yii::t('CustomPagesModule.views_common_edit', 'You need to be a system administrator to edit this URL'));
}

return $formField;
}
}
}
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Custom Pages",
"description": "Create custom pages and widgets and share them with your users. Take advantage of a wide range of editing options, including HTML and Markdown.",
"keywords": ["pages", "custom", "iframe", "markdown", "link", "navigation", "spaces"],
"version": "1.10.3",
"version": "1.10.4",
"homepage": "https://github.com/humhub/custom-pages",
"humhub": {
"minVersion": "1.14"
Expand Down

0 comments on commit 2053154

Please sign in to comment.