Skip to content

Commit

Permalink
Add guest visibility and top html, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Themroc committed Feb 7, 2022
1 parent 2183ea0 commit 5d0e008
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
10 changes: 7 additions & 3 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'=> '<i class="fa fa-'.$mod->getSetting($prefix.'icon').'"></i>',
'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),
Expand All @@ -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')
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:__ <https://github.com/Themroc/humhub_iframe>
Expand Down
32 changes: 32 additions & 0 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
13 changes: 13 additions & 0 deletions models/AdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'=> [
Expand All @@ -34,12 +36,20 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm
'hints'=> 'Determines topbar menu position',
],
'size'=> [
'prefix'=> '<style>.regular-radio-container{display:inline !important}</style>',
'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.',
Expand All @@ -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= [
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "(Nearly) fullscreen iframes",
"keywords": [
],
"version": "0.2",
"version": "0.4.2",
"humhub": {
"minVersion": "1.2"
},
Expand Down
27 changes: 2 additions & 25 deletions views/index/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="panel-body" style="padding:0px; margin:0px; border:0px">'."\n";
if (! empty($top_data))
echo $top_data."\n";
echo '<iframe src="'.$url.'" class="iframe-frame" width="100%" height="500" allowtransparency="true" frameborder="0" style="padding:0px; margin:0px; border:0px"></iframe>'."\n";
echo '</div>'."\n";

0 comments on commit 5d0e008

Please sign in to comment.