diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7683df --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +*.bak diff --git a/Events.php b/Events.php new file mode 100644 index 0000000..98c04e6 --- /dev/null +++ b/Events.php @@ -0,0 +1,64 @@ +getModule('iframe'); + + foreach ($mod->getFrames() as $f) { + $prefix= $f.'/'; + $label= $mod->getSetting('label', $f); + $event->sender->addItem([ + 'icon'=> '', + 'label'=> $label, + 'url'=> $mod->getUrl('index', ['frame'=> $label]), + 'sortOrder'=> $mod->getSetting('sort', $f), + 'isActive'=> self::checkActive('index', $f), + ]); + } + } + + /** + * Defines what to do if admin menu is initialized. + * + * @param $event + */ + public static function onAdminMenuInit($event) + { + $mod= Yii::$app->getModule('iframe'); + if (! Yii::$app->controller->module || ! Yii::$app->controller->module->id == 'iframe') + return; + + $event->sender->addItem([ + 'icon'=> '', + 'label'=> 'Iframe', + 'url'=> $mod->getUrl('admin'), + 'group'=> 'manage', + 'sortOrder'=> 99999, + 'isActive'=> self::checkActive('admin'), + ]); + } + + /** + * Defines what to do when the top menu is initialized. + * + * @param $event + */ + 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; + + return $frame==null ? 1 : (Yii::$app->request->get('frame') == $frame); + } +} diff --git a/Module.php b/Module.php new file mode 100644 index 0000000..e2c3889 --- /dev/null +++ b/Module.php @@ -0,0 +1,57 @@ +settings->get(($frame==null ? '' : $frame.'/') . $key); + } + + public function getUrl($page, $params=null) + { + $url= [ '/iframe/'.$page ]; + if (is_array($params)) + foreach ($params as $k => $v) + $url[$k]= strtolower($v); + + return Url::to($url); + } + + public function getFrames() + { + $frames= $this->settings->get('/frames'); + if ($frames == null) + return []; + + return preg_split('!\s*/\s*!', $frames); + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a892c3b --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +### Description +Add (nearly) fullscreen iframes to topbar. + +__Module website:__ + +__Author:__ Themroc <7hemroc@gmail.com> + +### Changelog + + + +### Bugtracker + + + +### ToDos + +- \ No newline at end of file diff --git a/assets/Assets.php b/assets/Assets.php new file mode 100644 index 0000000..7ac5e66 --- /dev/null +++ b/assets/Assets.php @@ -0,0 +1,31 @@ + \yii\web\View::POS_END + ]; + + /** + * @var array change forceCopy to true when testing your js in order to rebuild this assets on every request (otherwise they will be cached) + */ + public $publishOptions= [ + 'forceCopy'=> false + ]; + + public $js= [ + 'humhub.iframe.js' + ]; +} diff --git a/assets/module_image.png b/assets/module_image.png new file mode 100644 index 0000000..347ed9c Binary files /dev/null and b/assets/module_image.png differ diff --git a/assets/screen1.jpg b/assets/screen1.jpg new file mode 100644 index 0000000..61767e0 Binary files /dev/null and b/assets/screen1.jpg differ diff --git a/assets/screen2.jpg b/assets/screen2.jpg new file mode 100644 index 0000000..8cafd31 Binary files /dev/null and b/assets/screen2.jpg differ diff --git a/assets/screen3.jpg b/assets/screen3.jpg new file mode 100644 index 0000000..428649e Binary files /dev/null and b/assets/screen3.jpg differ diff --git a/config.php b/config.php new file mode 100644 index 0000000..95e1022 --- /dev/null +++ b/config.php @@ -0,0 +1,15 @@ + 'iframe', + 'class' => 'themroc\humhub\modules\iframe\Module', + 'namespace' => 'themroc\humhub\modules\iframe', + 'events' => [ + [ TopMenu::class, TopMenu::EVENT_INIT, [Events::class, 'onTopMenuInit'] ], + [ AdminMenu::class, AdminMenu::EVENT_INIT, [Events::class, 'onAdminMenuInit'] ], + ], +]; diff --git a/controllers/AdminController.php b/controllers/AdminController.php new file mode 100644 index 0000000..000b7f9 --- /dev/null +++ b/controllers/AdminController.php @@ -0,0 +1,62 @@ +getModule('mod-helper')===null) + $this->subLayout= null; + + return parent::init(); + } + + /** + * Render admin only page + * + * @return string + */ + public function actionIndex() + { + if ($this->subLayout===null) + return $this->render('error', [ + 'msg'=> 'Please install and activate the Mod-Helper plugin.', + ]); + + $mod= Yii::$app->getModule('iframe'); + $frame= Yii::$app->request->get('frame'); + + if (Yii::$app->request->get('delete') == 1) { + $model= new AdminForm(); + foreach (array_keys($model->getVars()) as $v) + $mod->settings->delete($frame.'/'.$v); + $frames= $mod->getFrames(); + if (false !== $k= array_search($frame, $frames)) { + unset($frames[$k]); + $mod->settings->set('/frames', join('/', $frames)); + } + + return $this->redirect($mod->getUrl('admin')); + } + + $model= new AdminForm(isset($frame) ? $frame.'/' : ''); + if ($model->load(Yii::$app->request->post()) && $model->save()) { + $this->view->saved(); + + return $this->redirect($mod->getUrl('admin')); + } + + return $this->render('@mod-helper/views/form', [ + 'model'=> $model, + 'standAlone'=> 0, + ]); + } +} diff --git a/controllers/IndexController.php b/controllers/IndexController.php new file mode 100644 index 0000000..2eaa90a --- /dev/null +++ b/controllers/IndexController.php @@ -0,0 +1,17 @@ +render('index', [ + ]); + } +} diff --git a/models/AdminForm.php b/models/AdminForm.php new file mode 100644 index 0000000..350b295 --- /dev/null +++ b/models/AdminForm.php @@ -0,0 +1,88 @@ + [ + 'hints'=> 'This will show up under the icon', + ], + 'icon'=> [ + 'form'=> [ + 'type'=> 'widget', + 'class'=> IconPicker::class, + ], + ], + 'sort'=> [ + 'label'=> 'Sort order', + 'hints'=> 'Determines topbar menu position', + ], + 'size'=> [ + 'rules'=> ['in', 'range'=> [0, 1]], + 'form'=> ['type'=> 'radio', 'params'=> [self::class, 'sizeModes']], + ], + 'url'=> [ + 'label'=> 'Page URL', + 'hints'=> 'The webpage to be shown', + ], + ]; + + protected $mod= [ + 'form'=> ['btn_post'=> [self::class, 'deleteButton']], + ]; + + /** + * @inheritdoc + */ + public function save() + { + $frame= strtolower($this->label); + $this->mod['prefix']= $frame.'/'; + $frames= $this->mod['_']->getFrames(); + $fs= []; + foreach ($frames as $f) + $fs[$f]= $this->mod['settings']->get($f.'/sort'); + $fs[$frame]= $this->sort; + asort($fs); + if (join('/', $frames) != ($frames_str= join('/', array_keys($fs)))) + $this->mod['settings']->set('/frames', $frames_str); + + foreach ($this->vars as $name => $v) + $this->mod['settings']->set($this->mod['prefix'].$name, trim($this->{$name})); + + return $this->loadSettings(); + } + + public function deleteButton($model) + { + return strlen($model->label) + ? "\t\t\t".Html::a( + Yii::t('IframeModule.base', 'Delete'), + $model->getMod('_')->getUrl('admin', ['frame'=> $model->label, 'delete'=> '1']), + ['class' => 'btn btn-default pull-right', 'style'=>'margin-right:10px'])."\n" + : ""; + } + + public function sizeModes() + { + return [ + 0=> Yii::t('IframeModule.base', 'Box'), + 1=> Yii::t('IframeModule.base', 'Fullscreen'), + ]; + } +} diff --git a/module.json b/module.json new file mode 100644 index 0000000..203fc79 --- /dev/null +++ b/module.json @@ -0,0 +1,12 @@ +{ + "id": "iframe", + "name": "Iframe", + "description": "(Nearly) fullscreen iframes", + "keywords": [ + ], + "version": "0.1", + "humhub": { + "minVersion": "1.2" + }, + "screenshots": ["assets/screen1.jpg", "assets/screen2.jpg", "assets/screen3.jpg"] +} diff --git a/resources/humhub.iframe.js b/resources/humhub.iframe.js new file mode 100644 index 0000000..6b2c563 --- /dev/null +++ b/resources/humhub.iframe.js @@ -0,0 +1,52 @@ +humhub.module('iframe', function(module, require, $) { + var init= function() { + $(window).on("resize", function (e) { humhub.modules.iframe.resize() }); + setTimeout(function (e) { humhub.modules.iframe.resize() }, 100); + tick(); + }; + + var frame= function () { + var fr= RegExp('frame=' + '(.+?)(&|$)').exec(window.location.href); + + return fr!=null ? fr[1] : ''; + } + + var tick= function () { + var fe= $(".iframe-frame"); + if (fe.length) { + var uframe= humhub.modules.iframe.frame(); + var hframe= jQuery.data(fe[0], "humhub.iframe.frame"); + if (uframe != hframe) { + jQuery.data(fe[0], "humhub.iframe.frame", uframe); + humhub.modules.iframe.resize(); + } + } + setTimeout(function (e) { humhub.modules.iframe.tick() }, 100); + } + + var resize= function () { + var fe= $(".iframe-frame"); + if (fe.length) { + var cfg= humhub.modules.iframe.config; + var frame= humhub.modules.iframe.frame(); + var height= $(window).height(); + var top= 0; + top+= 1 * $("#topbar-first").css("height").match(/[0-9]+/); + top+= 1 * $("#topbar-second").css("height").match(/[0-9]+/); + if (cfg[frame]!=1) { + top+= 25; + height-= 25; + } + height-= top; + $("body").css("padding-top", top + "px"); + fe.css("height", (height-5) + "px"); + } + } + + module.export({ + init: init, + frame: frame, + tick: tick, + resize: resize, + }); +}); diff --git a/views/admin/error.php b/views/admin/error.php new file mode 100644 index 0000000..6a70a5f --- /dev/null +++ b/views/admin/error.php @@ -0,0 +1,11 @@ +beginContent('@admin/views/layouts/main.php'); + +echo '
'. "\n"; +echo '
' . "\n"; +echo ' '. $msg . "\n"; +echo '
' . "\n"; +echo '
' . "\n"; + +$this->endContent(); diff --git a/views/index/index.php b/views/index/index.php new file mode 100644 index 0000000..510a49d --- /dev/null +++ b/views/index/index.php @@ -0,0 +1,18 @@ +request->get('frame'); +$mod= Yii::$app->getModule('iframe'); +$url= $mod->getSetting('url', $frame); + +$js= []; +foreach ($mod->getFrames() as $f) + $js[urlencode($f)]= $mod->getSetting('size', $f); +$this->registerJsConfig(['iframe'=> $js]); + +echo '
'."\n"; +echo ''."\n"; +echo '
'."\n"; diff --git a/views/layouts/admin.php b/views/layouts/admin.php new file mode 100644 index 0000000..c7bd387 --- /dev/null +++ b/views/layouts/admin.php @@ -0,0 +1,15 @@ +beginContent('@admin/views/layouts/main.php'); + +echo '
'."\n"; +echo '
'."\n"; +echo ' Iframe ' . Yii::t('IframeModule.base', 'module configuration') . "\n"; +echo '
'."\n"; +echo \themroc\humhub\modules\iframe\widgets\AdminTabs::widget(); +echo '
'."\n"; +echo ' ' . $content . "\n"; +echo '
'."\n"; +echo '
'."\n"; + +$this->endContent(); diff --git a/views/layouts/default.php b/views/layouts/default.php new file mode 100644 index 0000000..ba585c5 --- /dev/null +++ b/views/layouts/default.php @@ -0,0 +1,19 @@ +request->get('frame'); +$size= Yii::$app->getModule('iframe')->getSetting('size', $frame); + +if ($size==1) + echo $content; +else + echo << +
+
+
+ $content +
+
+
+ +EOF; diff --git a/widgets/AdminTabs.php b/widgets/AdminTabs.php new file mode 100644 index 0000000..0c77fee --- /dev/null +++ b/widgets/AdminTabs.php @@ -0,0 +1,40 @@ +controller; + $frame= Yii::$app->request->get('frame'); + $mod= Yii::$app->getModule('iframe'); + foreach ($mod->getFrames() as $f) + $this->addItem([ + 'label'=> $mod->getSetting('label', $f), + 'url'=> Url::to(['/iframe/admin', 'frame'=>$f]), + 'sortOrder'=> $mod->getSetting('/sort'. $f), + 'isActive'=> $f == $frame, + ]); + + $this->addItem([ + 'label'=> '  +  ', + 'url'=> Url::to(['/iframe/admin']), + 'sortOrder'=> 9999999, + 'isActive'=> $frame == null, + ]); + + parent::init(); + } +}