Skip to content

Commit

Permalink
New mod-helper API
Browse files Browse the repository at this point in the history
  • Loading branch information
Themroc committed Feb 16, 2022
1 parent 8a125e2 commit 68513a5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 100 deletions.
17 changes: 9 additions & 8 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Expand All @@ -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);
}
Expand Down
48 changes: 7 additions & 41 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
.' <a href="https://github.com/Themroc/humhub_mod-helper" target="_blank">Mod-Helper plugin</a>,'
.' 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);
}
}
44 changes: 4 additions & 40 deletions models/AdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'=> [
Expand All @@ -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 [
Expand Down
20 changes: 10 additions & 10 deletions module.json
Original file line number Diff line number Diff line change
@@ -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"]
}
3 changes: 2 additions & 1 deletion widgets/AdminTabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68513a5

Please sign in to comment.