Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Themroc committed Sep 22, 2019
0 parents commit b1f4f7e
Show file tree
Hide file tree
Showing 20 changed files with 521 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
*.bak
64 changes: 64 additions & 0 deletions Events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace themroc\humhub\modules\iframe;

use Yii;

class Events
{
/**
* Defines what to do when the top menu is initialized.
*
* @param $event
*/
public static function onTopMenuInit($event)
{
$mod= Yii::$app->getModule('iframe');

foreach ($mod->getFrames() as $f) {
$prefix= $f.'/';
$label= $mod->getSetting('label', $f);
$event->sender->addItem([
'icon'=> '<i class="fa '.$mod->getSetting($prefix.'icon').'"></i>',
'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'=> '<i class="fa fa-desktop"></i>',
'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);
}
}
57 changes: 57 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace themroc\humhub\modules\iframe;

use Yii;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use humhub\components\UrlManager;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;

use themroc\humhub\modules\iframe\Assets;

class Module extends \humhub\modules\content\components\ContentContainerModule
{
/**
* @inheritdoc
*/
public function getConfigUrl()
{
return Url::to(['/iframe/admin']);
}

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

public function getSetting($key, $frame=null)
{
return $this->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);
}
}
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Description
Add (nearly) fullscreen iframes to topbar.

__Module website:__ <https://github.com/Themroc/humhub_iframe>

__Author:__ Themroc <7hemroc@gmail.com>

### Changelog

<https://github.com/Themroc/humhub_iframe/commits/master>

### Bugtracker

<https://github.com/Themroc/humhub_iframe/issues>

### ToDos

-
31 changes: 31 additions & 0 deletions assets/Assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace themroc\humhub\modules\iframe\assets;

use yii\web\AssetBundle;

class Assets extends AssetBundle
{
/**
* @var string defines the path of your module assets
*/
public $sourcePath= '@iframe/resources';

/**
* @var array defines where the js files are included into the page, note your custom js files should be included after the core files (which are included in head)
*/
public $jsOptions= [
'position'=> \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'
];
}
Binary file added assets/module_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screen1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screen2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screen3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use humhub\widgets\TopMenu;
use humhub\modules\admin\widgets\AdminMenu;
use themroc\humhub\modules\iframe\Events;

return [
'id' => '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'] ],
],
];
62 changes: 62 additions & 0 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace themroc\humhub\modules\iframe\controllers;

use Yii;
use humhub\modules\admin\components\Controller;
use themroc\humhub\modules\iframe\models\AdminForm;

class AdminController extends Controller
{
public $adminOnly= true;
public $subLayout= '@iframe/views/layouts/admin';

public function init()
{
if (Yii::$app->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 <a href="https://github.com/Themroc/humhub_mod-helper" target="_blank">Mod-Helper plugin</a>.',
]);

$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,
]);
}
}
17 changes: 17 additions & 0 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace themroc\humhub\modules\iframe\controllers;

use Yii;
use humhub\components\Controller;

class IndexController extends Controller
{
public $subLayout = "@iframe/views/layouts/default";

public function actionIndex()
{
return $this->render('index', [
]);
}
}
88 changes: 88 additions & 0 deletions models/AdminForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace themroc\humhub\modules\iframe\models;

use Yii;
use yii\helpers\Url;
use humhub\libs\Html;
use humhub\modules\ui\form\widgets\IconPicker;

/**
* AdminForm defines the configurable fields.
*/
class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm
{
public $icon;
public $label;
public $sort;
public $size;
public $url;

protected $vars= [
'label'=> [
'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'),
];
}
}
12 changes: 12 additions & 0 deletions module.json
Original file line number Diff line number Diff line change
@@ -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"]
}
Loading

0 comments on commit b1f4f7e

Please sign in to comment.