Skip to content

Commit

Permalink
Config-form: make guest url invisible if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Themroc committed Feb 15, 2022
1 parent d93105c commit 8a125e2
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 25 deletions.
28 changes: 23 additions & 5 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,44 @@ class Module extends \humhub\modules\content\components\ContentContainerModule
/**
* @inheritdoc
*/
public function getConfigUrl()
public function getConfigUrl ()
{
return Url::to(['/iframe/admin']);
}

/**
* @inheritdoc
*/
public function disable()
public function disable ()
{
// Cleanup all module data, don't remove the parent::disable()!!!
parent::disable();
}

public function getSetting($key, $frame=null)
public function update ()
{
$ver= $this->getSetting('//version');
if (empty($ver) || $ver < 1) {
foreach ($this->getFrames() as $frame) {
$url= $this->getSetting('url', $frame);
$url_reg= $this->getSetting('url_reg', $frame);
if (empty($url_reg)) {
$this->settings->set($frame.'/url_reg', $url);
} else {
$this->settings->set($frame.'/url_guest', $url);
}
$this->settings->delete($frame.'/url');
}
$this->settings->set('//version', 1);
}
}

public function getSetting ($key, $frame=null)
{
return $this->settings->get(($frame==null ? '' : $frame.'/') . $key);
}

public function getUrl($page, $params=null)
public function getUrl ($page, $params=null)
{
$url= [ '/iframe/'.$page ];
if (is_array($params))
Expand All @@ -46,7 +64,7 @@ public function getUrl($page, $params=null)
return Url::to($url);
}

public function getFrames()
public function getFrames ()
{
$frames= $this->settings->get('/frames');
if ($frames == null)
Expand Down
16 changes: 12 additions & 4 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,38 @@

class AdminController extends Controller
{
const MH_MIN_REL= '0.2.1';

public $adminOnly= true;
public $subLayout= '@iframe/views/layouts/admin';

public function init()
public function init ()
{
if (Yii::$app->getModule('mod-helper')===null)
if (null == $mod= Yii::$app->getModule('mod-helper'))
$this->subLayout= null;
if (version_compare($mod->getVersion(), self::MH_MIN_REL) < 0)
$this->subLayout= null;

return parent::init();
}


/**
* Render admin only page
*
* @return string
*/
public function actionIndex()
public function actionIndex ()
{
if ($this->subLayout===null)
return $this->render('error', [
'msg'=> 'Please install and activate the <a href="https://github.com/Themroc/humhub_mod-helper" target="_blank">Mod-Helper plugin</a>.',
'msg'=> 'Please install and activate the'
.' <a href="https://github.com/Themroc/humhub_mod-helper" target="_blank">Mod-Helper plugin</a>,'
.' at least version '.self::MH_MIN_REL.'.',
]);

$mod= Yii::$app->getModule('iframe');
$mod->update();
$frame= Yii::$app->request->get('frame');

if (Yii::$app->request->get('delete') == 1) {
Expand Down
15 changes: 10 additions & 5 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ class IndexController extends Controller
{
public $subLayout = "@iframe/views/layouts/default";

public function actionIndex()
public function actionIndex ()
{
$mod= Yii::$app->getModule('iframe');
$uid= Yii::$app->user->id;
$mod->update();
$frame= Yii::$app->request->get('frame');
if (Yii::$app->user->isGuest && !$mod->getSetting('guest', $frame))
return $this->render('error', [ 'msg'=> 'Sorry, guests are not allowed here.']);

$uid= Yii::$app->user->id;
$top_data= $mod->getSetting('top_data', $frame);
$url= $mod->getSetting('url_reg', $frame);
if (empty($url) || Yii::$app->user->isGuest)
$url= $mod->getSetting('url', $frame);
if (Yii::$app->user->isGuest)
$url= $mod->getSetting('url_guest', $frame);
if (empty($url))
$url= $mod->getSetting('url_reg', $frame);

if (Yii::$app->user->isGuest) {
$user= Yii::$app->request->userIP;
Expand Down
6 changes: 3 additions & 3 deletions messages/de/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
'This will show up under the icon'=> 'Dies wird unter dem Symbol angezeigt',
'Sort order'=> 'Sortierreihenfolge',
'Determines topbar menu position'=> 'Legt die topbar Menüposition fest',
'Visible for guests'=> 'Sichtbar für Gäste',
// 'URL'=> '',
'URL for registered users'=> 'URL für registrierte Benutzer',
'URL for guests'=> 'URL für Gäste',
'The webpage to be shown. @UID@, @USER@, @EMAIL@ and @COLOR@ will be replaced by the respective values.'=>
'Die anzuzeigende Webseite. @UID@, @USER@, @EMAIL@ und @COLOR@ werden durch die jeweiligen Werte ersetzt.',
'URL for registered users'=> 'URL für registrierte Benutzer',
'Visible for guests'=> 'Sichtbar für Gäste',
'If empty, the above will be used.'=> 'Wenn leer, wird der Wert von oben verwendet.',
'HTML to add above the iframe'=> 'HTML oberhalb des iframes',
'Delete'=> 'Löschen',
Expand Down
18 changes: 11 additions & 7 deletions models/AdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm
public $sort;
public $size;
public $guest;
public $url;
public $url_reg;
public $url_guest;
public $top_data;

protected $vars= [
Expand All @@ -43,20 +43,24 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm
'items'=> [self::class, 'sizeModes']
],
],
'url_reg'=> [
'label'=> 'URL for registered users',
'hints'=> 'The webpage to be shown. @UID@, @USER@, @EMAIL@ and @COLOR@ will be replaced by the respective values.',
],
'guest'=> [
'label'=> 'Visible for guests',
'rules'=> ['in', 'range'=> [0, 1]],
'form'=> [
'type'=> 'checkbox',
],
],
'url'=> [
'label'=> 'URL',
'hints'=> 'The webpage to be shown. @UID@, @USER@, @EMAIL@ and @COLOR@ will be replaced by the respective values.',
],
'url_reg'=> [
'label'=> 'URL for registered users',
'url_guest'=> [
# 'url'=> [
'label'=> 'URL for guests',
'hints'=> 'If empty, the above will be used.',
'form'=> [
'visible'=> ['guest'=> 1],
],
],
'top_data'=> [
'label'=> 'HTML to add above the iframe',
Expand Down
7 changes: 7 additions & 0 deletions views/index/error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

echo '<div class="panel panel-default">'. "\n";
echo ' <div class="panel-body">' . "\n";
echo ' '. $msg . "\n";
echo ' </div>' . "\n";
echo '</div>' . "\n";
2 changes: 1 addition & 1 deletion widgets/AdminTabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AdminTabs extends \humhub\widgets\BaseMenu
*/
public $template = "@humhub/widgets/views/tabMenu";

public function init()
public function init ()
{
$controller= Yii::$app->controller;
$frame= Yii::$app->request->get('frame');
Expand Down

0 comments on commit 8a125e2

Please sign in to comment.