-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from GreenMeteor/develop
Enh: Support adding multiple codeboxes
- Loading branch information
Showing
21 changed files
with
532 additions
and
288 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,55 @@ | ||
<?php | ||
|
||
namespace humhub\modules\codebox; | ||
|
||
use Yii; | ||
use yii\helpers\Url; | ||
use yii\base\BaseObject; | ||
use humhub\modules\ui\menu\MenuLink; | ||
use humhub\modules\ui\icon\widgets\Icon; | ||
use humhub\modules\admin\widgets\AdminMenu; | ||
use humhub\modules\admin\permissions\ManageModules; | ||
|
||
class Events extends BaseObject | ||
{ | ||
|
||
public static function onAdminMenuInit($event) | ||
{ | ||
if (!Yii::$app->user->can(ManageModules::class)) { | ||
return; | ||
} | ||
|
||
/** @var AdminMenu $menu */ | ||
$menu = $event->sender; | ||
|
||
$menu->addEntry(new MenuLink([ | ||
'label' => Yii::t('CodeboxModule.base', 'Codebox Settings'), | ||
'url' => Url::toRoute('/codebox/admin/index'), | ||
'icon' => Icon::get('code'), | ||
'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'codebox' && Yii::$app->controller->id == 'admin', | ||
'sortOrder' => 600, | ||
'isVisible' => true, | ||
])); | ||
} | ||
|
||
public static function addCodeboxFrame($event) | ||
{ | ||
$module = Yii::$app->getModule('codebox'); | ||
$settings = $module->settings; | ||
|
||
if (Yii::$app->user->isGuest) { | ||
return; | ||
} else { | ||
Yii::$app->user; | ||
} | ||
|
||
$event->sender->addWidget(widgets\CodeboxFrame::class, [], ['sortOrder' => $settings->get('sortOrder')]); | ||
} | ||
} | ||
<?php | ||
|
||
namespace humhub\modules\codebox; | ||
|
||
use Yii; | ||
use yii\helpers\Url; | ||
use yii\base\BaseObject; | ||
use humhub\modules\ui\menu\MenuLink; | ||
use humhub\modules\ui\icon\widgets\Icon; | ||
use humhub\modules\admin\widgets\AdminMenu; | ||
use humhub\modules\admin\permissions\ManageModules; | ||
use humhub\modules\codebox\models\ConfigureForm; | ||
|
||
class Events extends BaseObject | ||
{ | ||
|
||
public static function onAdminMenuInit($event) | ||
{ | ||
if (!Yii::$app->user->can(ManageModules::class)) { | ||
return; | ||
} | ||
|
||
/** @var AdminMenu $menu */ | ||
$menu = $event->sender; | ||
|
||
$menu->addEntry(new MenuLink([ | ||
'label' => Yii::t('CodeboxModule.base', 'Codebox Settings'), | ||
'url' => Url::toRoute('/codebox/admin/index'), | ||
'icon' => Icon::get('code'), | ||
'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'codebox' && Yii::$app->controller->id == 'admin', | ||
'sortOrder' => 600, | ||
'isVisible' => true, | ||
])); | ||
} | ||
|
||
public static function addCodeboxFrame($event) | ||
{ | ||
// Retrieve the Codebox module | ||
$module = Yii::$app->getModule('codebox'); | ||
|
||
// Check if the module is enabled | ||
if ($module !== null && $module->isEnabled) { | ||
// Retrieve the settings from the database | ||
$entries = ConfigureForm::find()->asArray()->all(); | ||
|
||
// Add the CodeboxFrame widget with the entries | ||
$event->sender->addWidget( | ||
\humhub\modules\codebox\widgets\CodeboxFrame::class, | ||
['entries' => $entries], | ||
['sortOrder' => $module->getOrder()] | ||
); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,84 @@ | ||
<?php | ||
|
||
namespace humhub\modules\codebox; | ||
|
||
use Yii; | ||
use yii\helpers\Url; | ||
use humhub\libs\Html; | ||
use humhub\components\Module as BaseModule; | ||
|
||
class Module extends BaseModule | ||
{ | ||
|
||
public $resourcesPath = 'resources'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getConfigUrl() | ||
{ | ||
return Url::to(['/codebox/admin']); | ||
} | ||
|
||
public function getTitle() | ||
{ | ||
$title = $this->settings->get('title'); | ||
if (empty($title)) { | ||
return ''; | ||
} | ||
return $title; | ||
} | ||
|
||
public function getHtmlCode() | ||
{ | ||
$htmlCode = $this->settings->get('htmlCode'); | ||
|
||
if (empty($htmlCode)) { | ||
return ''; | ||
} | ||
|
||
return $htmlCode; | ||
} | ||
|
||
|
||
public function getOrder() | ||
{ | ||
$sortOrder = $this->settings->get('sortOrder'); | ||
if (empty($sortOrder)) { | ||
return '100'; | ||
} | ||
return $sortOrder; | ||
} | ||
} | ||
<?php | ||
|
||
namespace humhub\modules\codebox; | ||
|
||
use Yii; | ||
use yii\helpers\Url; | ||
use humhub\components\Module as BaseModule; | ||
use humhub\modules\codebox\models\ConfigureForm; | ||
|
||
class Module extends BaseModule | ||
{ | ||
public $resourcesPath = 'resources'; | ||
|
||
/** | ||
* Returns the URL to the configuration page. | ||
* | ||
* @return string the URL to the configuration page | ||
*/ | ||
public function getConfigUrl() | ||
{ | ||
return Url::to(['/codebox/admin']); | ||
} | ||
|
||
/** | ||
* Retrieves all settings from the database. | ||
* | ||
* @return array the settings | ||
*/ | ||
protected function getSettings() | ||
{ | ||
$models = ConfigureForm::find()->all(); | ||
$settings = []; | ||
|
||
foreach ($models as $model) { | ||
$settings[$model->getAttribute('name')] = $model->getAttribute('value'); | ||
} | ||
|
||
return $settings; | ||
} | ||
|
||
/** | ||
* Retrieves a setting from the database. | ||
* | ||
* @param string $name the name of the setting attribute | ||
* @param mixed $defaultValue the default value if the setting is not found | ||
* @return mixed the value of the setting | ||
*/ | ||
protected function getSetting($name, $defaultValue = null) | ||
{ | ||
$settings = $this->getSettings(); | ||
|
||
return isset($settings[$name]) ? $settings[$name] : $defaultValue; | ||
} | ||
|
||
/** | ||
* Retrieves the title from the module settings. | ||
* | ||
* @return string the title | ||
*/ | ||
public function getTitle() | ||
{ | ||
return $this->getSetting('title'); | ||
} | ||
|
||
/** | ||
* Retrieves the HTML code snippet from the module settings. | ||
* | ||
* @return string the HTML code snippet | ||
*/ | ||
public function getHtmlCode() | ||
{ | ||
return $this->getSetting('htmlCode'); | ||
} | ||
|
||
/** | ||
* Retrieves the sort order from the module settings. | ||
* | ||
* @return int the sort order | ||
*/ | ||
public function getOrder() | ||
{ | ||
return $this->getSetting('sortOrder', 100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,67 @@ | ||
<?php | ||
|
||
namespace humhub\modules\codebox\controllers; | ||
|
||
use Yii; | ||
use humhub\modules\admin\components\Controller; | ||
use humhub\modules\codebox\models\ConfigureForm; | ||
|
||
class AdminController extends Controller | ||
{ | ||
|
||
public function actionIndex() | ||
{ | ||
$model = new ConfigureForm(); | ||
$model->loadSettings(); | ||
|
||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
$this->view->saved(); | ||
} | ||
|
||
return $this->render('index', ['model' => $model]); | ||
} | ||
|
||
} | ||
<?php | ||
|
||
namespace humhub\modules\codebox\controllers; | ||
|
||
use Yii; | ||
use yii\web\NotFoundHttpException; | ||
use humhub\modules\admin\components\Controller; | ||
use humhub\modules\codebox\models\ConfigureForm; | ||
|
||
class AdminController extends Controller | ||
{ | ||
|
||
public function actionIndex() | ||
{ | ||
$models = ConfigureForm::find()->all(); | ||
|
||
return $this->render('index', ['models' => $models]); | ||
} | ||
|
||
public function actionCreate() | ||
{ | ||
$model = new ConfigureForm(); | ||
|
||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
return $this->redirect(['index']); | ||
} | ||
|
||
return $this->renderAjax('create', ['model' => $model]); | ||
} | ||
|
||
/** | ||
* Updates an existing ticket. | ||
* | ||
* @param int $id | ||
* @return string|\yii\web\Response | ||
* @throws NotFoundHttpException | ||
*/ | ||
public function actionUpdate($id) | ||
{ | ||
$model = $this->findModel($id); | ||
|
||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
return $this->redirect(['index']); | ||
} | ||
|
||
return $this->renderAjax('update', [ | ||
'model' => $model, | ||
]); | ||
} | ||
|
||
public function actionDelete($id) | ||
{ | ||
$model = $this->findModel($id); | ||
$model->delete(); | ||
|
||
return $this->redirect(['index']); | ||
} | ||
|
||
protected function findModel($id) | ||
{ | ||
if (($model = ConfigureForm::findOne($id)) !== null) { | ||
return $model; | ||
} | ||
|
||
throw new NotFoundHttpException(Yii::t('CodeboxModule.base', 'The requested entry does not exist.')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## [HumHub](https://www.humhub.org/en) Codebox Module | ||
Allows you to use HTML snippets to your sidebar. | ||
Allows you to add and use HTML snippets on your Dashboard sidebar. | ||
|
||
### __Product Distributors:__ | ||
[@GreenMeteor](https://github.com/GreenMeteor) | ||
|
||
> If you enjoy our work please consider [donating](https://donate.stripe.com/00g7uJ4gb7UZePu8wM). |
Oops, something went wrong.