diff --git a/Module.php b/Module.php index e5b1f12..e4ef6a7 100644 --- a/Module.php +++ b/Module.php @@ -6,13 +6,13 @@ 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 humhub\modules\content\components\ContentContainerModule; use themroc\humhub\modules\iframe\Assets; -class Module extends \humhub\modules\content\components\ContentContainerModule +class Module extends ContentContainerModule { /** * @inheritdoc @@ -38,13 +38,14 @@ public function update () foreach ($this->getFrames() as $frame) { $url= $this->getSetting('url', $frame); $url_reg= $this->getSetting('url_reg', $frame); - if (empty($url_reg)) { + if (empty($url_reg)) $this->settings->set($frame.'/url_reg', $url); - } else { + else $this->settings->set($frame.'/url_guest', $url); - } $this->settings->delete($frame.'/url'); } + $this->settings->set('//tabs', $this->settings->get('/frames')); + $this->settings->delete('/frames'); $this->settings->set('//version', 1); } } @@ -66,9 +67,9 @@ public function getUrl ($page, $params=null) public function getFrames () { - $frames= $this->settings->get('/frames'); - if ($frames == null) - return []; + if ('' == $frames= $this->settings->get('//tabs')) + if ('' == $frames= $this->settings->get('/frames')) + return []; return preg_split('!\s*/\s*!', $frames); } diff --git a/controllers/AdminController.php b/controllers/AdminController.php index 3a32c6b..ee29678 100644 --- a/controllers/AdminController.php +++ b/controllers/AdminController.php @@ -4,25 +4,16 @@ use Yii; use humhub\modules\admin\components\Controller; +use themroc\humhub\modules\modhelper\behaviors\MhAdminController; use themroc\humhub\modules\iframe\models\AdminForm; +use themroc\humhub\modules\iframe\widgets\AdminTabs; class AdminController extends Controller { - const MH_MIN_REL= '0.2.1'; + const MH_MIN_REL= '0.2.2'; public $adminOnly= true; - public $subLayout= '@iframe/views/layouts/admin'; - - public function init () - { - 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(); - } - + public $isTabbed= true; /** * Render admin only page @@ -31,40 +22,15 @@ public function init () */ public function actionIndex () { - if ($this->subLayout===null) + if (null == $mh= Yii::$app->getModule('mod-helper') || version_compare($mh->getVersion(), self::MH_MIN_REL) < 0) return $this->render('error', [ 'msg'=> 'Please install and activate the' .' Mod-Helper plugin,' .' 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) { - $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')); - } + $this->attachBehavior('MhAdmin', new MhAdminController()); - return $this->render('@mod-helper/views/form', [ - 'model'=> $model, - 'standAlone'=> 0, - ]); + return $this->MHactionIndex(AdminForm::class, AdminTabs::class); } } diff --git a/models/AdminForm.php b/models/AdminForm.php index 8a17f83..8cc9e83 100644 --- a/models/AdminForm.php +++ b/models/AdminForm.php @@ -6,12 +6,15 @@ use yii\helpers\Url; use humhub\libs\Html; use humhub\modules\ui\form\widgets\IconPicker; +use themroc\humhub\modules\modhelper\models\MhAdminForm; /** * AdminForm defines the configurable fields. */ -class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm +class AdminForm extends MhAdminForm { + const MH_API= 1; + public $icon; public $label; public $sort; @@ -55,7 +58,6 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm ], ], 'url_guest'=> [ -# 'url'=> [ 'label'=> 'URL for guests', 'hints'=> 'If empty, the above will be used.', 'form'=> [ @@ -67,44 +69,6 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm ], ]; - 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 [ diff --git a/module.json b/module.json index 72e1910..d7a10af 100644 --- a/module.json +++ b/module.json @@ -1,12 +1,12 @@ { - "id": "iframe", - "name": "Iframe", - "description": "(Nearly) fullscreen iframes", - "keywords": [ - ], - "version": "0.4.3", - "humhub": { - "minVersion": "1.2" - }, - "screenshots": ["assets/screen1.jpg", "assets/screen2.jpg", "assets/screen3.jpg"] + "id": "iframe", + "name": "Iframe", + "description": "(Nearly) fullscreen iframes", + "keywords": [ + ], + "version": "0.4.4", + "humhub": { + "minVersion": "1.2" + }, + "screenshots": ["assets/screen1.jpg", "assets/screen2.jpg", "assets/screen3.jpg"] } diff --git a/widgets/AdminTabs.php b/widgets/AdminTabs.php index 8c08227..bd4e81a 100644 --- a/widgets/AdminTabs.php +++ b/widgets/AdminTabs.php @@ -4,11 +4,12 @@ use Yii; use yii\helpers\Url; +use humhub\widgets\BaseMenu; /** * Iframes Administration Menu */ -class AdminTabs extends \humhub\widgets\BaseMenu +class AdminTabs extends BaseMenu { /** * @inheritdoc