From 5d0e0086132a69c1f56eca9f9bf84950f245d951 Mon Sep 17 00:00:00 2001 From: Themroc <7hemroc@gmail.com> Date: Mon, 7 Feb 2022 21:15:34 +0100 Subject: [PATCH] Add guest visibility and top html, code cleanup --- Events.php | 10 +++++++--- README.md | 5 +++++ controllers/IndexController.php | 32 ++++++++++++++++++++++++++++++++ models/AdminForm.php | 13 +++++++++++++ module.json | 2 +- views/index/index.php | 27 ++------------------------- 6 files changed, 60 insertions(+), 29 deletions(-) diff --git a/Events.php b/Events.php index 87aedb1..8ad17d3 100644 --- a/Events.php +++ b/Events.php @@ -11,16 +11,20 @@ class Events * * @param $event */ - public static function onTopMenuInit($event) + public static function onTopMenuInit ($event) { $mod= Yii::$app->getModule('iframe'); + $guest= Yii::$app->user->isGuest; foreach ($mod->getFrames() as $f) { + if ($guest && (! $mod->getSetting('guest', $f))) + continue; $prefix= $f.'/'; $label= $mod->getSetting('label', $f); $event->sender->addItem([ 'icon'=> '', 'label'=> $label, + 'top_data'=> $mod->getSetting('top_data', $f), 'url'=> $mod->getUrl('index', ['frame'=> $label]), 'sortOrder'=> $mod->getSetting('sort', $f), 'isActive'=> self::checkActive('index', $f), @@ -33,7 +37,7 @@ public static function onTopMenuInit($event) * * @param $event */ - public static function onAdminMenuInit($event) + public static function onAdminMenuInit ($event) { $mod= Yii::$app->getModule('iframe'); if (! Yii::$app->controller->module || ! Yii::$app->controller->module->id == 'iframe') @@ -54,7 +58,7 @@ public static function onAdminMenuInit($event) * * @param $event */ - public static function checkActive($page, $frame= null) + public static function checkActive ($page, $frame= null) { if ((! Yii::$app->controller->module) || Yii::$app->controller->module->id != 'iframe' || Yii::$app->controller->id != $page) return 0; diff --git a/README.md b/README.md index 58d7eea..8c0c022 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ ### Description Add (nearly) fullscreen iframes to topbar. +### Screenshots +![Themroc/humhub_iframe screenshot 1](https://raw.githubusercontent.com/Themroc/humhub_iframe/master/assets/screen1.jpg) +![Themroc/humhub_iframe screenshot 2](https://raw.githubusercontent.com/Themroc/humhub_iframe/master/assets/screen2.jpg) + ### Installation +Install and activate https://github.com/Themroc/humhub_mod-helper. Unzip into */protected/modules folder, activate in Administration / Modules. __Module website:__ diff --git a/controllers/IndexController.php b/controllers/IndexController.php index 2eaa90a..cb58a70 100644 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -11,7 +11,39 @@ class IndexController extends Controller public function actionIndex() { + $mod= Yii::$app->getModule('iframe'); + $uid= Yii::$app->user->id; + $frame= Yii::$app->request->get('frame'); + $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) { + $user= Yii::$app->request->userIP; + $email= ''; + } else { + $user= Yii::$app->user->identity->username; + $email= Yii::$app->user->identity->email; + } + + $ustr= $user.$email.$uid; + $color= ''; + for ($x=0; $x<6; $x++) { + $c= ord(substr($ustr, $x, 1)); + $color.= dechex($c & 0x0f); + } + + $url= str_replace('@UID@', $uid, $url); + $url= str_replace('@USER@', urlencode($user), $url); + $url= str_replace('@EMAIL@', urlencode($email), $url); + $url= str_replace('@COLOR@', $color, $url); + return $this->render('index', [ + 'mod'=> $mod, + 'frame'=> $frame, + 'url'=> $url, + 'top_data'=> $top_data, ]); } } diff --git a/models/AdminForm.php b/models/AdminForm.php index d3c4e09..65f1c14 100644 --- a/models/AdminForm.php +++ b/models/AdminForm.php @@ -16,8 +16,10 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm public $label; public $sort; public $size; + public $guest; public $url; public $url_reg; + public $top_data; protected $vars= [ 'label'=> [ @@ -34,12 +36,20 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm 'hints'=> 'Determines topbar menu position', ], 'size'=> [ + 'prefix'=> '', 'rules'=> ['in', 'range'=> [0, 1]], 'form'=> [ 'type'=> 'radio', 'items'=> [self::class, 'sizeModes'] ], ], + 'guest'=> [ + 'label'=> 'Visible for guests', + 'rules'=> ['in', 'range'=> [0, 1]], + 'form'=> [ + 'type'=> 'checkbox', + ], + ], 'url'=> [ 'label'=> 'Page URL', 'hints'=> 'The webpage to be shown. @UID@, @USER@ and @EMAIL@ will be replaced by the respective values.', @@ -48,6 +58,9 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm 'label'=> 'Page URL for registered users', 'hints'=> 'If empty, the above will be used.', ], + 'top_data'=> [ + 'label'=> 'HTML to add above the iframe', + ], ]; protected $mod= [ diff --git a/module.json b/module.json index 69f21f6..5c9cf8a 100644 --- a/module.json +++ b/module.json @@ -4,7 +4,7 @@ "description": "(Nearly) fullscreen iframes", "keywords": [ ], - "version": "0.2", + "version": "0.4.2", "humhub": { "minVersion": "1.2" }, diff --git a/views/index/index.php b/views/index/index.php index f5ef2e1..f2f67a0 100644 --- a/views/index/index.php +++ b/views/index/index.php @@ -4,36 +4,13 @@ themroc\humhub\modules\iframe\assets\Assets::register($this); -$frame= Yii::$app->request->get('frame'); -$mod= Yii::$app->getModule('iframe'); -$url= $mod->getSetting('url_reg', $frame); -if (empty($url) || Yii::$app->user->isGuest) - $url= $mod->getSetting('url', $frame); -if (Yii::$app->user->isGuest) { - $uid= 0; - $user= 'Guest-'.rand(10000000, 99999999); - $email= ''; -} else { - $uid= Yii::$app->user->id; - $user= Yii::$app->user->getIdentity()->__get('username'); - $email= Yii::$app->user->getIdentity()->__get('email'); -} -$ustr= $user.$email.$uid; -$color= ''; -for ($x=0; $x<6; $x++) { - $c= ord(substr($ustr, $x, 1)); - $color.= dechex($c & 0x0f); -} -$url= str_replace('@UID@', $uid, $url); -$url= str_replace('@USER@', urlencode($user), $url); -$url= str_replace('@EMAIL@', urlencode($email), $url); -$url= str_replace('@COLOR@', $color, $url); - $js= []; foreach ($mod->getFrames() as $f) $js[urlencode($f)]= $mod->getSetting('size', $f); $this->registerJsConfig(['iframe'=> $js]); echo '
'."\n"; +if (! empty($top_data)) + echo $top_data."\n"; echo ''."\n"; echo '
'."\n";