Merge remote-tracking branch 'remotes/origin/develop-menu' into develop

# Conflicts:
#	composer.json
#	protected/humhub/components/Widget.php
#	protected/humhub/docs/CHANGELOG_DEV.md
#	protected/humhub/modules/admin/widgets/AdminMenu.php
#	protected/humhub/modules/admin/widgets/AuthenticationMenu.php
#	protected/humhub/modules/user/widgets/AccountProfilMenu.php
#	protected/humhub/modules/user/widgets/ProfileMenu.php
#	static/less/humhub.less
#	themes/HumHub/css/theme.css
This commit is contained in:
buddh4 2019-08-22 15:22:48 +02:00
commit 3815e262e8
67 changed files with 3351 additions and 1815 deletions

View File

@ -5,8 +5,6 @@ HumHub Change Log (DEVELOP)
1.4
---
Warning: The minimum required PHP version is now 7.1
- Enh: GroupPermissionManager - allow to query users by given permission
- Enh: Automatic migrate DB collations from utf8 to utf8mb4
- Enh: Added Icon widget as wrapper class
@ -41,3 +39,8 @@ Warning: The minimum required PHP version is now 7.1
- Enh: Added integrated page icon handling
- Enh: Updated to Yii 2.0.16
- Enh: Raised minimum PHP Version to 7.1
- Chng: New Menu and MenuEntry rendering
- Enh: Added Icon abstraction `humhub\modules\ui\icon\widgets\Icon`
- Enh: Added `humhub\libs\Html::addPjaxPrevention()` for link options
- Enh: Added obj support for `humhub\libs\Sort`
- Enh: Reorganized WallEntry context menu

View File

@ -31,6 +31,7 @@ Basic Concepts
* [Activities](activities.md)
* [File Handling](files.md)
* [Widgets](widgets.md)
* [Menus and Navigations](menus.md)
* [Snippets](snippet.md)
* [Internationalization](i18n.md)

View File

@ -0,0 +1,109 @@
Menus and Navigations
=====================
All menus and navigation widgets are derived from the widget class [[humhub\modules\ui\menu\widgets\Menu]].
Additionally, there are following sub base classes with predefined templates available:
- [[humhub\modules\ui\menu\widgets\LeftNavigation]]
- [[humhub\modules\ui\menu\widgets\TabMenu]]
- [[humhub\modules\ui\menu\widgets\SubTabMenu]]
- [[humhub\modules\ui\menu\widgets\DropDownMenu]]
Based on these base classes, following menu implementations are most frequently used:
- TopMenu (Main navigation with entries like Dashboard/Directory) - [[humhub\widgets\TopMenu]]
- FooterMenu - [[humhub\widgets\FooterMenu]]
- AdminMenu - Administrative Section - [[humhub\modules\admin\widgets\AdminMenu]]
- AccountMenu - [[humhub\modules\user\widgets\AccountTopMenu]]
Menu entries are represented by the class [[humhub\modules\ui\menu\MenuEntry]].
Instances of this class can be added via the menu class.
See the [[humhub\modules\ui\menu\MenuEntry]] class for a full list of properties and options.
Events
------
The menu allow you to manipulate menu entries at certain execution points using events.
You can use all Yii2 widget events to interact with the menu class.
Example of the modules **config.php**:
```php
return [
'id' => 'example',
'class' => Module::class,
'events' => [
['class' => TopMenu::class, 'event' => TopMenu::EVENT_INIT, 'callback' => ['\humhub\modules\example\Events', 'onTopMenuInit']],
]
];
```
Example of a callback:
```php
namespace humhub\modules\example;
use humhub\modules\dashboard\widgets\ShareWidget;
use humhub\modules\ui\widgets\Icon;
use humhub\modules\ui\menu\MenuEntry;
use humhub\widgets\TopMenu;
use Yii;
use yii\base\Event;
use yii\helpers\Url;
/**
* Description of Events
*
* @author luke
*/
class Events
{
/**
* TopMenu init event callback
*
* @see TopMenu
* @param Event $event
*/
public static function onTopMenuInit($event)
{
/** @var TopMenu $topMenu */
$topMenu = $event->sender;
$entry = new MenuEntry();
$entry->setId('dashboard');
$entry->setLabel(Yii::t('DashboardModule.base', 'Dashboard'));
$entry->setUrl(['/dashboard/dashboard']);
$entry->setIcon(new Icon(['name' => 'tachometer']));
$entry->setSortOrder(100);
$entry->setIsActive((Yii::$app->controller->module && Yii::$app->controller->module->id === 'dashboard'));
$topMenu->addEntry($entry);
}
}
```
ToDos
-----
- Add UnitTesting
- Allow submenus
- Separator Entry support
- Location for Footer/TopMenu sources? Move into UI module?
- PanelMenu Cleanup

View File

@ -109,4 +109,9 @@ class Html extends \yii\bootstrap\Html
throw new InvalidArgumentException('Content container type not supported!');
}
}
public static function addPjaxPrevention(&$options)
{
$options['data-pjax-prevent'] = 1;
}
}

View File

@ -13,8 +13,8 @@ class Sort
public static function sort(&$arr, $field = 'sortOrder')
{
usort($arr, function($a, $b) use ($field) {
$sortA = (isset($a[$field])) ? $a[$field] : PHP_INT_MAX;
$sortB = (isset($b[$field])) ? $b[$field] : PHP_INT_MAX;
$sortA = static::getSortValue($a, $field);
$sortB = static::getSortValue($b, $field);
if ($sortA == $sortB) {
return 0;
@ -27,4 +27,18 @@ class Sort
return $arr;
}
private static function getSortValue($obj, $field)
{
if(is_array($obj) && isset($obj[$field])) {
return $obj[$field];
}
if(property_exists($obj, $field)) {
return $obj->$field;
}
return PHP_INT_MAX;
}
}

View File

@ -8,8 +8,11 @@
namespace humhub\modules\admin\controllers;
use humhub\modules\ui\menu\MenuLink;
use Yii;
use humhub\modules\admin\components\Controller;
use humhub\modules\admin\widgets\AdminMenu;
use yii\web\HttpException;
/**
* IndexController is the admin section start point.
@ -39,9 +42,16 @@ class IndexController extends Controller
*/
public function actionIndex()
{
$adminMenu = new \humhub\modules\admin\widgets\AdminMenu();
$adminMenu = new AdminMenu();
return $this->redirect($adminMenu->items[0]['url']);
/* @var $firstVisible MenuLink */
$firstVisible = $adminMenu->getFirstEntry(MenuLink::class, true);
if(!$firstVisible) {
throw new HttpException(403);
}
return $this->redirect($firstVisible->getUrl());
}
}

View File

@ -9,86 +9,91 @@
namespace humhub\modules\admin\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\admin\permissions\ManageModules;
use humhub\modules\admin\permissions\ManageSpaces;
use humhub\modules\admin\permissions\SeeAdminInformation;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\LeftNavigation;
use humhub\modules\admin\permissions\ManageUsers;
use humhub\modules\admin\permissions\ManageSettings;
use humhub\modules\admin\permissions\ManageGroups;
/**
* Description of AdminMenu
* AdminMenu
*
* @author luke
*/
class AdminMenu extends \humhub\widgets\BaseMenu
class AdminMenu extends LeftNavigation
{
/**
* @inheritdoc
*/
const SESSION_CAN_SEE_ADMIN_SECTION = 'user.canSeeAdminSection';
public $template = "@humhub/widgets/views/leftNavigation";
public $type = "adminNavigation";
public $id = "admin-menu";
/**
* @inheritdoc
*/
public function init()
{
$this->addItemGroup([
'id' => 'admin',
'label' => \Yii::t('AdminModule.widgets_AdminMenuWidget', '<strong>Administration</strong> menu'),
'sortOrder' => 100,
]);
$this->panelTitle = Yii::t('AdminModule.widgets_AdminMenuWidget', '<strong>Administration</strong> menu');
$this->addItem([
'label' => \Yii::t('AdminModule.widgets_AdminMenuWidget', 'Users'),
'url' => Url::toRoute(['/admin/user']),
'icon' => '<i class="fa fa-user"></i>',
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Users'),
'url' => ['/admin/user'],
'icon' => 'user',
'sortOrder' => 200,
'isActive' => (\Yii::$app->controller->module && \Yii::$app->controller->module->id == 'admin' && (Yii::$app->controller->id == 'user' || Yii::$app->controller->id == 'group' || Yii::$app->controller->id == 'approval' || Yii::$app->controller->id == 'authentication' || Yii::$app->controller->id == 'user-profile' || Yii::$app->controller->id == 'pending-registrations')),
'isActive' => MenuLink::isActiveState('admin', ['user', 'group', 'approval', 'authentication', 'user-profile', 'pending-registrations']),
'isVisible' => Yii::$app->user->can([
new \humhub\modules\admin\permissions\ManageUsers(),
new \humhub\modules\admin\permissions\ManageSettings(),
new \humhub\modules\admin\permissions\ManageGroups()
]),
]);
ManageUsers::class,
ManageSettings::class,
ManageGroups::class
])
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Spaces'),
'id' => 'spaces',
'url' => Url::toRoute('/admin/space'),
'icon' => '<i class="fa fa-inbox"></i>',
'url' => ['/admin/space'],
'icon' => 'inbox',
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'space'),
'isActive' => MenuLink::isActiveState('admin', 'space'),
'isVisible' => Yii::$app->user->can([
new \humhub\modules\admin\permissions\ManageSpaces(),
new \humhub\modules\admin\permissions\ManageSettings(),
]),
]);
ManageSpaces::class,
ManageSettings::class
])
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Modules'),
'id' => 'modules',
'url' => Url::toRoute('/admin/module'),
'icon' => '<i class="fa fa-rocket"></i>',
'url' => ['/admin/module'],
'icon' => 'rocket',
'sortOrder' => 500,
'newItemCount' => 0,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'module'),
'isVisible' => Yii::$app->user->can(new \humhub\modules\admin\permissions\ManageModules())
]);
'htmlOptions' => ['class' => 'modules'],
'isActive' => MenuLink::isActiveState('admin', 'module'),
'isVisible' => Yii::$app->user->can(ManageModules::class)
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Settings'),
'url' => Url::toRoute('/admin/setting'),
'icon' => '<i class="fa fa-gears"></i>',
'url' => ['/admin/setting'],
'icon' => 'gears',
'sortOrder' => 600,
'newItemCount' => 0,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'setting'),
'isVisible' => Yii::$app->user->can(new \humhub\modules\admin\permissions\ManageSettings())
]);
'isActive' => MenuLink::isActiveState('admin', 'setting'),
'isVisible' => Yii::$app->user->can(ManageSettings::class)
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Information'),
'url' => Url::toRoute('/admin/information'),
'icon' => '<i class="fa fa-info-circle"></i>',
'sortOrder' => 10000,
'newItemCount' => 0,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'information'),
'isVisible' => Yii::$app->user->can(new \humhub\modules\admin\permissions\SeeAdminInformation())
]);
'url' => ['/admin/information'],
'icon' => 'info-circle',
'sortOrder' => 1000,
'isActive' => MenuLink::isActiveState('admin', 'information'),
'isVisible' => Yii::$app->user->can(SeeAdminInformation::class)
]));
parent::init();
}
@ -96,25 +101,15 @@ class AdminMenu extends \humhub\widgets\BaseMenu
/**
* @inheritdoc
*/
public function run()
public function addItem($entryArray)
{
// Workaround for modules with no admin menu permission support.
if (!Yii::$app->user->isAdmin()) {
foreach ($this->items as $key => $item) {
if (!isset($item['isVisible'])) {
unset($this->items[$key]);
}
}
$entry = MenuLink::createByArray($entryArray);
if(!isset($entryArray['isVisible'])) {
$entry->setIsVisible(Yii::$app->user->isAdmin());
}
return parent::run();
}
public function addItem($item)
{
$item['group'] = 'admin';
parent::addItem($item);
$this->addEntry($entry);
}
public static function canAccess()
@ -135,14 +130,7 @@ class AdminMenu extends \humhub\widgets\BaseMenu
private static function checkNonAdminAccess()
{
$adminMenu = new self();
foreach($adminMenu->items as $item) {
if(isset($item['isVisible']) && $item['isVisible']) {
return true;
}
}
return false;
return Yii::$app->user->can([ManageGroups::class, ManageModules::class, ManageSettings::class, ManageUsers::class, SeeAdminInformation::class]);
}
}

View File

@ -8,85 +8,84 @@
namespace humhub\modules\admin\widgets;
use humhub\modules\ui\menu\MenuLink;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\widgets\SubTabMenu;
/**
* Authentication Settings Menu
*/
class AdvancedSettingMenu extends \humhub\widgets\BaseMenu
class AdvancedSettingMenu extends SubTabMenu
{
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/subTabMenu";
/**
* @inheritdoc
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Caching'),
'url' => Url::toRoute(['/admin/setting/caching']),
'icon' => '<i class="fa fa-dashboard"></i>',
'icon' => 'dashboard',
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'caching'),
'isActive' => MenuLink::isActiveState('admin', 'setting', 'caching'),
'isVisible' => Yii::$app->user->isAdmin(),
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Files'),
'url' => Url::toRoute('/admin/setting/file'),
'icon' => '<i class="fa fa-file"></i>',
'icon' => 'file',
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'file'),
'isActive' => MenuLink::isActiveState('admin', 'setting', 'file'),
'isVisible' => Yii::$app->user->isAdmin(),
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.views_setting_mailing', 'E-Mail'),
'url' => Url::toRoute(['/admin/setting/mailing-server']),
'icon' => '<i class="fa fa-envelope"></i>',
'icon' => 'envelope',
'sortOrder' => 250,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'mailing-server'),
]);
'isActive' => MenuLink::isActiveState('admin', 'setting', 'mailing-server'),
'isVisible' => Yii::$app->user->isAdmin(),
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Proxy'),
'url' => Url::toRoute('/admin/setting/proxy'),
'icon' => '<i class="fa fa-sitemap"></i>',
'icon' => 'sitemap',
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'proxy'),
'isActive' => MenuLink::isActiveState('admin', 'setting', 'proxy'),
'isVisible' => Yii::$app->user->isAdmin(),
]);
$this->addItem([
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Statistics'),
'url' => Url::toRoute('/admin/setting/statistic'),
'icon' => '<i class="fa fa-bar-chart-o"></i>',
'icon' => 'bar-chart-o',
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'statistic'),
'isActive' => MenuLink::isActiveState('admin', 'setting', 'statistic'),
'isVisible' => Yii::$app->user->isAdmin(),
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'OEmbed'),
'url' => Url::toRoute('/admin/setting/oembed'),
'icon' => '<i class="fa fa-cloud"></i>',
'icon' => 'cloud',
'sortOrder' => 500,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && (Yii::$app->controller->action->id == 'oembed' || Yii::$app->controller->action->id == 'oembed-edit')),
'isActive' => MenuLink::isActiveState('admin', 'setting', 'oembed-edit'),
'isVisible' => Yii::$app->user->isAdmin(),
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Logs'),
'url' => Url::toRoute('/admin/setting/logs'),
'icon' => '<i class="fa fa-terminal"></i>',
'icon' => 'terminal',
'sortOrder' => 600,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && (Yii::$app->controller->action->id == 'logs' || Yii::$app->controller->action->id == 'logs-edit')),
'isActive' => MenuLink::isActiveState('admin', 'setting', ['logs', 'logs-edit']),
'isVisible' => Yii::$app->user->isAdmin(),
]);
]));
parent::init();
}

View File

@ -8,31 +8,28 @@
namespace humhub\modules\admin\widgets;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\SubTabMenu;
use Yii;
use yii\helpers\Url;
/**
* Authentication Settings Menu
*/
class AuthenticationMenu extends \humhub\widgets\BaseMenu
class AuthenticationMenu extends SubTabMenu
{
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/subTabMenu";
/**
* @inheritdoc
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.setting', 'General'),
'url' => Url::toRoute(['/admin/authentication']),
'url' => ['/admin/authentication'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'authentication' && Yii::$app->controller->action->id == 'index'),
]);
'isActive' => MenuLink::isActiveState('admin', 'authentication', 'index'),
]));
parent::init();
}

View File

@ -9,19 +9,15 @@
namespace humhub\modules\admin\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\SubTabMenu;
/**
* Group Administration Menu
*/
class GroupManagerMenu extends \humhub\widgets\BaseMenu
class GroupManagerMenu extends SubTabMenu
{
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/subTabMenu";
/**
* @var \humhub\modules\user\models\Group
*/
@ -32,24 +28,27 @@ class GroupManagerMenu extends \humhub\widgets\BaseMenu
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.user', 'Settings'),
'url' => Url::toRoute(['/admin/group/edit', 'id' => $this->group->id]),
'url' => ['/admin/group/edit', 'id' => $this->group->id],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group' && Yii::$app->controller->action->id == 'edit'),
]);
$this->addItem([
'isActive' => MenuLink::isActiveState('admin', 'group', 'edit')
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.user', "Permissions"),
'url' => Url::toRoute(['/admin/group/manage-permissions', 'id' => $this->group->id]),
'url' => ['/admin/group/manage-permissions', 'id' => $this->group->id],
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group' && Yii::$app->controller->action->id == 'manage-permissions'),
]);
$this->addItem([
'isActive' => MenuLink::isActiveState('admin', 'group', 'manage-permissions')
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.user', "Members"),
'url' => Url::toRoute(['/admin/group/manage-group-users', 'id' => $this->group->id]),
'url' => ['/admin/group/manage-group-users', 'id' => $this->group->id],
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group' && Yii::$app->controller->action->id == 'manage-group-users'),
]);
'isActive' => MenuLink::isActiveState('admin', 'group', 'manage-group-users')
]));
parent::init();
}

View File

@ -8,38 +8,28 @@
namespace humhub\modules\admin\widgets;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\SubTabMenu;
use Yii;
use yii\helpers\Url;
/**
* Group Administration Menu
*/
class GroupMenu extends \humhub\widgets\BaseMenu
class GroupMenu extends SubTabMenu
{
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/subTabMenu";
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.views_user_index', 'Overview'),
'url' => Url::toRoute(['/admin/group/index']),
'url' => ['/admin/group/index'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group' && Yii::$app->controller->action->id == 'index'),
]);
'isActive' => MenuLink::isActiveState('admin', 'group', 'index'),
]));
parent::init();
}
public function run()
{
if(count($this->getItemGroups()) > 1) {
return parent::run();
}
return '';
}
}

View File

@ -9,55 +9,55 @@
namespace humhub\modules\admin\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
/**
* Group Administration Menu
*/
class InformationMenu extends \humhub\widgets\BaseMenu
class InformationMenu extends TabMenu
{
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/tabMenu";
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.information', 'About HumHub'),
'url' => Url::to(['/admin/information/about']),
'url' => ['/admin/information/about'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'information' && Yii::$app->controller->action->id == 'about'),
]);
'isActive' => MenuLink::isActiveState('admin', 'information', 'about')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.information', 'Prerequisites'),
'url' => Url::to(['/admin/information/prerequisites']),
'url' => ['/admin/information/prerequisites'],
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'information' && Yii::$app->controller->action->id == 'prerequisites'),
]);
'isActive' => MenuLink::isActiveState('admin', 'information', 'prerequisites')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.information', 'Database'),
'url' => Url::to(['/admin/information/database']),
'url' => ['/admin/information/database'],
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'information' && Yii::$app->controller->action->id == 'database'),
]);
'isActive' => MenuLink::isActiveState('admin', 'information', 'database')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.information', 'Background Jobs'),
'url' => Url::to(['/admin/information/background-jobs']),
'url' => ['/admin/information/background-jobs'],
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'information' && Yii::$app->controller->action->id == 'background-jobs'),
]);
'isActive' => MenuLink::isActiveState('admin', 'information', 'background-jobs')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.information', 'Logging'),
'url' => Url::toRoute(['/admin/logging']),
'url' => ['/admin/logging'],
'sortOrder' => 500,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'logging'),
]);
'isActive' => MenuLink::isActiveState('admin', 'logging')
]));
parent::init();
}

View File

@ -9,61 +9,61 @@
namespace humhub\modules\admin\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
use humhub\modules\admin\permissions\ManageSettings;
/**
* Group Administration Menu
*/
class SettingsMenu extends \humhub\widgets\BaseMenu
class SettingsMenu extends TabMenu
{
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/tabMenu";
public function init()
{
$canEditSettings = Yii::$app->user->can(new \humhub\modules\admin\permissions\ManageSettings());
$canEditSettings = Yii::$app->user->can(ManageSettings::class);
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'General'),
'url' => Url::toRoute('/admin/setting/index'),
'url' => ['/admin/setting/index'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'basic'),
'isActive' => MenuLink::isActiveState('admin', 'setting', 'basic'),
'isVisible' => $canEditSettings
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Appearance'),
'url' => Url::toRoute('/admin/setting/design'),
'url' => ['/admin/setting/design'],
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'design'),
'isActive' => MenuLink::isActiveState('admin', 'setting', 'design'),
'isVisible' => $canEditSettings
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'E-Mail summaries'),
'url' => Url::toRoute('/activity/admin/defaults'),
'url' => ['/activity/admin/defaults'],
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'activity' && Yii::$app->controller->id == 'admin' && (Yii::$app->controller->action->id == 'defaults')),
'isActive' => MenuLink::isActiveState('activity', 'admin', 'defaults'),
'isVisible' => $canEditSettings
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Notifications'),
'url' => Url::toRoute('/notification/admin/defaults'),
'url' => ['/notification/admin/defaults'],
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'notification' && Yii::$app->controller->id == 'admin' && (Yii::$app->controller->action->id == 'defaults')),
'isActive' => MenuLink::isActiveState('notification', 'admin', 'defaults'),
'isVisible' => $canEditSettings
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Advanced'),
'url' => Url::toRoute('/admin/setting/advanced'),
'url' => ['/admin/setting/advanced'],
'sortOrder' => 1000,
'isVisible' => $canEditSettings
]);
]));
parent::init();
}

View File

@ -10,36 +10,39 @@ namespace humhub\modules\admin\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\admin\permissions\ManageSpaces;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\admin\permissions\ManageSettings;
use humhub\modules\admin\permissions\ManageSpaces;
use humhub\modules\ui\menu\widgets\TabMenu;
/**
* Space Administration Menu
*
* @author Luke
*/
class SpaceMenu extends \humhub\widgets\BaseMenu
class SpaceMenu extends TabMenu
{
public $template = "@humhub/widgets/views/tabMenu";
public $type = "adminUserSubNavigation";
/**
* @inheritdoc
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.views_space_index', 'Spaces'),
'url' => Url::toRoute(['/admin/space/index']),
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'space' && Yii::$app->controller->action->id == 'index'),
'isVisible' => Yii::$app->user->can(new ManageSpaces())
]);
$this->addItem([
'isActive' => MenuLink::isActiveState('admin', 'space', 'index'),
'isVisible' => Yii::$app->user->can(ManageSpaces::class)
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.views_space_index', 'Settings'),
'url' => Url::toRoute(['/admin/space/settings']),
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'space' && Yii::$app->controller->action->id == 'settings'),
'isVisible' => Yii::$app->user->can(new ManageSettings())
]);
'isActive' => MenuLink::isActiveState('admin', 'space', 'settings'),
'isVisible' => Yii::$app->user->can(ManageSettings::class)
]));
parent::init();
}

View File

@ -9,81 +9,75 @@
namespace humhub\modules\admin\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\admin\models\UserApprovalSearch;
use humhub\modules\admin\permissions\ManageUsers;
use humhub\modules\admin\permissions\ManageGroups;
use humhub\modules\admin\permissions\ManageSettings;
use humhub\modules\user\models\Invite;
use humhub\widgets\BaseMenu;
use humhub\modules\admin\permissions\ManageUsers;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
/**
* User Administration Menu
*
* @author Basti
*/
class UserMenu extends BaseMenu
class UserMenu extends TabMenu
{
public $template = '@humhub/widgets/views/tabMenu';
public $type = 'adminUserSubNavigation';
/**
* @inheritdoc
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.views_user_index', 'Users'),
'url' => Url::to(['/admin/user/index']),
'url' => ['/admin/user/index'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && (Yii::$app->controller->id == 'user' || Yii::$app->controller->id == 'pending-registrations')),
'isActive' => MenuLink::isActiveState('admin', ['user', 'pending-registrations']),
'isVisible' => Yii::$app->user->can([
new ManageUsers(),
new ManageGroups(),
ManageUsers::class,
ManageGroups::class,
])
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.views_user_index', 'Settings'),
'url' => Url::to(['/admin/authentication']),
'url' => ['/admin/authentication'],
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'authentication'),
'isVisible' => Yii::$app->user->can([
new ManageSettings()
])
]);
'isActive' => MenuLink::isActiveState('admin', 'authentication'),
'isVisible' => Yii::$app->user->can(ManageSettings::class)
]));
$approvalCount = UserApprovalSearch::getUserApprovalCount();
if ($approvalCount > 0) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.user', 'Pending approvals') . ' <span class="label label-danger">' . $approvalCount . '</span>',
'url' => Url::to(['/admin/approval']),
'url' => ['/admin/approval'],
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'approval'),
'isActive' => MenuLink::isActiveState('admin', 'approval'),
'isVisible' => Yii::$app->user->can([
new ManageUsers(),
new ManageGroups()
ManageUsers::class,
ManageGroups::class
])
]);
]));
}
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.user', 'Profiles'),
'url' => Url::to(['/admin/user-profile']),
'url' => ['/admin/user-profile'],
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'user-profile'),
'isVisible' => Yii::$app->user->can([
new ManageUsers()
])
]);
'isActive' => MenuLink::isActiveState('admin', 'user-profile'),
'isVisible' => Yii::$app->user->can(ManageUsers::class)
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.user', 'Groups'),
'url' => Url::to(['/admin/group']),
'url' => ['/admin/group'],
'sortOrder' => 500,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group'),
'isVisible' => Yii::$app->user->can(
new ManageGroups()
)
]);
'isActive' => MenuLink::isActiveState('admin', 'group'),
'isVisible' => Yii::$app->user->can(ManageGroups::class)
]));
parent::init();
}

View File

@ -9,33 +9,35 @@
namespace humhub\modules\admin\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
/**
* User Administration Menu
*
* @author Basti
*/
class UserSettingMenu extends \humhub\widgets\BaseMenu
class UserSettingMenu extends TabMenu
{
public $template = "@humhub/widgets/views/tabMenu";
public $type = "adminUserSettingNavigation";
/**
* @inheritdoc
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.views_setting_authentication', 'General'),
'url' => Url::toRoute(['/admin/setting/authentication']),
'url' => ['/admin/setting/authentication'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'settings' && Yii::$app->controller->action->id == 'authentication'),
]);
$this->addItem([
'isActive' => MenuLink::isActiveState('admin', 'settings', 'authentication'),
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.views_setting_authentication', 'LDAP'),
'url' => Url::toRoute(['/admin/setting/authentication-ldap']),
'url' => ['/admin/setting/authentication-ldap'],
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'settings' && Yii::$app->controller->action->id == 'authentication-ldap'),
]);
'isActive' => MenuLink::isActiveState('admin', 'settings', 'authentication-ldap'),
]));
parent::init();
}

View File

@ -20,13 +20,14 @@ use humhub\modules\content\components\ContentContainerController;
class ContentContainerHelper
{
/**
* @param string|null $type type filter available since 1.4
* @return ContentContainerActiveRecord|null currently active container from app context.
*/
public static function getCurrent()
public static function getCurrent($type = null)
{
$controller = Yii::$app->controller;
if($controller instanceof ContentContainerController) {
return $controller->contentContainer;
return (!$type || get_class($controller->contentContainer) === $type) ? $controller->contentContainer : null;
}
return null;

View File

@ -190,12 +190,12 @@ class WallEntry extends Widget
$this->addControl($result, [EditLink::class, ['model' => $this->contentObject, 'mode' => $this->editMode, 'url' => $this->getEditUrl()], ['sortOrder' => 200]]);
}
$this->addControl($result, [VisibilityLink::class, ['contentRecord' => $this->contentObject], ['sortOrder' => 250]]);
$this->addControl($result, [NotificationSwitchLink::class, ['content' => $this->contentObject], ['sortOrder' => 300]]);
$this->addControl($result, [PermaLink::class, ['content' => $this->contentObject], ['sortOrder' => 400]]);
$this->addControl($result, [PinLink::class, ['content' => $this->contentObject], ['sortOrder' => 500]]);
$this->addControl($result, [MoveContentLink::class, ['model' => $this->contentObject], ['sortOrder' => 550]]);
$this->addControl($result, [ArchiveLink::class, ['content' => $this->contentObject], ['sortOrder' => 600]]);
$this->addControl($result, [PermaLink::class, ['content' => $this->contentObject], ['sortOrder' => 300]]);
$this->addControl($result, [VisibilityLink::class, ['contentRecord' => $this->contentObject], ['sortOrder' => 400]]);
$this->addControl($result, [NotificationSwitchLink::class, ['content' => $this->contentObject], ['sortOrder' => 500]]);
$this->addControl($result, [PinLink::class, ['content' => $this->contentObject], ['sortOrder' => 600]]);
$this->addControl($result, [MoveContentLink::class, ['model' => $this->contentObject], ['sortOrder' => 700]]);
$this->addControl($result, [ArchiveLink::class, ['content' => $this->contentObject], ['sortOrder' => 800]]);
if(isset($this->controlsOptions['add'])) {
foreach ($this->controlsOptions['add'] as $linkOptions) {

View File

@ -48,8 +48,8 @@ class WallEntryControls extends \humhub\widgets\BaseStack
*
* [MyWidget::class, [...], [...]]
*
* @param type $menuItem
* @return type
* @param [] $menuItem
* @return array
*/
protected function getWallEntryLinkDefinition($menuItem)
{

View File

@ -8,9 +8,10 @@
namespace humhub\modules\dashboard;
use humhub\modules\ui\menu\MenuLink;
use humhub\widgets\TopMenu;
use Yii;
use yii\helpers\Url;
use humhub\modules\dashboard\widgets\ShareWidget;
use yii\base\Event;
/**
* Description of Events
@ -21,23 +22,24 @@ class Events
{
/**
* On build of the TopMenu, check if module is enabled
* When enabled add a menu item
* TopMenu init event callback
*
* @param type $event
* @see TopMenu
* @param Event $event
*/
public static function onTopMenuInit($event)
{
/** @var TopMenu $topMenu */
$topMenu = $event->sender;
// Is Module enabled on this workspace?
$event->sender->addItem([
'label' => Yii::t('DashboardModule.base', 'Dashboard'),
$topMenu->addEntry(new MenuLink([
'id' => 'dashboard',
'icon' => '<i class="fa fa-tachometer"></i>',
'url' => Url::toRoute('/dashboard/dashboard'),
'label' => Yii::t('DashboardModule.base', 'Dashboard'),
'url' => ['/dashboard/dashboard'],
'icon' => 'tachometer',
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'dashboard'),
]);
'isActive' => MenuLink::isActiveState('dashboard')
]));
}
}

View File

@ -8,73 +8,62 @@
namespace humhub\modules\directory\widgets;
use humhub\modules\directory\Module;
use Yii;
use yii\helpers\Url;
use humhub\modules\directory\models\User;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\directory\Module;
use humhub\modules\ui\menu\widgets\LeftNavigation;
/**
* Directory Menu
* Directory module navigation
*
* @since 0.21
* @author Luke
*/
class Menu extends \humhub\widgets\BaseMenu
class Menu extends LeftNavigation
{
public $template = "@humhub/widgets/views/leftNavigation";
/**
* @inheritdoc
*/
public function init()
{
/** @var Module $module */
$module = Yii::$app->getModule('directory');
$this->addItemGroup([
'id' => 'directory',
'label' => Yii::t('DirectoryModule.base', '<strong>Directory</strong> menu'),
'sortOrder' => 100,
]);
$this->panelTitle = Yii::t('DirectoryModule.base', '<strong>Directory</strong> menu');
if (Yii::$app->getModule('directory')->isGroupListingEnabled()) {
$this->addItem([
if ($module->isGroupListingEnabled()) {
$this->addEntry(new MenuLink([
'label' => Yii::t('DirectoryModule.base', 'Groups'),
'group' => 'directory',
'url' => Url::to(['/directory/directory/groups']),
'url' => ['/directory/directory/groups'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->action->id == "groups"),
]);
'isActive' => MenuLink::isActiveState('directory', 'directory', 'groups')
]));
}
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('DirectoryModule.base', 'Members'),
'group' => 'directory',
'url' => Url::to(['/directory/directory/members']),
'url' => ['/directory/directory/members'],
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->action->id == "members"),
]);
'isActive' => MenuLink::isActiveState('directory', 'directory', 'members')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('DirectoryModule.base', 'Spaces'),
'group' => 'directory',
'url' => Url::to(['/directory/directory/spaces']),
'url' => ['/directory/directory/spaces'],
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->action->id == "spaces"),
]);
'isActive' => MenuLink::isActiveState('directory', 'directory', 'spaces')
]));
if ($module->showUserProfilePosts) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('DirectoryModule.base', 'User profile posts'),
'group' => 'directory',
'url' => Url::to(['/directory/directory/user-posts']),
'url' => ['/directory/directory/user-posts'],
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->action->id == "user-posts"),
]);
'isActive' => MenuLink::isActiveState('directory', 'directory', 'user-posts')
]));
}
parent::init();
}
}
?>

View File

@ -9,13 +9,14 @@
namespace humhub\modules\friendship\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
use humhub\modules\friendship\models\Friendship;
/**
* Account Settings Tab Menu
*/
class ManageMenu extends \humhub\widgets\BaseMenu
class ManageMenu extends TabMenu
{
/**
@ -23,39 +24,35 @@ class ManageMenu extends \humhub\widgets\BaseMenu
*/
public $user;
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/tabMenu";
/**
* @inheritdoc
*/
public function init()
{
$friendCount = Friendship::getFriendsQuery($this->user)->count();
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('FriendshipModule.base', 'Friends') . ' (' . $friendCount . ')',
'url' => Url::toRoute(['/friendship/manage/list']),
'url' => ['/friendship/manage/list'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->id == 'manage' && Yii::$app->controller->action->id == 'list'),
]);
'isActive' => MenuLink::isActiveState(null, 'manage', 'list')
]));
$receivedRequestsCount = Friendship::getReceivedRequestsQuery($this->user)->count();
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('FriendshipModule.base', 'Requests') . ' (' . $receivedRequestsCount . ')',
'url' => Url::toRoute(['/friendship/manage/requests']),
'url' => ['/friendship/manage/requests'],
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->id == 'manage' && Yii::$app->controller->action->id == 'requests'),
]);
'isActive' => MenuLink::isActiveState(null, 'manage', 'requests')
]));
$sentRequestsCount = Friendship::getSentRequestsQuery($this->user)->count();
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('FriendshipModule.base', 'Sent requests') . ' (' . $sentRequestsCount . ')',
'url' => Url::toRoute(['/friendship/manage/sent-requests']),
'url' => ['/friendship/manage/sent-requests'],
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->id == 'manage' && Yii::$app->controller->action->id == 'sent-requests'),
]);
'isActive' => MenuLink::isActiveState(null, 'manage', 'sent-requests')
]));
parent::init();
}

View File

@ -8,39 +8,41 @@
namespace humhub\modules\space\modules\manage\widgets;
use humhub\widgets\BaseMenu;
use Yii;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
/**
* Space Administration Menu
*
* @author Luke
*/
class DefaultMenu extends BaseMenu
class DefaultMenu extends TabMenu
{
public $template = '@humhub/widgets/views/tabMenu';
/**
* @var \humhub\modules\space\models\Space
*/
public $space;
/**
* @inheritdoc
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.manage', 'Basic'),
'url' => $this->space->createUrl('/space/manage/default/index'),
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->id == 'default' && Yii::$app->controller->action->id == 'index'),
]);
'isActive' => MenuLink::isActiveState(null, 'default', 'index')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.manage', 'Advanced'),
'url' => $this->space->createUrl('/space/manage/default/advanced'),
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->id == 'default' && Yii::$app->controller->action->id == 'advanced'),
]);
'isActive' => MenuLink::isActiveState(null, 'default', 'advanced')
]));
parent::init();
}

View File

@ -8,24 +8,19 @@
namespace humhub\modules\space\modules\manage\widgets;
use humhub\widgets\BaseMenu;
use humhub\modules\space\modules\manage\models\MembershipSearch;
use humhub\modules\space\models\Membership;
use Yii;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\space\models\Membership;
use humhub\modules\space\modules\manage\models\MembershipSearch;
use humhub\modules\ui\menu\widgets\TabMenu;
/**
* MemberMenu is a tabbed menu for space member administration
*
* @author Basti
*/
class MemberMenu extends BaseMenu
class MemberMenu extends TabMenu
{
/**
* @inheritdoc
*/
public $template = '@humhub/widgets/views/tabMenu';
/**
* @var \humhub\modules\space\models\Space
*/
@ -37,37 +32,37 @@ class MemberMenu extends BaseMenu
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Members'),
'url' => $this->space->createUrl('/space/manage/member/index'),
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->action->id == 'index' && Yii::$app->controller->id === 'member'),
]);
'isActive' => MenuLink::isActiveState(null, 'member', 'index')
]));
if ($this->countPendingInvites() != 0) {
$this->addItem([
'label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Pending Invites') . '&nbsp;&nbsp;<span class="label label-danger">'.$this->countPendingInvites().'</span>',
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Pending Invites') . '&nbsp;&nbsp;<span class="label label-danger">' . $this->countPendingInvites() . '</span>',
'url' => $this->space->createUrl('/space/manage/member/pending-invitations'),
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->action->id == 'pending-invitations'),
]);
'isActive' => MenuLink::isActiveState(null, 'member', 'pending-invitations')
]));
}
if ($this->countPendingApprovals() != 0) {
$this->addItem([
'label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Pending Approvals'). '&nbsp;&nbsp;<span class="label label-danger">'.$this->countPendingApprovals().'</span>',
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Pending Approvals') . '&nbsp;&nbsp;<span class="label label-danger">' . $this->countPendingApprovals() . '</span>',
'url' => $this->space->createUrl('/space/manage/member/pending-approvals'),
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->action->id == 'pending-approvals'),
]);
'isActive' => MenuLink::isActiveState(null, 'member', 'pending-approvals')
]));
}
if ($this->space->isSpaceOwner()) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceMembersMenu', 'Owner'),
'url' => $this->space->createUrl('/space/manage/member/change-owner'),
'sortOrder' => 500,
'isActive' => (Yii::$app->controller->action->id == 'change-owner'),
]);
'isActive' => MenuLink::isActiveState(null, 'member', 'change-owner')
]));
}

View File

@ -8,7 +8,8 @@
namespace humhub\modules\space\modules\manage\widgets;
use humhub\widgets\BaseMenu;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
use Yii;
/**
@ -16,31 +17,32 @@ use Yii;
*
* @author Luke
*/
class SecurityTabMenu extends BaseMenu
class SecurityTabMenu extends TabMenu
{
public $template = '@humhub/widgets/views/tabMenu';
/**
* @var \humhub\modules\space\models\Space
*/
public $space;
/**
* @inheritdoc
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.manage', 'General'),
'url' => $this->space->createUrl('/space/manage/security'),
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->id == 'security' && Yii::$app->controller->action->id == 'index'),
]);
'isActive' => MenuLink::isActiveState(null, 'security', 'index'),
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.manage', 'Permissions'),
'url' => $this->space->createUrl('/space/manage/security/permissions'),
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->id == 'security' && Yii::$app->controller->action->id == 'permissions'),
]);
'isActive' => MenuLink::isActiveState(null, 'security', 'permissions'),
]));
parent::init();
}

View File

@ -1,20 +0,0 @@
<?php
namespace humhub\modules\space\widgets;
/**
* Deprecated Admin Menu Widget
*
* Use humhub\module\space\modules\manage\widget\Menu instead!
* This is only a stub to avoid potential module errors!
*
* @author Luke
* @since 0.5
* @deprecated since version 0.21
*/
class AdminMenu extends \humhub\widgets\BaseMenu
{
}
?>

View File

@ -8,7 +8,10 @@
namespace humhub\modules\space\widgets;
use humhub\widgets\BaseMenu;
use humhub\modules\space\models\Space;
use humhub\modules\ui\menu\DropdownDivider;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\DropdownMenu;
use Yii;
/**
@ -18,108 +21,99 @@ use Yii;
* @package humhub.modules_core.space.widgets
* @since 0.5
*/
class HeaderControlsMenu extends BaseMenu
class HeaderControlsMenu extends DropdownMenu
{
/**
* @var Space
*/
public $space;
public $template = '@humhub/widgets/views/leftNavigation';
/**
* @inheritdoc
*/
public $label = '<i class="fa fa-cog"></i>';
/**
* @inheritdoc
*/
public function init()
{
$this->addItemGroup([
'id' => 'admin',
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', '<i class="fa fa-cog"></i>'),
'sortOrder' => 100,
]);
if ($this->template === '@humhub/widgets/views/dropdownNavigation') {
$this->template = '@ui/menu/widgets/views/dropdown-menu.php';
}
// check user rights
if ($this->space->isAdmin()) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.base', 'Settings'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/manage'),
'icon' => '<i class="fa fa-cogs"></i>',
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->id === 'default'),
]);
'icon' => 'cogs',
'sortOrder' => 100
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Security'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/manage/security'),
'icon' => '<i class="fa fa-lock"></i>',
'icon' => 'lock',
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->id === 'security'),
]);
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Members'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/manage/member'),
'icon' => '<i class="fa fa-group"></i>',
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->id === 'member'),
]);
'icon' => 'group',
'sortOrder' => 300
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Modules'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/manage/module'),
'icon' => '<i class="fa fa-rocket"></i>',
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->id === 'module'),
]);
'icon' => 'rocket',
'sortOrder' => 400,
]));
$this->addEntry(new DropdownDivider(['sortOrder' => 500]));
}
if ($this->space->isMember()) {
$membership = $this->space->getMembership();
if (!$membership->send_notifications) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Receive Notifications for new content'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/membership/receive-notifications'),
'icon' => '<i class="fa fa-bell"></i>',
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->id === 'module'),
'icon' => 'bell',
'sortOrder' => 600,
'htmlOptions' => ['data-method' => 'POST']
]);
]));
} else {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Don\'t receive notifications for new content'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/membership/revoke-notifications'),
'icon' => '<i class="fa fa-bell-o"></i>',
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->id === 'module'),
'icon' => 'bell-o',
'sortOrder' => 600,
'htmlOptions' => ['data-method' => 'POST']
]);
]));
}
if (!$this->space->isSpaceOwner() && $this->space->canLeave()) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Cancel Membership'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/membership/revoke-membership'),
'icon' => '<i class="fa fa-times"></i>',
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->id === 'module'),
'icon' => 'times',
'sortOrder' => 700,
'htmlOptions' => ['data-method' => 'POST']
]);
]));
}
if ($membership->show_at_dashboard) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Hide posts on dashboard'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/membership/switch-dashboard-display', ['show' => 0]),
'icon' => '<i class="fa fa-eye-slash"></i>',
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->id === 'module'),
'icon' => 'eye-slash',
'sortOrder' => 800,
'htmlOptions' => [
'data-method' => 'POST',
'class' => 'tt',
@ -127,22 +121,20 @@ class HeaderControlsMenu extends BaseMenu
'data-placement' => 'left',
'title' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'This option will hide new content from this space at your dashboard')
]
]);
]));
} else {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Show posts on dashboard'),
'group' => 'admin',
'url' => $this->space->createUrl('/space/membership/switch-dashboard-display', ['show' => 1]),
'icon' => '<i class="fa fa-eye"></i>',
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->id === 'module'),
'icon' => 'fa-eye',
'sortOrder' => 800,
'htmlOptions' => ['data-method' => 'POST',
'class' => 'tt',
'data-toggle' => 'tooltip',
'data-placement' => 'left',
'title' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'This option will show new content from this space at your dashboard')
]
]);
]));
}
}

View File

@ -8,9 +8,11 @@
namespace humhub\modules\space\widgets;
use humhub\widgets\BaseMenu;
use humhub\modules\content\components\ContentContainerController;
use humhub\modules\content\helpers\ContentContainerHelper;
use humhub\modules\space\models\Space;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\LeftNavigation;
use Yii;
use yii\base\Exception;
@ -18,41 +20,38 @@ use yii\base\Exception;
* The Main Navigation for a space. It includes the Modules the Stream
*
* @author Luke
* @package humhub.modules_core.space.widgets
* @since 0.5
*/
class Menu extends BaseMenu
class Menu extends LeftNavigation
{
/** @var Space */
public $space;
public $template = '@humhub/widgets/views/leftNavigation';
/**
* @inheritdoc
*/
public function init()
{
if ($this->space === null && Yii::$app->controller instanceof ContentContainerController && Yii::$app->controller->contentContainer instanceof Space) {
$this->space = Yii::$app->controller->contentContainer;
if(!$this->space) {
$this->space = ContentContainerHelper::getCurrent(Space::class);
}
if ($this->space === null) {
if (!$this->space) {
throw new Exception('Could not instance space menu without space!');
}
$this->id = 'navigation-menu-space-' . $this->space->getUniqueId();
$this->addItemGroup([
'id' => 'modules',
'label' => Yii::t('SpaceModule.widgets_SpaceMenuWidget', '<strong>Space</strong> menu'),
'sortOrder' => 100,
]);
$this->panelTitle = Yii::t('SpaceModule.widgets_SpaceMenuWidget', '<strong>Space</strong> menu');
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('SpaceModule.widgets_SpaceMenuWidget', 'Stream'),
'group' => 'modules',
'url' => $this->space->createUrl('/space/space/home'),
'icon' => '<i class="fa fa-bars"></i>',
'icon' => 'fa-bars',
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->id == 'space' && (Yii::$app->controller->action->id == 'index' || Yii::$app->controller->action->id == 'home') && Yii::$app->controller->module->id == 'space'),
]);
'isActive' => MenuLink::isActiveState('space', 'space', ['index', 'home']),
]));
parent::init();
}
@ -63,15 +62,15 @@ class Menu extends BaseMenu
* The urls are associated with a module label.
*
* Returns an array of urls with associated module labes for modules
* @param type $space
*/
public static function getAvailablePages()
{
//Initialize the space Menu to check which active modules have an own page
$moduleItems = (new static())->getItems('modules');
$entries = (new static())->getEntries(MenuLink::class);
$result = [];
foreach ($moduleItems as $moduleItem) {
$result[$moduleItem['url']] = $moduleItem['label'];
foreach ($entries as $entry) {
/* @var $entry MenuLink */
$result[$entry->getUrl()] = $entry->getLabel();
}
return $result;
@ -80,6 +79,7 @@ class Menu extends BaseMenu
/**
* Returns space default / homepage
*
* @param Space $space
* @return string|null the url to redirect or null for default home
*/
public static function getDefaultPageUrl($space)
@ -91,11 +91,11 @@ class Menu extends BaseMenu
$pages = static::getAvailablePages();
if (isset($pages[$indexUrl])) {
return $indexUrl;
} else {
}
//Either the module was deactivated or url changed
$settings->contentContainer($space)->delete('indexUrl');
}
}
return null;
}
@ -103,6 +103,7 @@ class Menu extends BaseMenu
/**
* Returns space default / homepage
*
* @param $space Space
* @return string|null the url to redirect or null for default home
*/
public static function getGuestsDefaultPageUrl($space)
@ -114,11 +115,11 @@ class Menu extends BaseMenu
$pages = static::getAvailablePages();
if (isset($pages[$indexUrl])) {
return $indexUrl;
} else {
}
//Either the module was deactivated or url changed
$settings->contentContainer($space)->delete('indexGuestUrl');
}
}
return null;
}

View File

@ -181,10 +181,7 @@ if ($space->isAdmin()) {
['sortOrder' => 30]]
]]);
?>
<?= HeaderControlsMenu::widget([
'space' => $space,
'template' => '@humhub/widgets/views/dropdownNavigation'
]);
<?= HeaderControlsMenu::widget(['space' => $space]);
?>
</div>
</div>

View File

@ -9,6 +9,7 @@
namespace humhub\modules\ui\form\validators;
use humhub\modules\ui\form\widgets\IconPicker;
use humhub\modules\ui\icon\widgets\Icon;
use Yii;
use yii\validators\Validator;
@ -30,7 +31,7 @@ class IconValidator extends Validator
{
$iconPicker = new IconPicker(['model' => $model, 'attribute' => $attribute]);
if (!in_array($model->$attribute, $iconPicker->getIcons())) {
if (!in_array($model->$attribute, Icon::$names)) {
$this->addError($model, $attribute, Yii::t('UiModule.form', 'Invalid icon.'));
}
}

View File

@ -9,6 +9,7 @@
namespace humhub\modules\ui\form\widgets;
use humhub\modules\ui\icon\widgets\Icon;
use kartik\select2\Select2;
use Yii;
use yii\web\JsExpression;
@ -28,591 +29,9 @@ use yii\web\JsExpression;
class IconPicker extends Select2
{
/**
* @var array the list of available icons
* @var string optional icon provider id
*/
public $icons = [
'fa-adjust',
'fa-adn',
'fa-align-center',
'fa-align-justify',
'fa-align-left',
'fa-align-right',
'fa-ambulance',
'fa-anchor',
'fa-android',
'fa-angellist',
'fa-angle-double-down',
'fa-angle-double-left',
'fa-angle-double-right',
'fa-angle-double-up',
'fa-angle-down',
'fa-angle-left',
'fa-angle-right',
'fa-angle-up',
'fa-apple',
'fa-archive',
'fa-area-chart',
'fa-arrow-circle-down',
'fa-arrow-circle-left',
'fa-arrow-circle-o-down',
'fa-arrow-circle-o-left',
'fa-arrow-circle-o-right',
'fa-arrow-circle-o-up',
'fa-arrow-circle-right',
'fa-arrow-circle-up',
'fa-arrow-down',
'fa-arrow-left',
'fa-arrow-right',
'fa-arrow-up',
'fa-arrows',
'fa-arrows-alt',
'fa-arrows-h',
'fa-arrows-v',
'fa-asterisk',
'fa-at',
'fa-backward',
'fa-ban',
'fa-bank-alias',
'fa-bar-chart',
'fa-bar-chart-o-alias',
'fa-barcode',
'fa-bars',
'fa-bed',
'fa-beer',
'fa-behance',
'fa-behance-square',
'fa-bell',
'fa-bell-o',
'fa-bell-slash',
'fa-bell-slash-o',
'fa-bicycle',
'fa-binoculars',
'fa-birthday-cake',
'fa-bitbucket',
'fa-bitbucket-square',
'fa-bitcoin-alias',
'fa-bold',
'fa-bolt',
'fa-bomb',
'fa-book',
'fa-bookmark',
'fa-bookmark-o',
'fa-briefcase',
'fa-btc',
'fa-bug',
'fa-building',
'fa-building-o',
'fa-bullhorn',
'fa-bullseye',
'fa-bus',
'fa-buysellads',
'fa-cab-alias',
'fa-calculator',
'fa-calendar',
'fa-calendar-o',
'fa-camera',
'fa-camera-retro',
'fa-car',
'fa-caret-down',
'fa-caret-left',
'fa-caret-right',
'fa-caret-square-o-down',
'fa-caret-square-o-left',
'fa-caret-square-o-right',
'fa-caret-square-o-up',
'fa-caret-up',
'fa-cart-arrow-down',
'fa-cart-plus',
'fa-cc',
'fa-cc-amex',
'fa-cc-discover',
'fa-cc-mastercard',
'fa-cc-paypal',
'fa-cc-stripe',
'fa-cc-visa',
'fa-certificate',
'fa-chain-alias',
'fa-chain-broken',
'fa-check',
'fa-check-circle',
'fa-check-circle-o',
'fa-check-square',
'fa-check-square-o',
'fa-chevron-circle-down',
'fa-chevron-circle-left',
'fa-chevron-circle-right',
'fa-chevron-circle-up',
'fa-chevron-down',
'fa-chevron-left',
'fa-chevron-right',
'fa-chevron-up',
'fa-child',
'fa-circle',
'fa-circle-o',
'fa-circle-o-notch',
'fa-circle-thin',
'fa-clipboard',
'fa-clock-o',
'fa-close-alias',
'fa-cloud',
'fa-cloud-download',
'fa-cloud-upload',
'fa-cny-alias',
'fa-code',
'fa-code-fork',
'fa-codepen',
'fa-coffee',
'fa-cog',
'fa-cogs',
'fa-columns',
'fa-comment',
'fa-comment-o',
'fa-comments',
'fa-comments-o',
'fa-compass',
'fa-compress',
'fa-connectdevelop',
'fa-copy-alias',
'fa-copyright',
'fa-credit-card',
'fa-crop',
'fa-crosshairs',
'fa-css3',
'fa-cube',
'fa-cubes',
'fa-cut-alias',
'fa-cutlery',
'fa-dashboard-alias',
'fa-dashcube',
'fa-database',
'fa-dedent-alias',
'fa-delicious',
'fa-desktop',
'fa-deviantart',
'fa-diamond',
'fa-digg',
'fa-dollar-alias',
'fa-dot-circle-o',
'fa-download',
'fa-dribbble',
'fa-dropbox',
'fa-drupal',
'fa-edit-alias',
'fa-eject',
'fa-ellipsis-h',
'fa-ellipsis-v',
'fa-empire',
'fa-envelope',
'fa-envelope-o',
'fa-envelope-square',
'fa-eraser',
'fa-eur',
'fa-euro-alias',
'fa-exchange',
'fa-exclamation',
'fa-exclamation-circle',
'fa-exclamation-triangle',
'fa-expand',
'fa-external-link',
'fa-external-link-square',
'fa-eye',
'fa-eye-slash',
'fa-eyedropper',
'fa-facebook',
'fa-facebook-f-alias',
'fa-facebook-official',
'fa-facebook-square',
'fa-fast-backward',
'fa-fast-forward',
'fa-fax',
'fa-female',
'fa-fighter-jet',
'fa-file',
'fa-file-archive-o',
'fa-file-audio-o',
'fa-file-code-o',
'fa-file-excel-o',
'fa-file-image-o',
'fa-file-movie-o-alias',
'fa-file-o',
'fa-file-pdf-o',
'fa-file-photo-o-alias',
'fa-file-picture-o-alias',
'fa-file-powerpoint-o',
'fa-file-sound-o-alias',
'fa-file-text',
'fa-file-text-o',
'fa-file-video-o',
'fa-file-word-o',
'fa-file-zip-o-alias',
'fa-files-o',
'fa-film',
'fa-filter',
'fa-fire',
'fa-fire-extinguisher',
'fa-flag',
'fa-flag-checkered',
'fa-flag-o',
'fa-flash-alias',
'fa-flask',
'fa-flickr',
'fa-floppy-o',
'fa-folder',
'fa-folder-o',
'fa-folder-open',
'fa-folder-open-o',
'fa-font',
'fa-forumbee',
'fa-forward',
'fa-foursquare',
'fa-frown-o',
'fa-futbol-o',
'fa-gamepad',
'fa-gavel',
'fa-gbp',
'fa-ge-alias',
'fa-gear-alias',
'fa-gears-alias',
'fa-genderless-alias',
'fa-gift',
'fa-git',
'fa-git-square',
'fa-github',
'fa-github-alt',
'fa-github-square',
'fa-gittip-alias',
'fa-glass',
'fa-globe',
'fa-google',
'fa-google-plus',
'fa-google-plus-square',
'fa-google-wallet',
'fa-graduation-cap',
'fa-gratipay',
'fa-group-alias',
'fa-h-square',
'fa-hacker-news',
'fa-hand-o-down',
'fa-hand-o-left',
'fa-hand-o-right',
'fa-hand-o-up',
'fa-hdd-o',
'fa-header',
'fa-headphones',
'fa-heart',
'fa-heart-o',
'fa-heartbeat',
'fa-history',
'fa-home',
'fa-hospital-o',
'fa-hotel-alias',
'fa-html5',
'fa-ils',
'fa-image-alias',
'fa-inbox',
'fa-indent',
'fa-info',
'fa-info-circle',
'fa-inr',
'fa-instagram',
'fa-institution-alias',
'fa-ioxhost',
'fa-italic',
'fa-joomla',
'fa-jpy',
'fa-jsfiddle',
'fa-key',
'fa-keyboard-o',
'fa-krw',
'fa-language',
'fa-laptop',
'fa-lastfm',
'fa-lastfm-square',
'fa-leaf',
'fa-leanpub',
'fa-legal-alias',
'fa-lemon-o',
'fa-level-down',
'fa-level-up',
'fa-life-bouy-alias',
'fa-life-buoy-alias',
'fa-life-ring',
'fa-life-saver-alias',
'fa-lightbulb-o',
'fa-line-chart',
'fa-link',
'fa-linkedin',
'fa-linkedin-square',
'fa-linux',
'fa-list',
'fa-list-alt',
'fa-list-ol',
'fa-list-ul',
'fa-location-arrow',
'fa-lock',
'fa-long-arrow-down',
'fa-long-arrow-left',
'fa-long-arrow-right',
'fa-long-arrow-up',
'fa-magic',
'fa-magnet',
'fa-mail-forward-alias',
'fa-mail-reply-alias',
'fa-mail-reply-all-alias',
'fa-male',
'fa-map-marker',
'fa-mars',
'fa-mars-double',
'fa-mars-stroke',
'fa-mars-stroke-h',
'fa-mars-stroke-v',
'fa-maxcdn',
'fa-meanpath',
'fa-medium',
'fa-medkit',
'fa-meh-o',
'fa-mercury',
'fa-microphone',
'fa-microphone-slash',
'fa-minus',
'fa-minus-circle',
'fa-minus-square',
'fa-minus-square-o',
'fa-mobile',
'fa-mobile-phone-alias',
'fa-money',
'fa-moon-o',
'fa-mortar-board-alias',
'fa-motorcycle',
'fa-music',
'fa-navicon-alias',
'fa-neuter',
'fa-newspaper-o',
'fa-openid',
'fa-outdent',
'fa-pagelines',
'fa-paint-brush',
'fa-paper-plane',
'fa-paper-plane-o',
'fa-paperclip',
'fa-paragraph',
'fa-paste-alias',
'fa-pause',
'fa-paw',
'fa-paypal',
'fa-pencil',
'fa-pencil-square',
'fa-pencil-square-o',
'fa-phone',
'fa-phone-square',
'fa-photo-alias',
'fa-picture-o',
'fa-pie-chart',
'fa-pied-piper',
'fa-pied-piper-alt',
'fa-pinterest',
'fa-pinterest-p',
'fa-pinterest-square',
'fa-plane',
'fa-play',
'fa-play-circle',
'fa-play-circle-o',
'fa-plug',
'fa-plus',
'fa-plus-circle',
'fa-plus-square',
'fa-plus-square-o',
'fa-power-off',
'fa-print',
'fa-puzzle-piece',
'fa-qq',
'fa-qrcode',
'fa-question',
'fa-question-circle',
'fa-quote-left',
'fa-quote-right',
'fa-ra-alias',
'fa-random',
'fa-rebel',
'fa-recycle',
'fa-reddit',
'fa-reddit-square',
'fa-refresh',
'fa-remove-alias',
'fa-renren',
'fa-reorder-alias',
'fa-repeat',
'fa-reply',
'fa-reply-all',
'fa-retweet',
'fa-rmb-alias',
'fa-road',
'fa-rocket',
'fa-rotate-left-alias',
'fa-rotate-right-alias',
'fa-rouble-alias',
'fa-rss',
'fa-rss-square',
'fa-rub',
'fa-ruble-alias',
'fa-rupee-alias',
'fa-save-alias',
'fa-scissors',
'fa-search',
'fa-search-minus',
'fa-search-plus',
'fa-sellsy',
'fa-send-alias',
'fa-send-o-alias',
'fa-server',
'fa-share',
'fa-share-alt',
'fa-share-alt-square',
'fa-share-square',
'fa-share-square-o',
'fa-shekel-alias',
'fa-sheqel-alias',
'fa-shield',
'fa-ship',
'fa-shirtsinbulk',
'fa-shopping-cart',
'fa-sign-in',
'fa-sign-out',
'fa-signal',
'fa-simplybuilt',
'fa-sitemap',
'fa-skyatlas',
'fa-skype',
'fa-slack',
'fa-sliders',
'fa-slideshare',
'fa-smile-o',
'fa-soccer-ball-o-alias',
'fa-sort',
'fa-sort-alpha-asc',
'fa-sort-alpha-desc',
'fa-sort-amount-asc',
'fa-sort-amount-desc',
'fa-sort-asc',
'fa-sort-desc',
'fa-sort-down-alias',
'fa-sort-numeric-asc',
'fa-sort-numeric-desc',
'fa-sort-up-alias',
'fa-soundcloud',
'fa-space-shuttle',
'fa-spinner',
'fa-spoon',
'fa-spotify',
'fa-square',
'fa-square-o',
'fa-stack-exchange',
'fa-stack-overflow',
'fa-star',
'fa-star-half',
'fa-star-half-empty-alias',
'fa-star-half-full-alias',
'fa-star-half-o',
'fa-star-o',
'fa-steam',
'fa-steam-square',
'fa-step-backward',
'fa-step-forward',
'fa-stethoscope',
'fa-stop',
'fa-street-view',
'fa-strikethrough',
'fa-stumbleupon',
'fa-stumbleupon-circle',
'fa-subscript',
'fa-subway',
'fa-suitcase',
'fa-sun-o',
'fa-superscript',
'fa-support-alias',
'fa-table',
'fa-tablet',
'fa-tachometer',
'fa-tag',
'fa-tags',
'fa-tasks',
'fa-taxi',
'fa-tencent-weibo',
'fa-terminal',
'fa-text-height',
'fa-text-width',
'fa-th',
'fa-th-large',
'fa-th-list',
'fa-thumb-tack',
'fa-thumbs-down',
'fa-thumbs-o-down',
'fa-thumbs-o-up',
'fa-thumbs-up',
'fa-ticket',
'fa-times',
'fa-times-circle',
'fa-times-circle-o',
'fa-tint',
'fa-toggle-off',
'fa-toggle-on',
'fa-train',
'fa-transgender',
'fa-transgender-alt',
'fa-trash',
'fa-trash-o',
'fa-tree',
'fa-trello',
'fa-trophy',
'fa-truck',
'fa-try',
'fa-tty',
'fa-tumblr',
'fa-tumblr-square',
'fa-twitch',
'fa-twitter',
'fa-twitter-square',
'fa-umbrella',
'fa-underline',
'fa-undo',
'fa-university',
'fa-unlock',
'fa-unlock-alt',
'fa-upload',
'fa-usd',
'fa-user',
'fa-user-md',
'fa-user-plus',
'fa-user-secret',
'fa-user-times',
'fa-users',
'fa-venus',
'fa-venus-double',
'fa-venus-mars',
'fa-viacoin',
'fa-video-camera',
'fa-vimeo-square',
'fa-vine',
'fa-vk',
'fa-volume-down',
'fa-volume-off',
'fa-volume-up',
'fa-weibo',
'fa-weixin',
'fa-whatsapp',
'fa-wheelchair',
'fa-wifi',
'fa-windows',
'fa-wordpress',
'fa-wrench',
'fa-xing',
'fa-xing-square',
'fa-yahoo',
'fa-yelp',
'fa-youtube',
'fa-youtube-play',
'fa-youtube-square'
];
public $lib;
/**
* @inheritdoc
@ -627,6 +46,18 @@ class IconPicker extends Select2
parent::init();
}
/**
* @inheritdoc
*/
public function run()
{
$this->value = (strpos($this->value, 'fa-') === 0)
? substr($this->value, 3, strlen($this->value))
: $this->value;
return parent::run();
}
/**
* @inheritdoc
*/
@ -641,13 +72,13 @@ class IconPicker extends Select2
*/
protected function populateIconList()
{
foreach ($this->getIcons() as $icon) {
foreach ($this->getIconNames() as $icon) {
$title = $icon;
if (substr($title, 0, 3) === 'fa-') {
$title = substr($title, 3);
}
$this->data[$icon] = '<i class="fa ' . $icon . '"></i>&nbsp;&nbsp;' . $title;
$this->data[$icon] = Icon::get(['name' => $icon, 'lib' => $this->lib]) . '&nbsp;&nbsp;' . $title;
}
}
@ -656,9 +87,9 @@ class IconPicker extends Select2
*
* @return array a list of icons
*/
public function getIcons()
public function getIconNames()
{
return $this->icons;
return Icon::getNames($this->lib);
}
}

View File

@ -0,0 +1,126 @@
<?php
namespace humhub\modules\ui\icon\components;
use humhub\libs\Html;
use humhub\modules\ui\icon\widgets\Icon;
/**
* Class FontAwesomeIconFactory
* @package humhub\modules\ui\icon
*
* @since 1.4
*/
class FontAwesomeIconProvider implements IconProvider
{
/**
* @return string
*/
public function getId()
{
return 'fa';
}
/**
* @param Icon $icon
* @return string
*/
public function render($icon, $options = [])
{
$icon = Icon::get($icon,$options);
$options = $icon->htmlOptions;
$options['class'] = 'fa fa-'.$icon->name;
if($icon->size) {
Html::addCssClass($options, $this->getIconSizeClass($icon));
}
if($icon->fixedWidth) {
Html::addCssClass($options, 'fa-fw');
}
if($icon->listItem) {
Html::addCssClass($options, 'fa-li');
}
if($icon->right) {
Html::addCssClass($options, 'fa-pull-right');
}
if($icon->left) {
Html::addCssClass($options, 'fa-pull-left');
}
if($icon->border) {
Html::addCssClass($options, 'fa-border');
}
if($icon->ariaHidden) {
$options['aria-hidden'] = 'true';
}
if($icon->color) {
Html::addCssStyle($options, ['color' => $icon->color]);
}
return Html::beginTag('i', $options).Html::endTag('i');
}
/**
* @param $listDefinition []
* @return $
*/
public function renderList($listDefinition)
{
$items = [];
foreach ($listDefinition as $listItem)
{
$text = reset($listItem);
$iconName = key($listItem);
$options = (isset($listItem['options'])) ? $listItem['options'] : [];
$options['listItem'] = true;
$items[] = $this->render($iconName, $options).$text;
}
return Html::ul($items, ['class' => 'fa-ul', 'encode' => false]);
}
private function getIconSizeClass(Icon $icon)
{
switch ($icon->size) {
case Icon::SIZE_SM:
return 'fa-sm';
case Icon::SIZE_LG:
return 'fa-lg';
case Icon::SIZE_2x:
return 'fa-2x';
case Icon::SIZE_3x:
return 'fa-3x';
case Icon::SIZE_4x:
return 'fa-4x';
case Icon::SIZE_5x:
return 'fa-5x';
case Icon::SIZE_6x:
return 'fa-6x';
case Icon::SIZE_7x:
return 'fa-7x';
case Icon::SIZE_8x:
return 'fa-8x';
case Icon::SIZE_9x:
return 'fa-9x';
case Icon::SIZE_10x:
return 'fa-10x';
default:
return null;
}
}
/**
* @inheritdoc
*/
public function getNames()
{
return Icon::$names;
}
}

View File

@ -0,0 +1,149 @@
<?php
namespace humhub\modules\ui\icon\components;
use Yii;
use yii\base\Component;
/**
* IconFactory handles the registration and access of IconProviders.
*
* Modules may register additional IconProviders or overwrite the default IconProvider by means of [[registerProvider()]]
* within the [[EVENT_AFTER_INIT]] event.
*
* If an IconProvider does only a subset of all icon names the [[IconProvider::render]] function should return null. In
* this case the IconFactory will fall back to an [[fallbackProvider]].
*
* By default the FontAwesomeIconProvider is set as default provider.
*
* @see DevtoolsIconProvider
* @since 1.4
*/
class IconFactory extends Component
{
/**
* @event \yii\base\Event triggered after init, can be used to overwrite the [[defaultProvider]]
*/
const EVENT_AFTER_INIT = 'afterInit';
/**
* @var IconProvider
*/
private static $defaultProvider;
/**
* @var IconProvider
*/
public static $fallbackProvider;
/**
* @var [] array of IconProvider instances associated with a provider id
*/
private static $provider = [];
/**
* @var IconFactory singleton instance
*/
private static $instance;
/**
* @return IconFactory singleton instance
* @throws \yii\base\InvalidConfigException
*/
public static function getInstance()
{
if(!static::$instance) {
static::$instance = Yii::createObject(['class' => static::class]);
}
return static::$instance;
}
/**
* Adds a provider to this factory, if `$isDefault` is set to true the current default IconProvider
* will be overwritten.
*
* @param IconProvider $instance
*/
public static function registerProvider(IconProvider $instance, $isDefault = false)
{
static::$provider[$instance->getId()] = $instance;
if($isDefault) {
static::$defaultProvider = $instance;
}
}
/**
* @inheritdoc
*/
public function init()
{
$fontAwesomeIconProvider = new FontAwesomeIconProvider();
static::registerProvider($fontAwesomeIconProvider, true);
static::$fallbackProvider = $fontAwesomeIconProvider;
$this->trigger(static::EVENT_AFTER_INIT);
}
/**
* @param $icon
* @param array $options
* @see IconProvider::render()
* @return mixed
*/
public function render($icon, $options = [])
{
$result = $this->getProvider($icon->lib)->render($icon, $options);
if(empty($result)) {
$result = static::$fallbackProvider->render($icon, $options);
}
return $result;
}
/**
* @param string|null $providerId icon provider id
* @return IconProvider
*/
public function getProvider($providerId = null)
{
if(empty($providerId)) {
return static::$defaultProvider;
}
if(!isset(static::$provider[$providerId])) {
Yii::warning(Yii::t('UiModule.icon', 'No icon provider registered for provider id {id}', ['id' => $providerId]));
return static::$defaultProvider;
}
return static::$provider[$providerId];
}
/**
*
* @param $listDefinition
* @param null $providerId
* @see IconProvider::renderList()
* @return mixed
*/
public function renderList($listDefinition, $providerId = null)
{
$result = $this->getProvider($providerId)->renderList($listDefinition);
if(empty($result)) {
$result = static::$fallbackProvider->renderList($listDefinition);
}
return $result;
}
/**
* Returns the supported icon names of the IconProvider
*
* @param null $providerId
* @see IconProvider::getNames()
* @return string[]
*/
public function getNames($providerId = null)
{
return $this->getProvider($providerId)->getNames();
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace humhub\modules\ui\icon\components;
use humhub\modules\ui\icon\widgets\Icon;
/**
* IconProviders are used to render an icon for a specific icon library.
*
* The [[render()]] function of a IconProvider should ideally support all features of the [[\humhub\modules\ui\icon\widgets\Icon]]
* widget and furthermore map all icon names available in [[\humhub\modules\ui\icon\widgets\Icon::$names]].
*
* @since 1.4
*/
interface IconProvider
{
/**
* @return string unique factory id used in the `lib` option of icons
*/
public function getId();
/**
* Use as follows:
*
* ```php
* IconFactory::render('task');
*
* IconFactory::render('task', ['fixedWith' => true]);
*
* IconFactory::render(['name' => 'task', 'fixedWith' => true]);
*
* IconFactory::render(new Icon(['name' => 'task', 'fixedWith' => true]));
* ```
*
* > Note: If the provider does not support a specific icon name or feature it should return null.
*
* @param $icon string|Icon|[]|null either an icon name, icon instance or icon array definition
* @return mixed
*/
public function render($icon, $options = []);
/**
* Renders a icon list:
*
* <?= IconFactory::renderList([
* ['task' => 'My List Item 1', 'options' => []],
* ['tachometer' => 'My List Item 2', 'options' => []]
* ]); ?>
*
* > Note: If the provider does not support this feature, it should return null.
*
* @param $listDefinition
* @return $
*/
public function renderList($listDefinition);
/**
* Return all supported icon names.
* @return string[]
*/
public function getNames();
}

View File

@ -0,0 +1,946 @@
<?php
namespace humhub\modules\ui\icon\widgets;
use Yii;
use humhub\libs\Html;
use humhub\modules\ui\icon\components\IconProvider;
use humhub\modules\ui\icon\components\IconFactory;
/**
* The Icon widget is used as abstraction layer for rendering icons.
*
* This class only holds the icon definition as icon name, size and color and will forward the
* actual rendering to an IconProvider through an IconFactory.
*
* It is possible to define own IconProvider, see [[IconFactory]]
*
* Usage:
*
* ```php
* // Simple Icon
* Icon::get('myIcon');
*
* // Icon with color definition
* Icon::get('myIcon', ['color' => 'danger']);
*
* // Use another icon lib
* Icon::get('myIcon', ['lib' => 'myIconLib']);
* ```
*
* @see IconFactory
* @see IconProvider
* @since 1.4
*/
class Icon extends \humhub\components\Widget
{
const SIZE_XS = 'xs';
const SIZE_SM = 'sm';
const SIZE_LG = 'lg';
const SIZE_2x = '2x';
const SIZE_3x = '3x';
const SIZE_4x = '4x';
const SIZE_5x = '5x';
const SIZE_6x = '6x';
const SIZE_7x = '7x';
const SIZE_8x = '8x';
const SIZE_9x = '9x';
const SIZE_10x = '10x';
/**
* @var array contains all available names which should be supported by the main icon provider
*/
public static $names = [
'adjust',
'adn',
'align-center',
'align-justify',
'align-left',
'align-right',
'ambulance',
'anchor',
'android',
'angellist',
'angle-double-down',
'angle-double-left',
'angle-double-right',
'angle-double-up',
'angle-down',
'angle-left',
'angle-right',
'angle-up',
'apple',
'archive',
'area-chart',
'arrow-circle-down',
'arrow-circle-left',
'arrow-circle-o-down',
'arrow-circle-o-left',
'arrow-circle-o-right',
'arrow-circle-o-up',
'arrow-circle-right',
'arrow-circle-up',
'arrow-down',
'arrow-left',
'arrow-right',
'arrow-up',
'arrows',
'arrows-alt',
'arrows-h',
'arrows-v',
'asterisk',
'at',
'backward',
'ban',
'bank',
'bar-chart',
'bar-chart-o',
'barcode',
'bars',
'bed',
'beer',
'behance',
'behance-square',
'bell',
'bell-o',
'bell-slash',
'bell-slash-o',
'bicycle',
'binoculars',
'birthday-cake',
'bitbucket',
'bitbucket-square',
'bitcoin',
'bold',
'bolt',
'bomb',
'book',
'bookmark',
'bookmark-o',
'briefcase',
'btc',
'bug',
'building',
'building-o',
'bullhorn',
'bullseye',
'bus',
'buysellads',
'cab',
'calculator',
'calendar',
'calendar-o',
'camera',
'camera-retro',
'car',
'caret-down',
'caret-left',
'caret-right',
'caret-square-o-down',
'caret-square-o-left',
'caret-square-o-right',
'caret-square-o-up',
'caret-up',
'cart-arrow-down',
'cart-plus',
'cc',
'cc-amex',
'cc-discover',
'cc-mastercard',
'cc-paypal',
'cc-stripe',
'cc-visa',
'certificate',
'chain',
'chain-broken',
'check',
'check-circle',
'check-circle-o',
'check-square',
'check-square-o',
'chevron-circle-down',
'chevron-circle-left',
'chevron-circle-right',
'chevron-circle-up',
'chevron-down',
'chevron-left',
'chevron-right',
'chevron-up',
'child',
'circle',
'circle-o',
'circle-o-notch',
'circle-thin',
'clipboard',
'clock-o',
'close',
'cloud',
'cloud-download',
'cloud-upload',
'cny',
'code',
'code-fork',
'codepen',
'coffee',
'cog',
'cogs',
'columns',
'comment',
'comment-o',
'comments',
'comments-o',
'compass',
'compress',
'connectdevelop',
'copy',
'copyright',
'credit-card',
'crop',
'crosshairs',
'css3',
'cube',
'cubes',
'cut',
'cutlery',
'dashboard',
'dashcube',
'database',
'dedent',
'delicious',
'desktop',
'deviantart',
'diamond',
'digg',
'dollar',
'dot-circle-o',
'download',
'dribbble',
'dropbox',
'drupal',
'edit',
'eject',
'ellipsis-h',
'ellipsis-v',
'empire',
'envelope',
'envelope-o',
'envelope-square',
'eraser',
'eur',
'euro',
'exchange',
'exclamation',
'exclamation-circle',
'exclamation-triangle',
'expand',
'external-link',
'external-link-square',
'eye',
'eye-slash',
'eyedropper',
'facebook',
'facebook-f',
'facebook-official',
'facebook-square',
'fast-backward',
'fast-forward',
'fax',
'female',
'fighter-jet',
'file',
'file-archive-o',
'file-audio-o',
'file-code-o',
'file-excel-o',
'file-image-o',
'file-movie-o',
'file-o',
'file-pdf-o',
'file-photo-o',
'file-picture-o',
'file-powerpoint-o',
'file-sound-o',
'file-text',
'file-text-o',
'file-video-o',
'file-word-o',
'file-zip-o',
'files-o',
'film',
'filter',
'fire',
'fire-extinguisher',
'flag',
'flag-checkered',
'flag-o',
'flash',
'flask',
'flickr',
'floppy-o',
'folder',
'folder-o',
'folder-open',
'folder-open-o',
'font',
'forumbee',
'forward',
'foursquare',
'frown-o',
'futbol-o',
'gamepad',
'gavel',
'gbp',
'ge',
'gear',
'gears',
'genderless',
'gift',
'git',
'git-square',
'github',
'github-alt',
'github-square',
'gittip',
'glass',
'globe',
'google',
'google-plus',
'google-plus-square',
'google-wallet',
'graduation-cap',
'gratipay',
'group',
'h-square',
'hacker-news',
'hand-o-down',
'hand-o-left',
'hand-o-right',
'hand-o-up',
'hdd-o',
'header',
'headphones',
'heart',
'heart-o',
'heartbeat',
'history',
'home',
'hospital-o',
'hotel',
'html5',
'ils',
'image',
'inbox',
'indent',
'info',
'info-circle',
'inr',
'instagram',
'institution',
'ioxhost',
'italic',
'joomla',
'jpy',
'jsfiddle',
'key',
'keyboard-o',
'krw',
'language',
'laptop',
'lastfm',
'lastfm-square',
'leaf',
'leanpub',
'legal',
'lemon-o',
'level-down',
'level-up',
'life-bouy',
'life-buoy',
'life-ring',
'life-saver',
'lightbulb-o',
'line-chart',
'link',
'linkedin',
'linkedin-square',
'linux',
'list',
'list-alt',
'list-ol',
'list-ul',
'location-arrow',
'lock',
'long-arrow-down',
'long-arrow-left',
'long-arrow-right',
'long-arrow-up',
'magic',
'magnet',
'mail-forward',
'mail-reply',
'mail-reply-all',
'male',
'map-marker',
'mars',
'mars-double',
'mars-stroke',
'mars-stroke-h',
'mars-stroke-v',
'maxcdn',
'meanpath',
'medium',
'medkit',
'meh-o',
'mercury',
'microphone',
'microphone-slash',
'minus',
'minus-circle',
'minus-square',
'minus-square-o',
'mobile',
'mobile-phone',
'money',
'moon-o',
'mortar-board',
'motorcycle',
'music',
'navicon',
'neuter',
'newspaper-o',
'openid',
'outdent',
'pagelines',
'paint-brush',
'paper-plane',
'paper-plane-o',
'paperclip',
'paragraph',
'paste',
'pause',
'paw',
'paypal',
'pencil',
'pencil-square',
'pencil-square-o',
'phone',
'phone-square',
'photo',
'picture-o',
'pie-chart',
'pied-piper',
'pied-piper-alt',
'pinterest',
'pinterest-p',
'pinterest-square',
'plane',
'play',
'play-circle',
'play-circle-o',
'plug',
'plus',
'plus-circle',
'plus-square',
'plus-square-o',
'power-off',
'print',
'puzzle-piece',
'qq',
'qrcode',
'question',
'question-circle',
'quote-left',
'quote-right',
'ra',
'random',
'rebel',
'recycle',
'reddit',
'reddit-square',
'refresh',
'remove',
'renren',
'reorder',
'repeat',
'reply',
'reply-all',
'retweet',
'rmb',
'road',
'rocket',
'rotate-left',
'rotate-right',
'rouble',
'rss',
'rss-square',
'rub',
'ruble',
'rupee',
'save',
'scissors',
'search',
'search-minus',
'search-plus',
'sellsy',
'send',
'send-o',
'server',
'share',
'share-alt',
'share-alt-square',
'share-square',
'share-square-o',
'shekel',
'sheqel',
'shield',
'ship',
'shirtsinbulk',
'shopping-cart',
'sign-in',
'sign-out',
'signal',
'simplybuilt',
'sitemap',
'skyatlas',
'skype',
'slack',
'sliders',
'slideshare',
'smile-o',
'soccer-ball-o',
'sort',
'sort-alpha-asc',
'sort-alpha-desc',
'sort-amount-asc',
'sort-amount-desc',
'sort-asc',
'sort-desc',
'sort-down',
'sort-numeric-asc',
'sort-numeric-desc',
'sort-up',
'soundcloud',
'space-shuttle',
'spinner',
'spoon',
'spotify',
'square',
'square-o',
'stack-exchange',
'stack-overflow',
'star',
'star-half',
'star-half-empty',
'star-half-full',
'star-half-o',
'star-o',
'steam',
'steam-square',
'step-backward',
'step-forward',
'stethoscope',
'stop',
'street-view',
'strikethrough',
'stumbleupon',
'stumbleupon-circle',
'subscript',
'subway',
'suitcase',
'sun-o',
'superscript',
'support',
'table',
'tablet',
'tachometer',
'tag',
'tags',
'tasks',
'taxi',
'tencent-weibo',
'terminal',
'text-height',
'text-width',
'th',
'th-large',
'th-list',
'thumb-tack',
'thumbs-down',
'thumbs-o-down',
'thumbs-o-up',
'thumbs-up',
'ticket',
'times',
'times-circle',
'times-circle-o',
'tint',
'toggle-off',
'toggle-on',
'train',
'transgender',
'transgender-alt',
'trash',
'trash-o',
'tree',
'trello',
'trophy',
'truck',
'try',
'tty',
'tumblr',
'tumblr-square',
'twitch',
'twitter',
'twitter-square',
'umbrella',
'underline',
'undo',
'university',
'unlock',
'unlock-alt',
'upload',
'usd',
'user',
'user-md',
'user-plus',
'user-secret',
'user-times',
'users',
'venus',
'venus-double',
'venus-mars',
'viacoin',
'video-camera',
'vimeo-square',
'vine',
'vk',
'volume-down',
'volume-off',
'volume-up',
'weibo',
'weixin',
'whatsapp',
'wheelchair',
'wifi',
'windows',
'wordpress',
'wrench',
'xing',
'xing-square',
'yahoo',
'yelp',
'youtube',
'youtube-play',
'youtube-square'
];
/**
* @var string icon name
*/
public $name;
/**
* @var int icon size in pixel
*/
public $size;
/**
* @var bool right float
*/
public $right = false;
/**
* @var bool left float
*/
public $left = false;
/**
* @var bool used to vertical alignment of icons;
*/
public $fixedWidth = false;
/**
* @var bool used for icon list items
*/
public $listItem = false;
/**
* @var bool bordered icon
*/
public $border = false;
/**
* Set this to true if the icon is only used for decoration and is not required for navigating your site.
* @var bool used for accessibility, set this to true if the icon is just used as decoration and
*/
public $ariaHidden = false;
/**
* @var array
*/
public $htmlOptions = [];
/**
* @var string css color
*/
public $color;
/**
* @var string explicitly define a icon library, if not defined the default icon provider is used
*/
public $lib;
/**
* Can be used to get an Icon instance from an unknown format.
*
* The following formats are supported:
*
* ```php
* // Will just return the given $instance
* Icon::get($instance);
*
* // Will overwrite the instance configuration and return the given $instane
* Icon::get($instance, $someOptions);
*
*
* // Will create an instance with the given icon name and options
* Icon::get('tasks', $someOptoins);
*
*
* // Will create an instance from the given options array
* Icon::get(['name' => 'tasks', color => 'success']);
* ```
* @param $icon
* @param array $options
* @return Icon|null|object
*/
public static function get($icon, $options = [])
{
if($icon instanceof static) {
return Yii::configure($icon, $options);
} else if(is_string($icon)) {
$options['name'] = $icon;
return new Icon($options);
} else if(is_array($icon)) {
return new Icon($icon);
}
return null;
}
/**
* Returns all supported icon names of a provider-
*
* @param null $providerId
* @return string[]
* @see IconFactory::getNames()
* @throws \yii\base\InvalidConfigException
*/
public static function getNames($providerId = null)
{
return IconFactory::getInstance()->getNames($providerId);
}
/**
* Renders a icon list e.g.:
*
* ```php
* Icon::renderList([
* ['tasks' => 'First list item', 'options' => ['color' => 'success']],
* ['book' => 'First second item', 'options' => ['color' => 'danger']]
* ])
* ```
*
* @param $listDefinition
* @return mixed
* @throws \yii\base\InvalidConfigException
*/
public static function renderList($listDefinition)
{
return IconFactory::getInstance()->renderList($listDefinition);
}
/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
*/
public function run()
{
/**
* Catch for legacy icon usage
*/
$this->name = (strpos($this->name, 'fa-') === 0)
? substr($this->name, 3, strlen($this->name))
: $this->name;
if($this->color) {
switch($this->color) {
case 'default':
$this->color = $this->view->theme->variable('default');
break;
case 'primary':
$this->color = $this->view->theme->variable('primary');
break;
case 'info':
$this->color = $this->view->theme->variable('info');
break;
case 'success':
$this->color = $this->view->theme->variable('success');
break;
case 'warning':
case 'warn':
$this->color = $this->view->theme->variable('warn');
break;
case 'error':
case 'danger':
$this->color = $this->view->theme->variable('danger');
break;
}
}
if($this->id) {
$this->htmlOptions['id'] = $this->id;
}
return IconFactory::getInstance()->render($this);
}
/**
* @param $size string
* @return $this
*/
public function size($size)
{
$this->size = $size;
return $this;
}
/**
* @param bool $active
* @return $this
*/
public function fixedWith($active = true)
{
$this->fixedWidth = $active;
return $this;
}
/**
* @param bool $active
* @return $this
*/
public function listItem($active = true)
{
$this->listItem;
return $this;
}
/**
* @param bool $active
* @return $this
*/
public function right($active = true)
{
if($active) {
$this->left(false);
}
$this->right = $active;
return $this;
}
/**
* @param bool $active
* @return $this
*/
public function left($active = true)
{
if($active) {
$this->right(false);
}
$this->left = $active;
return $this;
}
/**
* @param bool $active
*/
public function ariaHidden($active = true)
{
$this->ariaHidden = $active;
return $this;
}
/**
* @param bool $active
* @return $this
*/
public function border($active = true)
{
$this->border = $active;
return $this;
}
/**
* @param string|array $style
*/
public function style($style)
{
Html::addCssStyle($this->htmlOptions, $style);
return $this;
}
/**
* @param string $color
*/
public function color($color)
{
$this->color = $color;
return $this;
}
/**
* @param $lib
* @return $this
*/
public function lib($lib)
{
$this->lib = $lib;
return $this;
}
/**
* @return [] array representation of this icon
*/
public function asArray()
{
return [
'id' => $this->id,
'name' => $this->name,
'size' => $this->size,
'fixedWidth' => $this->fixedWidth,
'listItem' => $this->listItem,
'right' => $this->right,
'left' => $this->left,
'ariaHidden' => $this->ariaHidden,
'border' => $this->border,
'htmlOptions' => $this->htmlOptions,
'color' => $this->color,
'lib' => $this->lib
];
}
/**
* @return string
* @throws \Exception
*/
public function __toString()
{
$result = $this::widget($this->asArray());
return $result ? $result : '';
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu;
use humhub\modules\ui\menu\widgets\Menu;
use yii\bootstrap\Html;
/**
* Class DropdownDivider
*
* Used for rendering divider within a DropdownMenu.
*
* Usage:
*
* ```php
* $dropdown->addEntry(new DropdownDivider(['sortOrder' => 100]);
* ```
*
* @since 1.4
* @see Menu
*/
class DropdownDivider extends MenuEntry
{
/**
* @inheritdoc
*/
public function renderEntry($extraHtmlOptions = [])
{
Html::addCssClass($extraHtmlOptions, 'divider');
return Html::tag('li', '', $this->getHtmlOptions($extraHtmlOptions));
}
}

View File

@ -0,0 +1,247 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu;
use humhub\modules\ui\menu\widgets\Menu;
use Yii;
use yii\base\BaseObject;
use yii\bootstrap\Html;
/**
* Class MenuEntry
*
* An abstract menu entry class. Subclasses need to extend the [[render()]] function.
*
* @since 1.4
* @see Menu
*/
abstract class MenuEntry extends BaseObject
{
/**
* @var string menu entry identifier (optional)
*/
protected $id;
/**
* @var int the sort order
*/
protected $sortOrder;
/**
* @var array additional html options for the link HTML tag
*/
protected $htmlOptions = [];
/**
* @var bool
*/
protected $isVisible = true;
/**
* @var bool mark this entry as active
*/
protected $isActive = false;
/**
* Renders the entry html, this template function should respect [[htmlOptions]] array by calling [[getHtmlOptions()]] and passing
* the $extraHtmlOptions array as for example:
*
* ```php
*
* return Html::a($label, $url, $this->getHtmlOptions($extraHtmlOptions));
*
* ```
*
* @param array $extraHtmlOptions
* @return string the Html link
*/
abstract protected function renderEntry($extraHtmlOptions = []);
/**
* Public accessible render function responsible for rendering this entry.
*
* @param array $extraHtmlOptions
* @return string
*/
public function render($extraHtmlOptions = []) {
if(!$this->isVisible) {
return '';
}
return $this->renderEntry($extraHtmlOptions);
}
/**
* @return boolean is active
*/
public function getIsActive()
{
if (is_callable($this->isActive)) {
call_user_func($this->isActive);
}
if ($this->isActive) {
return true;
}
return false;
}
/**
* @param $state boolean
* @return static
*/
public function setIsActive($state)
{
$this->isActive = $state;
return $this;
}
/**
* Activates this MenuEntry in case the given moduleId, controllerId and actionId matches the current request.
* @param string $moduleId controller module id
* @param array|string $controllerIds controller id
* @param array|string $actionIds action id
* @return static
*/
public function setIsActiveState($moduleId, $controllerIds = [], $actionIds = [])
{
$this->isActive = static::isActiveState($moduleId,$controllerIds,$actionIds);
return $this;
}
public static function isActiveState($moduleId = null, $controllerIds = [], $actionIds = [])
{
if($moduleId && (!Yii::$app->controller->module || Yii::$app->controller->module->id !== $moduleId)) {
return false;
}
if(empty($controllerIds) && empty($actionIds)) {
return true;
}
if($controllerIds && !is_array($controllerIds)) {
$controllerIds = [$controllerIds];
}
if(!empty($controllerIds) && !in_array(Yii::$app->controller->id, $controllerIds)) {
return false;
}
if($actionIds && !is_array($actionIds)) {
$actionIds = [$actionIds];
}
if(!empty($actionIds) && !in_array(Yii::$app->controller->action->id, $actionIds)) {
return false;
}
return true;
}
/**
* @param $id string the id
* @return static
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return string the id
*/
public function getId()
{
return $this->id;
}
/**
* Compares this entry with the given entry
* @param MenuEntry $entry
* @return bool
*/
public function compare(MenuEntry $entry)
{
return !empty($this->getId()) && $this->getId() === $entry->getId();
}
/**
* Returns the Html options for the menu entry link tag.
*
* @return array
*/
public function getHtmlOptions($extraOptions = [])
{
$options = $this->htmlOptions;
if(isset($extraOptions['class'])) {
Html::addCssClass($options, $extraOptions['class']);
}
if(isset($extraOptions['style'])) {
Html::addCssStyle($options, $extraOptions['style']);
}
if ($this->isActive) {
Html::addCssClass($options, 'active');
}
return array_merge($extraOptions, $options);
}
/**
* @param array $htmlOptions
* @return static
*/
public function setHtmlOptions($htmlOptions)
{
$this->htmlOptions = $htmlOptions;
return $this;
}
/**
* @return bool
*/
public function isVisible()
{
return $this->isVisible;
}
/**
* @param bool $isVisible
* @return static
*/
public function setIsVisible($isVisible)
{
$this->isVisible = $isVisible;
return $this;
}
/**
* @return int
*/
public function getSortOrder()
{
return $this->sortOrder;
}
/**
* @param int $sortOrder
* @return static
*/
public function setSortOrder($sortOrder)
{
$this->sortOrder = $sortOrder;
return $this;
}
}

View File

@ -0,0 +1,275 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu;
use humhub\modules\ui\icon\widgets\Icon;
use humhub\modules\ui\menu\widgets\Menu;
use humhub\libs\Html;
use humhub\widgets\Link;
use Yii;
use yii\helpers\Url;
/**
* Class MenuLink
*
* Used to render menu link entries.
*
* @since 1.4
* @see Menu
*/
class MenuLink extends MenuEntry
{
/**
* @var string the label of the menu entry
*/
protected $label;
/**
* @var string|array the url or route
*/
protected $url;
/**
* @var Icon the icon
*/
protected $icon;
/**
* @var bool use PJAX link if possible
*/
protected $pjaxEnabled = true;
/**
* @var string optional badge (e.g. new item count) not supported by all templates
*/
protected $badgeText;
/**
* @var Link
*/
protected $link;
/**
* Renders the link tag for this menu entry
*
* @param array $extraHtmlOptions
* @return string the Html link
*/
public function renderEntry($extraHtmlOptions = [])
{
if($this->link) {
return $this->link.'';
}
return Html::a(
$this->getIcon() . ' ' . $this->getLabel(),
$this->getUrl(),
$this->getHtmlOptions($extraHtmlOptions)
);
}
public function getHtmlOptions($extraOptions = [])
{
$options = parent::getHtmlOptions($extraOptions);
if(!$this->pjaxEnabled) {
Html::addPjaxPrevention($options);
}
return array_merge($extraOptions, $options);
}
public function compare(MenuEntry $entry)
{
return parent::compare($entry) || ($entry instanceof self && $this->getUrl() === $entry->getUrl());
}
/**
* @param $label string the label
* @return static
*/
public function setLabel($label)
{
$this->label = $label;
return $this;
}
/**
* @return Link
*/
public function getLink()
{
return $this->link;
}
/**
* @param $link Link the label
* @return static
*/
public function setLink(Link $link)
{
$this->link = $link;
return $this;
}
/**
* @return string the label
*/
public function getLabel()
{
return $this->label;
}
/**
* @return Icon the icon
*/
public function getIcon()
{
return $this->icon;
}
/**
* @param $icon Icon|string the icon instance or icon name
* * @return static
*/
public function setIcon($icon)
{
$this->icon = Icon::get($icon);
return $this;
}
/**
* Sets the URL
*
* @param $url array|string
* @return static
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Returns the URL
*
* @param bool $asString return the URL as string
* @return array|string
*/
public function getUrl($asString = true)
{
if ($asString) {
return Url::to($this->url);
}
return $this->url;
}
/**
* @return bool
*/
public function isPjaxEnabled()
{
return $this->pjaxEnabled;
}
/**
* @param bool $pjaxEnabled
* @return static
*/
public function setPjaxEnabled($pjaxEnabled)
{
$this->pjaxEnabled = $pjaxEnabled;
return $this;
}
/**
* @return string
*/
public function getBadgeText()
{
return $this->badgeText;
}
/**
* @param string $badgeText
* @return static
*/
public function setBadgeText($badgeText)
{
$this->badgeText = $badgeText;
return $this;
}
/**
* Creates MenuEntry by old and deprecated array structure
*
* @deprecated since 1.4
* @param $item
* @return MenuLink
*/
public static function createByArray($item)
{
$entry = new static;
if (isset($item['id'])) {
$entry->id = $item['id'];
}
if (isset($item['label'])) {
$entry->label = $item['label'];
}
if (isset($item['icon'])) {
$entry->icon = $item['icon'];
}
if (isset($item['url'])) {
$entry->url = $item['url'];
}
if (isset($item['sortOrder'])) {
$entry->sortOrder = $item['sortOrder'];
}
if (isset($item['isActive'])) {
$entry->isActive = $item['isActive'];
}
if (isset($item['htmlOptions'])) {
$entry->isActive = $item['htmlOptions'];
}
return $entry;
}
/**
* Returns the MenuEntry as array structure
*
* @deprecated since 1.4
* @return array the menu entry array representation
*/
public function toArray()
{
if (!isset($this->htmlOptions['class'])) {
$this->htmlOptions['class'] = '';
}
return [
'label' => $this->label,
'id' => $this->id,
'icon' => $this->icon,
'url' => $this->url,
'sortOrder' => $this->sortOrder,
'isActive' => $this->isActive,
'htmlOptions' => $this->htmlOptions
];
}
}

View File

@ -0,0 +1,24 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu\events;
use humhub\components\Event;
use humhub\modules\directory\widgets\Menu;
/**
* Class MenuEvent
*
* @since 1.4
* @property Menu $sender
* @package humhub\modules\ui\widgets
*/
class MenuEvent extends Event
{
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu\widgets;
/**
* Class DropdownMenu
*
* @since 1.4
* @package humhub\modules\ui\menu\widgets
*/
abstract class DropdownMenu extends Menu
{
/**
* @var string the label of the dropdown button
*/
public $label;
/**
* @inheritdoc
*/
public $template = '@ui/menu/widgets/views/dropdown-menu.php';
/**
* @inheritdoc
*/
public function getAttributes()
{
return [
'class' => 'btn-group dropdown-navigation'
];
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu\widgets;
/**
* Class LeftNavigation
*
* @since 1.4
* @package humhub\modules\ui\menu\widgets
*/
abstract class LeftNavigation extends Menu
{
/**
* @var string the title of the panel
*/
public $panelTitle;
/**
* @inheritdoc
*/
public $template = '@ui/menu/widgets/views/left-navigation.php';
}

View File

@ -0,0 +1,368 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu\widgets;
use humhub\components\Event;
use humhub\libs\Sort;
use humhub\modules\ui\menu\MenuEntry;
use humhub\modules\ui\menu\MenuLink;
use humhub\widgets\JsWidget;
use yii\helpers\Url;
use yii\web\View;
/**
* Base class for menus and navigations.
*
* @since 1.4
* @package humhub\modules\ui\widgets
*/
abstract class Menu extends JsWidget
{
/**
* @inheritdocs
*/
public $jsWidget = 'ui.navigation.Navigation';
/**
* @event MenuEvent an event raised before running the navigation widget.
*/
const EVENT_RUN = 'run';
/**
* @var string template view file of the navigation
*/
public $template;
/**
* @var MenuEntry[] the menu entries
*/
protected $entries = [];
/**
* Add new menu entry to the navigation
*
* @param MenuEntry $entry
*/
public function addEntry(MenuEntry $entry)
{
$this->entries[] = $entry;
}
/**
* Removes the entry from the navigation
*
* @param MenuEntry $entry
* @return boolean
*/
public function removeEntry($entry)
{
foreach ($this->entries as $i => $e) {
if ($e === $entry) {
unset($this->entries[$i]);
return true;
}
}
return false;
}
/**
* Executes the navigation widget.
*
* @return string the result of navigation widget execution to be outputted.
*/
public function run()
{
$this->trigger(static::EVENT_RUN);
if (empty($this->template)) {
return '';
}
return $this->render($this->template, $this->getViewParams());
}
/**
* Returns the parameters which are passed to the view template
*
* @return array the view parameters
*/
protected function getViewParams()
{
return [
'menu' => $this,
'entries' => $this->getSortedEntries(),
'options' => $this->getOptions(),
// Deprecated
'items' => $this->getItems(),
'numItems' => count($this->getItems())
];
}
/**
* Sorts the entry list by sortOrder and returns the sorted entry list.
*
* @return MenuEntry[]
*/
public function getSortedEntries()
{
return Sort::sort($this->entries);
}
/**
* @inheritdoc
*/
public function getData()
{
return [
'menu-id' => $this->id
];
}
/**
* @inheritdoc
*/
public function getAttributes()
{
return [
'class' => 'panel panel-default left-navigation'
];
}
/**
* Returns the first entry with the given URL
*
* @param $url string|array the url or route
* @return MenuLink
*/
public function getEntryByUrl($url)
{
if (is_array($url)) {
$url = Url::to($url);
}
foreach ($this->entries as $entry) {
if(!$entry instanceof MenuLink) {
continue;
}
if ($entry->getUrl() === $url) {
return $entry;
}
}
return null;
}
/**
* Returns the first active menu entry
*
* @return MenuEntry
*/
public function getActiveEntry()
{
foreach ($this->entries as $entry) {
if ($entry->getIsActive()) {
return $entry;
}
}
}
/**
* Sets an menu entry active and inactive all other entries
*
* @param MenuEntry $entry
*/
public function setEntryActive(MenuEntry $entry)
{
foreach ($this->entries as $currentEntry) {
$currentEntry->setIsActive(($currentEntry->compare($entry)));
}
}
/**
* -------------------------------------------------------------------
* Compatibility Layer
* -------------------------------------------------------------------
*/
/**
* @deprecated since 1.4
* @param array $entryArray
*/
public function addItem($entryArray)
{
$entry = MenuLink::createByArray($entryArray);
$this->addEntry($entry);
}
/**
* @deprecated since 1.4 not longer supported!
* @return array item group
*/
public function addItemGroup($itemGroup)
{
//throw new InvalidCallException('Item groups are not longer supported');
}
/**
* @deprecated since 1.4
* @return array the item group
*/
public function getItemGroups()
{
return [
['id' => 'default', 'label' => '', 'icon' => '', 'sortOrder' => 1000]
];
}
/**
* @deprecated since 1.4
* @return array the menu items as array list
*/
public function getItems($group = '')
{
$items = [];
foreach ($this->entries as $entry) {
if($entry instanceof MenuLink) {
$items[] = $entry->toArray();
}
}
return $items;
}
/**
* Returns all entries filtered by $type. If no $type filter is given all entries
* are returned.
*
* If $filterVisible is set, only visible entries will be returned
*
* @param null|string $type
* @param bool $filterVisible
* @return MenuEntry[]
*/
public function getEntries($type = null, $filterVisible = false)
{
$result = [];
foreach ($this->getSortedEntries() as $entry) {
if((!$filterVisible || $entry->isVisible()) && (!$type || get_class($entry) === $type || is_subclass_of($entry, $type))) {
$result[] = $entry;
}
}
return $result;
}
/**
* @param null $type
* @param bool $filterVisible
* @return MenuEntry|null
*/
public function getFirstEntry($type = null, $filterVisible = false)
{
$entries = $this->getEntries($type, $filterVisible);
if(count($entries)) {
return $entries[0];
}
return null;
}
/**
* Checks if this menu contains multiple entries of the given $type, or at all if no $type filter is given.
*
* @param null $type
* @return bool
*/
public function hasMultipleEntries($type = null)
{
return count($this->getEntries($type)) > 1;
}
/**
* @deprecated since 1.4
*/
public function setActive($url)
{
$entry = $this->getEntryByUrl($url);
if ($entry) {
$this->setEntryActive($entry);
}
}
/**
* @deprecated since 1.4
*/
public function setInactive($url)
{
$entry = $this->getEntryByUrl($url);
if ($entry) {
$entry->setIsActive(false);
}
}
/**
* @deprecated since 1.4
*/
public static function markAsActive($url)
{
Event::on(static::class, static::EVENT_RUN, function ($event) use ($url) {
$event->sender->setActive($url);
});
}
/**
* @deprecated since 1.4
*/
public static function markAsInactive($url)
{
Event::on(static::class, static::EVENT_RUN, function ($event) use ($url) {
$event->sender->setInactive($url);
});
}
/**
* @deprecated since 1.4
* @return array the menu entry as array
*/
public function getActive()
{
$activeEntry = $this->getActiveEntry();
if ($activeEntry && $activeEntry instanceof MenuLink) {
return $activeEntry->toArray();
}
return null;
}
/**
* @deprecated since 1.4
* @param $url string the URL or route
*/
public function deleteItemByUrl($url)
{
$entry = $this->getEntryByUrl($url);
if ($entry) {
$this->removeEntry($entry);
}
}
/**
* @deprecated since 1.4
*/
public static function setViewState()
{
$instance = new static();
if (!empty($instance->id)) {
$active = $instance->getActive();
$instance->view->registerJs('humhub.modules.ui.navigation.setActive("' . $instance->id . '", ' . json_encode($active) . ');', View::POS_END, 'active-' . $instance->id);
}
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu\widgets;
/**
* SubTabMenu
*
* @sicne 1.4
* @package humhub\modules\ui\menu\widgets
*/
abstract class SubTabMenu extends TabMenu
{
/**
* @var string the title of the panel
*/
public $panelTitle;
/**
* @inheritdoc
*/
public $template = '@ui/menu/widgets/views/sub-tab-menu.php';
/**
* @inheritdoc
*/
public function getAttributes()
{
return [
'class' => 'nav nav-tabs tab-sub-menu'
];
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\menu\widgets;
use humhub\modules\ui\menu\MenuLink;
/**
* Class TabMenu
*
* @since 1.4
* @package humhub\modules\ui\menu\widgets
*/
abstract class TabMenu extends Menu
{
/**
* @inheritdoc
*/
public $template = '@ui/menu/widgets/views/tab-menu.php';
/**
* @var bool whether or not to skip rendering if only one menu link is given
*/
public $renderSingleTab = false;
public function render($view, $params = [])
{
if(!$this->renderSingleTab && !$this->hasMultipleEntries(MenuLink::class)) {
return '';
}
return parent::render($view, $params);
}
/**
* @inheritdoc
*/
public function getAttributes()
{
return [
'class' => 'tab-menu'
];
}
}

View File

@ -0,0 +1,26 @@
<?php
use humhub\libs\Html;
/* @var $this \humhub\components\View */
/* @var $menu \humhub\modules\ui\menu\widgets\DropdownMenu */
/* @var $entries \humhub\modules\ui\menu\MenuEntry[] */
/* @var $options [] */
?>
<?= Html::beginTag('div', $options)?>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="true">
<?= $menu->label ?>
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right">
<?php foreach ($entries as $entry) : ?>
<li>
<?= $entry->render() ?>
</li>
<?php endforeach; ?>
</ul>
<?= Html::endTag('div')?>

View File

@ -0,0 +1,21 @@
<?php
use humhub\libs\Html;
/* @var $this \humhub\components\View */
/* @var $menu \humhub\modules\ui\menu\widgets\LeftNavigation */
/* @var $entries \humhub\modules\ui\menu\MenuEntry[] */
/* @var $options [] */
?>
<?= Html::beginTag('div', $options) ?>
<?php if (!empty($menu->panelTitle)) : ?>
<div class="panel-heading"><?= $menu->panelTitle; ?></div>
<?php endif; ?>
<div class="list-group">
<?php foreach ($entries as $entry): ?>
<?= $entry->render(['class' => 'list-group-item']) ?>
<?php endforeach; ?>
</div>
<?= Html::endTag('div') ?>

View File

@ -0,0 +1,17 @@
<?php
use humhub\libs\Html;
/* @var $this \humhub\components\View */
/* @var $menu \humhub\modules\ui\menu\widgets\DropdownMenu */
/* @var $entries \humhub\modules\ui\menu\MenuEntry[] */
/* @var $options [] */
?>
<?= Html::beginTag('ul', $options)?>
<?php foreach ($entries as $entry): ?>
<li <?php if ($entry->getIsActive()): ?>class="active"<?php endif; ?>>
<?= $entry->render() ?>
</li>
<?php endforeach; ?>
<?= Html::endTag('ul')?>

View File

@ -0,0 +1,19 @@
<?php
use humhub\libs\Html;
/* @var $this \humhub\components\View */
/* @var $menu \humhub\modules\ui\menu\widgets\DropdownMenu */
/* @var $entries \humhub\modules\ui\menu\MenuEntry[] */
/* @var $options [] */
?>
<?= Html::beginTag('div', $options)?>
<ul class="nav nav-tabs">
<?php foreach ($entries as $entry): ?>
<li <?php if ($entry->getIsActive()): ?>class="active"<?php endif; ?>>
<?= $entry->render() ?>
</li>
<?php endforeach; ?>
</ul>
<?= Html::endTag('div')?>

View File

@ -1,55 +0,0 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\ui\widgets;
use humhub\components\Widget;
/**
* Class Icon
*
* Wrapper class for icon handling.
* Currently this class only supports FontAwesome 4.7 icons
*
* @since 1.4
* @package humhub\modules\ui\widgets
*/
class Icon extends Widget
{
/**
* @var string the name/id of the icon
*/
public $name;
/**
* @return string returns the Html tag for the current icon
*/
public function renderHtml()
{
return '<i class="fa fa-' . $this->name . '"></i>';
}
/**
* @inheritdoc
*/
public function run()
{
return $this->renderHtml();
}
/**
* @return string returns the Html tag for this icon
*/
public function __toString()
{
return $this->renderHtml();
}
}

View File

@ -9,8 +9,8 @@
namespace humhub\modules\user\widgets;
use Yii;
use \humhub\widgets\BaseMenu;
use \yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\LeftNavigation;
/**
* AccountMenuWidget as (usally left) navigation on users account options.
@ -19,82 +19,66 @@ use \yii\helpers\Url;
* @since 0.5
* @author Luke
*/
class AccountMenu extends BaseMenu
class AccountMenu extends LeftNavigation
{
public $template = "@humhub/widgets/views/leftNavigation";
public $type = "accountNavigation";
/**
* @inheritdoc
*/
public function init()
{
$this->panelTitle = Yii::t('UserModule.widgets_AccountMenuWidget', '<strong>Account</strong> settings');
$controllerAction = Yii::$app->controller->action->id;
$this->addItemGroup([
'id' => 'account',
'label' => Yii::t('UserModule.widgets_AccountMenuWidget', '<strong>Account</strong> settings'),
'sortOrder' => 100,
]);
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.widgets_AccountMenuWidget', 'Profile'),
'icon' => '<i class="fa fa-user"></i>',
'group' => 'account',
'url' => Url::toRoute('/user/account/edit'),
'icon' => 'user',
'url' => ['/user/account/edit'],
'sortOrder' => 100,
'isActive' => ($controllerAction == "edit" || $controllerAction == "change-email" || $controllerAction == "change-password" || $controllerAction == "delete"),
]);
'isActive' => MenuLink::isActiveState('user', 'account', ['edit', 'change-email', 'change-password', 'delete'])
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.account', 'E-Mail Summaries'),
'icon' => '<i class="fa fa-envelope"></i>',
'group' => 'account',
'url' => Url::toRoute('/activity/user'),
'icon' => 'envelope',
'url' => ['/activity/user'],
'sortOrder' => 105,
'isActive' => (Yii::$app->controller->module->id == 'activity'),
]);
'isActive' => MenuLink::isActiveState('activity')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.account', 'Notifications'),
'icon' => '<i class="fa fa-bell"></i>',
'group' => 'account',
'url' => Url::toRoute('/notification/user'),
'icon' => 'bell',
'url' => ['/notification/user'],
'sortOrder' => 106,
'isActive' => (Yii::$app->controller->module->id == 'notification'),
]);
'isActive' => MenuLink::isActiveState('notification')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.widgets_AccountMenuWidget', 'Settings'),
'icon' => '<i class="fa fa-wrench"></i>',
'group' => 'account',
'url' => Url::toRoute('/user/account/edit-settings'),
'icon' => 'wrench',
'url' => ['/user/account/edit-settings'],
'sortOrder' => 110,
'isActive' => ($controllerAction == "edit-settings"),
]);
'isActive' => MenuLink::isActiveState('user', 'account', 'edit-settings')
]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.widgets_AccountMenuWidget', 'Security'),
'icon' => '<i class="fa fa-lock"></i>',
'group' => 'account',
'url' => Url::toRoute('/user/account/security'),
'icon' => 'lock',
'url' => ['/user/account/security'],
'sortOrder' => 115,
'isActive' => (Yii::$app->controller->action->id == "security"),
]);
'isActive' => MenuLink::isActiveState('user', 'account', 'security')
]));
// Only show this page when really user specific modules available
if (count(Yii::$app->user->getIdentity()->getAvailableModules()) != 0) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.widgets_AccountMenuWidget', 'Modules'),
'icon' => '<i class="fa fa-rocket"></i>',
'group' => 'account',
'url' => Url::toRoute('//user/account/edit-modules'),
'icon' => 'rocket',
'url' => ['/user/account/edit-modules'],
'sortOrder' => 120,
'isActive' => (Yii::$app->controller->action->id == "edit-modules"),
]);
}
'isActive' => MenuLink::isActiveState('user', 'account', 'edit-modules'),
'isVisible' => (count(Yii::$app->user->getIdentity()->getAvailableModules()) !== 0)
]));
parent::init();
}
}
?>

View File

@ -9,30 +9,26 @@
namespace humhub\modules\user\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
/**
* Account Settings Tab Menu
*/
class AccountProfilMenu extends \humhub\widgets\BaseMenu
class AccountProfilMenu extends TabMenu
{
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/tabMenu";
/**
* @inheritdoc
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.base', 'General'),
'url' => Url::toRoute(['/user/account/edit']),
'url' => ['/user/account/edit'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'user' && Yii::$app->controller->id == 'account' && Yii::$app->controller->action->id == 'edit'),
]);
'isActive' => MenuLink::isActiveState('user', 'account', 'edit')
]));
if (Yii::$app->user->canChangeUsername()) {
$this->addItem([
@ -51,24 +47,29 @@ class AccountProfilMenu extends \humhub\widgets\BaseMenu
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'user' && Yii::$app->controller->id == 'account' && (Yii::$app->controller->action->id == 'change-email' || Yii::$app->controller->action->id == 'change-email-validate')),
]);
}
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.base', 'Change Email'),
'url' => ['/user/account/change-email'],
'sortOrder' => 200,
'isActive' => MenuLink::isActiveState('user', 'account', ['change-email', 'change-email-validate']),
'isVisible' => Yii::$app->user->canChangeEmail()
]));
if (Yii::$app->user->canChangePassword()) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.base', 'Change Password'),
'url' => Url::toRoute(['/user/account/change-password']),
'url' => ['/user/account/change-password'],
'sortOrder' => 400,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'user' && Yii::$app->controller->id == 'account' && Yii::$app->controller->action->id == 'change-password'),
]);
}
'isActive' => MenuLink::isActiveState('user', 'account', 'change-password'),
'isVisible' => Yii::$app->user->canChangePassword()
]));
if (Yii::$app->user->canDeleteAccount()) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.base', 'Delete Account'),
'url' => Url::toRoute(['/user/account/delete']),
'url' => ['/user/account/delete'],
'sortOrder' => 500,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'user' && Yii::$app->controller->id == 'account' && Yii::$app->controller->action->id == 'delete'),
]);
}
'isActive' => MenuLink::isActiveState('user', 'account', 'delete'),
'isVisible' => Yii::$app->user->canDeleteAccount()
]));
parent::init();
}
@ -77,6 +78,7 @@ class AccountProfilMenu extends \humhub\widgets\BaseMenu
* Returns optional authclients
*
* @return \yii\authclient\ClientInterface[]
* @throws \yii\base\InvalidConfigException
*/
protected function getSecondoaryAuthProviders()
{

View File

@ -9,40 +9,37 @@
namespace humhub\modules\user\widgets;
use Yii;
use yii\helpers\Url;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\TabMenu;
/**
* Account Settings Tab Menu
*/
class AccountSettingsMenu extends \humhub\widgets\BaseMenu
class AccountSettingsMenu extends TabMenu
{
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/tabMenu";
/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.base', 'Basic Settings'),
'url' => Url::toRoute(['/user/account/edit-settings']),
'url' => ['/user/account/edit-settings'],
'sortOrder' => 100,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'user' && Yii::$app->controller->id == 'account' && Yii::$app->controller->action->id == 'edit-settings'),
]);
'isActive' => MenuLink::isActiveState('user', 'account', 'edit-settings')
]));
if (count($this->getSecondaryAuthProviders()) != 0) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.base', 'Connected Accounts'),
'url' => Url::toRoute(['/user/account/connected-accounts']),
'url' => ['/user/account/connected-accounts'],
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'user' && Yii::$app->controller->id == 'account' && Yii::$app->controller->action->id == 'connected-accounts'),
]);
}
'isActive' => MenuLink::isActiveState('user', 'account', 'connected-accounts'),
'isVisible' => count($this->getSecondaryAuthProviders()) !== 0
]));
parent::init();
}
@ -51,6 +48,7 @@ class AccountSettingsMenu extends \humhub\widgets\BaseMenu
* Returns optional authclients
*
* @return \yii\authclient\ClientInterface[]
* @throws \yii\base\InvalidConfigException
*/
protected function getSecondaryAuthProviders()
{

View File

@ -8,17 +8,21 @@
namespace humhub\modules\user\widgets;
use humhub\modules\ui\menu\DropdownDivider;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\Menu;
use Yii;
use yii\helpers\Url;
use humhub\widgets\BaseMenu;
use humhub\modules\admin\widgets\AdminMenu;
/**
* AccountTopMenu Widget
*
* @author luke
*/
class AccountTopMenu extends BaseMenu
class AccountTopMenu extends Menu
{
public $id = 'account-top-menu';
/**
* @var boolean show user name
@ -40,50 +44,54 @@ class AccountTopMenu extends BaseMenu
}
$user = Yii::$app->user->getIdentity();
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('base', 'My profile'),
'icon' => '<i class="fa fa-user"></i>',
'icon' => 'user',
'url' => $user->createUrl('/user/profile/home'),
'sortOrder' => 100,
]);
$this->addItem([
'sortOrder' => 100]));
$this->addEntry(new MenuLink([
'label' => Yii::t('base', 'Account settings'),
'icon' => '<i class="fa fa-edit"></i>',
'icon' => 'edit',
'url' => Url::toRoute('/user/account/edit'),
'sortOrder' => 200,
]);
]));
if (\humhub\modules\admin\widgets\AdminMenu::canAccess()) {
$this->addItem([
'label' => '---',
'url' => '#',
'sortOrder' => 300,
]);
if (AdminMenu::canAccess()) {
$this->addEntry(new DropdownDivider(['sortOrder' => 300]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('base', 'Administration'),
'icon' => '<i class="fa fa-cogs"></i>',
'icon' => 'cogs',
'url' => Url::toRoute('/admin'),
'sortOrder' => 400,
]);
]));
}
$this->addItem([
'label' => '---',
'url' => '#',
'sortOrder' => 600,
]);
$this->addEntry(new DropdownDivider(['sortOrder' => 600]));
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('base', 'Logout'),
'id' => 'account-logout',
'icon' => '<i class="fa fa-sign-out"></i>',
'pjax' => false,
'icon' => 'sign-out',
'pjaxEnabled' => false,
'url' => Url::toRoute('/user/auth/logout'),
'sortOrder' => 700,
]);
]));
parent::init();
}
/**
* @inheritdoc
*/
public function getAttributes()
{
return [
'class' => 'nav'
];
}
}

View File

@ -9,6 +9,8 @@
namespace humhub\modules\user\widgets;
use Yii;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\ui\menu\widgets\LeftNavigation;
use humhub\modules\user\models\User;
use humhub\modules\user\permissions\ViewAboutPage;
@ -24,7 +26,7 @@ use humhub\modules\user\permissions\ViewAboutPage;
* @since 0.5
* @author Luke
*/
class ProfileMenu extends \humhub\widgets\BaseMenu
class ProfileMenu extends LeftNavigation
{
/**
@ -32,39 +34,33 @@ class ProfileMenu extends \humhub\widgets\BaseMenu
*/
public $user;
/**
* @inheritdoc
*/
public $template = "@humhub/widgets/views/leftNavigation";
/**
* @inheritdoc
*/
public function init()
{
$this->addItemGroup([
'id' => 'profile',
'label' => Yii::t('UserModule.widgets_ProfileMenuWidget', '<strong>Profile</strong> menu'),
'sortOrder' => 100,
]);
$this->addItem([
$this->panelTitle = Yii::t('UserModule.widgets_ProfileMenuWidget', '<strong>Profile</strong> menu');
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.widgets_ProfileMenuWidget', 'Stream'),
'icon' => '<i class="fa fa-bars"></i>',
'icon' => 'bars',
'url' => $this->user->createUrl('//user/profile/home'),
'sortOrder' => 200,
'isActive' => (Yii::$app->controller->id == "profile" && (Yii::$app->controller->action->id == "index" || Yii::$app->controller->action->id == "home")),
]);
'isActive' => MenuLink::isActiveState('user', 'profile', ['index', 'home'])
]));
if ($this->user->permissionManager->can(new ViewAboutPage())) {
$this->addItem([
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.widgets_ProfileMenuWidget', 'About'),
'icon' => '<i class="fa fa-info-circle"></i>',
'url' => $this->user->createUrl('//user/profile/about'),
'icon' => 'info-circle>',
'url' => $this->user->createUrl('/user/profile/about'),
'sortOrder' => 300,
'isActive' => (Yii::$app->controller->id == "profile" && Yii::$app->controller->action->id == "about"),
]);
}
'isActive' => MenuLink::isActiveState('user', 'profile', 'about'),
'isVisible' => $this->user->permissionManager->can(ViewAboutPage::class)
]));
parent::init();
}
@ -74,7 +70,7 @@ class ProfileMenu extends \humhub\widgets\BaseMenu
public function run()
{
if (Yii::$app->user->isGuest && $this->user->visibility != User::VISIBILITY_ALL) {
return;
return '';
}
return parent::run();

View File

@ -9,6 +9,12 @@
use humhub\widgets\FooterMenu;
use \yii\helpers\Html;
use \yii\helpers\Url;
use humhub\modules\user\widgets\Image;
/* @var $this \humhub\components\View */
/* @var $menu \humhub\modules\ui\menu\widgets\DropdownMenu */
/* @var $entries \humhub\modules\ui\menu\MenuEntry[] */
/* @var $options [] */
/** @var \humhub\modules\user\models\User $userModel */
$userModel = Yii::$app->user->getIdentity();
@ -22,7 +28,7 @@ $userModel = Yii::$app->user->getIdentity();
<?php endif; ?>
</a>
<?php else: ?>
<ul class="nav">
<?= Html::beginTag('ul', $options) ?>
<li class="dropdown account">
<a href="#" id="account-dropdown-link" class="dropdown-toggle" data-toggle="dropdown" aria-label="<?= Yii::t('base', 'Profile dropdown') ?>">
@ -32,27 +38,25 @@ $userModel = Yii::$app->user->getIdentity();
</div>
<?php endif; ?>
<img id="user-account-image" class="img-rounded"
src="<?= $userModel->getProfileImage()->getUrl(); ?>"
height="32" width="32" alt="<?= Yii::t('base', 'My profile image') ?>" data-src="holder.js/32x32"
style="width: 32px; height: 32px;"/>
<?= Image::widget([
'user' => $userModel,
'link' => false,
'width' => 32,
'htmlOptions' => [
'id' => 'user-account-image',
'alt' => Yii::t('base', 'My profile image')
]])?>
<b class="caret"></b>
</a>
<ul class="dropdown-menu pull-right">
<?php foreach ($this->context->getItems() as $item): ?>
<?php if ($item['label'] == '---'): ?>
<li class="divider"></li>
<?php else: ?>
<?php foreach ($entries as $entry): ?>
<li>
<a <?= isset($item['id']) ? 'id="' . $item['id'] . '"' : '' ?> href="<?= $item['url']; ?>" <?= isset($item['pjax']) && $item['pjax'] === false ? 'data-pjax-prevent' : '' ?>>
<?= $item['icon'] . ' ' . $item['label']; ?>
</a>
<?= $entry->render() ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
<?= FooterMenu::widget(['location' => FooterMenu::LOCATION_ACCOUNT_MENU]); ?>
</ul>
</li>
</ul>
<?= Html::endTag('ul') ?>
<?php endif; ?>

View File

@ -8,352 +8,16 @@
namespace humhub\widgets;
use Yii;
use yii\base\Widget;
use yii\helpers\Url;
use yii\base\Event;
use yii\web\View;
use humhub\modules\ui\menu\widgets\Menu;
/**
* BaseMenu is the base class for navigations.
*
* @deprecated since 1.4
* @see Menu
*/
class BaseMenu extends Widget
class BaseMenu extends Menu
{
const EVENT_INIT = 'init';
const EVENT_RUN = 'run';
/**
*
* @var array of items
*/
public $items = [];
/**
*
* @var array of item groups
*/
public $itemGroups = [];
/**
*
* @var string type of the navigation, optional for identifing.
*/
public $type = '';
/**
* @var string dom element id
* @since 1.2
*/
public $id;
/**
* Template of the navigation
*
* Available default template views:
* - leftNavigation
* - tabMenu
*
* @var string template file
*/
public $template;
/**
* Initializes the navigation widget.
* This method mainly normalizes the {@link items} property.
* If this method is overridden, make sure the parent implementation is invoked.
*/
public function init()
{
$this->addItemGroup([
'id' => '',
'label' => ''
]);
// Yii 2.0.11 introduced own init event
if (version_compare(Yii::getVersion(), '2.0.11', '<')) {
$this->trigger(self::EVENT_INIT);
}
return parent::init();
}
/**
* Adds new Item to the menu
*
* @param array $item
* with item definitions
*/
public function addItem($item)
{
if (!isset($item['label'])) {
$item['label'] = 'Unnamed';
}
if (!isset($item['url'])) {
$item['url'] = '#';
}
if (!isset($item['icon'])) {
$item['icon'] = '';
}
if (!isset($item['group'])) {
$item['group'] = '';
}
if (!isset($item['htmlOptions'])) {
$item['htmlOptions'] = [];
}
if (!isset($item['pjax'])) {
$item['pjax'] = true;
}
/**
*
* @deprecated since version 0.11 use directly htmlOptions instead
*/
if (isset($item['target'])) {
$item['htmlOptions']['target'] = $item['target'];
}
if (!isset($item['sortOrder'])) {
$item['sortOrder'] = 1000;
}
if (!isset($item['newItemCount'])) {
$item['newItemCount'] = 0;
}
if (!isset($item['isActive'])) {
$item['isActive'] = false;
}
if (isset($item['isVisible']) && !$item['isVisible']) {
return;
}
// Build Item CSS Class
if (!isset($item['htmlOptions']['class'])) {
$item['htmlOptions']['class'] = '';
}
if ($item['isActive']) {
$item['htmlOptions']['class'] .= ' active';
}
if (isset($item['id'])) {
$item['htmlOptions']['class'] .= ' ' . $item['id'];
}
$this->items[] = $item;
}
/**
* Adds new Item Group to the menu
*
* @param array $itemGroup
* with group definition
*/
public function addItemGroup($itemGroup)
{
if (!isset($itemGroup['id'])) {
$itemGroup['id'] = 'default';
}
if (!isset($itemGroup['label'])) {
$itemGroup['label'] = 'Unnamed';
}
if (!isset($itemGroup['icon'])) {
$itemGroup['icon'] = '';
}
if (!isset($itemGroup['sortOrder'])) {
$itemGroup['sortOrder'] = 1000;
}
if (isset($itemGroup['isVisible']) && !$itemGroup['isVisible']) {
return;
}
$this->itemGroups[] = $itemGroup;
}
/**
* Returns Items of this Navigation
*
* @param string $group
* limits the items to a specified group
* @return array a list of items with definition
*/
public function getItems($group = '')
{
$this->sortItems();
$ret = [];
foreach ($this->items as $item) {
if ($group == $item['group'])
$ret[] = $item;
}
return $ret;
}
/**
* Sorts the item attribute by sortOrder
*/
private function sortItems()
{
usort($this->items, function ($a, $b) {
if ($a['sortOrder'] == $b['sortOrder']) {
return 0;
} elseif ($a['sortOrder'] < $b['sortOrder']) {
return - 1;
} else {
return 1;
}
});
}
/**
* Sorts Item Groups by sortOrder Field
*/
private function sortItemGroups()
{
usort($this->itemGroups, function ($a, $b) {
if ($a['sortOrder'] == $b['sortOrder']) {
return 0;
} elseif ($a['sortOrder'] < $b['sortOrder']) {
return - 1;
} else {
return 1;
}
});
}
/**
* Returns all Item Groups
*
* @return array of item group definitions
*/
public function getItemGroups()
{
$this->sortItemGroups();
return $this->itemGroups;
}
/**
* Executes the Menu Widget
*/
public function run()
{
$this->trigger(self::EVENT_RUN);
if (empty($this->template)) {
return;
}
return $this->render($this->template, []);
}
/**
* Activates the menu item with the given url
* @param type $url
*/
public function setActive($url)
{
foreach ($this->items as $key => $item) {
if ($item['url'] == $url) {
$this->items[$key]['htmlOptions']['class'] = 'active';
$this->items[$key]['isActive'] = true;
$this->view->registerJs('humhub.modules.ui.navigation.setActive("' . $this->id . '", ' . json_encode($this->items[$key]) . ');', View::POS_END, 'active-' . $this->id);
}
}
}
public function getActive()
{
foreach ($this->items as $item) {
if ($item['isActive']) {
return $item;
}
}
}
/*
* Deactivates the menu item with the given url
*/
public function setInactive($url)
{
foreach ($this->items as $key => $item) {
if ($item['url'] == $url) {
$this->items[$key]['htmlOptions']['class'] = '';
$this->items[$key]['isActive'] = false;
}
}
}
/**
* Add the active class from a menue item.
*
* @param string $url
* the URL of the item to mark. You can use Url::toRoute(...) to generate it.
*/
public static function markAsActive($url)
{
if (is_array($url)) {
$url = Url::to($url);
}
Event::on(static::className(), static::EVENT_RUN, function ($event) use ($url) {
$event->sender->setActive($url);
});
}
/**
* This function is used in combination with pjax to get sure the required menu is active
*/
public static function setViewState()
{
$instance = new static();
if (!empty($instance->id)) {
$active = $instance->getActive();
$instance->view->registerJs('humhub.modules.ui.navigation.setActive("' . $instance->id . '", ' . json_encode($active) . ');', \yii\web\View::POS_END, 'active-' . $instance->id);
}
}
/**
* Remove the active class from a menue item.
*
* @param string $url
* the URL of the item to mark. You can use Url::toRoute(...) to generate it.
*/
public static function markAsInactive($url)
{
if (is_array($url)) {
$url = Url::to($url);
}
Event::on(static::className(), static::EVENT_RUN, function ($event) use ($url) {
$event->sender->setInactive($url);
});
}
/**
* Removes Item by URL
*
* @param string $url
*/
public function deleteItemByUrl($url)
{
foreach ($this->items as $key => $item) {
if ($item['url'] == $url) {
unset($this->items[$key]);
}
}
}
}

View File

@ -8,13 +8,15 @@
namespace humhub\widgets;
use humhub\modules\ui\menu\widgets\Menu;
/**
* FooterMenu displays a footer navigation for pages e.g. Imprint
*
* @since 1.2.6
* @author Luke
*/
class FooterMenu extends BaseMenu
class FooterMenu extends Menu
{
const LOCATION_ACCOUNT_MENU = 'account_menu';
const LOCATION_LOGIN = 'login';
@ -22,7 +24,6 @@ class FooterMenu extends BaseMenu
const LOCATION_FULL_PAGE = 'full';
const LOCATION_EMAIL = 'mail';
/**
* @var string location of footer menu (e.g. login, mail, sidebar)
*/
@ -59,14 +60,11 @@ class FooterMenu extends BaseMenu
/**
* @inheritdoc
*/
public function run()
protected function getViewParams()
{
$this->trigger(self::EVENT_RUN);
return $this->render($this->template, [
'items' => $this->getItems(),
'location' => $this->location,
'numItems' => count($this->getItems())
]);
$params = parent::getViewParams();
$params['location'] = $this->location;
return $params;
}
}

View File

@ -9,6 +9,7 @@
namespace humhub\widgets;
use Yii;
use humhub\modules\ui\menu\widgets\Menu;
use humhub\modules\user\components\User;
/**
@ -17,18 +18,19 @@ use humhub\modules\user\components\User;
* @since 0.5
* @author Luke
*/
class TopMenu extends BaseMenu
class TopMenu extends Menu
{
/**
* @inheritdoc
*/
public $id = 'top-menu-nav';
/**
* @inheritdoc
*/
public $template = 'topNavigation';
/**
* @inheritdoc
*/
public $id = 'top-menu-nav';
/**
* @inheritdoc
@ -43,4 +45,6 @@ class TopMenu extends BaseMenu
}
}
}

View File

@ -1,32 +0,0 @@
<?php
/**
* Left Navigation by MenuWidget.
*
* @package humhub.widgets
* @since 0.5
*/
?>
<?php foreach ($this->context->getItemGroups() as $group) : ?>
<?php $items = $this->context->getItems($group['id']); ?>
<?php if (count($items) == 0) continue; ?>
<div class="btn-group dropdown-navigation">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="true">
<?php if ($group['label'] != "") {
echo $group['label'];
} ?>
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right">
<?php foreach ($items as $item) : ?>
<li>
<?php echo \yii\helpers\Html::a($item['icon'] . " <span>" . $item['label'] . "</span>", $item['url'], $item['htmlOptions']); ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>

View File

@ -1,29 +0,0 @@
<?php
/**
* Left Navigation by MenuWidget.
*
* @package humhub.widgets
* @since 0.5
*/
?>
<!-- start: list-group navi for large devices -->
<div id="<?= $this->context->id; ?>" class="panel panel-default left-navigation">
<?php foreach ($this->context->getItemGroups() as $group) : ?>
<?php $items = $this->context->getItems($group['id']); ?>
<?php if (count($items) == 0) continue; ?>
<?php if ($group['label'] != "") : ?>
<div class="panel-heading"><?php echo $group['label']; ?></div>
<?php endif; ?>
<div class="list-group">
<?php foreach ($items as $item) : ?>
<?php $item['htmlOptions']['class'] .= " list-group-item"; ?>
<?php echo \yii\helpers\Html::a($item['icon'] . "<span>" . $item['label'] . "</span>", $item['url'], $item['htmlOptions']); ?>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
<!-- end: list-group navi for large devices -->

View File

@ -1,16 +0,0 @@
<?php
/**
* Tab Navigation by MenuWidget.
*
* @package humhub.widgets
* @since 0.5 */
use \yii\helpers\Html;
?>
<ul id="tabs" class="nav nav-tabs tab-sub-menu">
<?php foreach ($this->context->getItems() as $item) {?>
<li <?php echo Html::renderTagAttributes($item['htmlOptions'])?>>
<?php echo Html::a($item['label'], $item['url']); ?>
</li>
<?php }; ?>
</ul>

View File

@ -1,19 +0,0 @@
<?php
/**
* Tab Navigation by MenuWidget.
*
* @package humhub.widgets
* @since 0.5 */
use \yii\helpers\Html;
?>
<div class="tab-menu">
<ul class="nav nav-tabs">
<?php foreach ($this->context->getItems() as $item) {?>
<li <?php echo Html::renderTagAttributes($item['htmlOptions'])?>>
<?php echo Html::a($item['label'], $item['url']); ?>
</li>
<?php }; ?>
</ul>
</div>

View File

@ -2,29 +2,28 @@
use yii\helpers\Html;
/* @var $this \humhub\components\View */
/* @var $menu \humhub\widgets\TopMenu */
/* @var $entries \humhub\modules\ui\menu\MenuEntry[] */
?>
<?php foreach ($this->context->getItems() as $item) : ?>
<li class="visible-md visible-lg <?php if ($item['isActive']): ?>active<?php endif; ?> <?php
if (isset($item['id'])) {
echo $item['id'];
}
?>">
<?php echo Html::a($item['icon'] . "<br />" . $item['label'], $item['url'], $item['htmlOptions']); ?>
<?php foreach ($entries as $entry) : ?>
<li class="visible-md visible-lg <?php if ($entry->getIsActive()): ?>active<?php endif; ?>">
<?= Html::a($entry->getIcon() . '<br />' . $entry->getLabel(), $entry->getUrl(), $entry->getHtmlOptions()); ?>
</li>
<?php endforeach; ?>
<li class="dropdown visible-xs visible-sm">
<a href="#" id="top-dropdown-menu" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-align-justify"></i><br>
<?php echo Yii::t('base', 'Menu'); ?>
<b class="caret"></b></a>
<?= Yii::t('base', 'Menu'); ?>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<?php foreach ($this->context->getItems() as $item) : ?>
<li class="<?php if ($item['isActive']): ?>active<?php endif; ?>">
<?php echo Html::a($item['label'], $item['url'], $item['htmlOptions']); ?>
<?php foreach ($entries as $entry) : ?>
<li class="<?php if ($entry->getIsActive()): ?>active<?php endif; ?>">
<?= $entry->render(); ?>
</li>
<?php endforeach; ?>
</ul>
</li>

View File

@ -1,6 +1,9 @@
humhub.module('ui.navigation', function (module, require, $) {
var event = require('event');
var Widget = require('ui.widget').Widget;
var Navigation = Widget.extend();
var init = function () {
module.initTopNav();
@ -54,6 +57,7 @@ humhub.module('ui.navigation', function (module, require, $) {
init: init,
setActive: setActive,
initTopNav: initTopNav,
setActiveItem: setActiveItem
setActiveItem: setActiveItem,
Navigation: Navigation
});
});

View File

@ -189,6 +189,11 @@
@import "mobile.less";
}
@prev-icon: false;
& when not(@prev-icon) {
@import "icon.less";
}
@import "../css/select2Theme/build.less";
// LEGACY/DEPRECATED User- & Space picker

41
static/less/icon.less Normal file
View File

@ -0,0 +1,41 @@
.icon-sm, .fa-sm {
font-size: .875em;
}
.icon-lg, .fa-lg {
font-size: 1.33333em;
line-height: .75em;
vertical-align: -.0667em;
}
.icon-2x, .fa-2x {
font-size: 2em;
}
.icon-3x, .fa-3x {
font-size: 3em;
}
.icon-4x, .fa-4x {
font-size: 4em;
}
.icon-5x, .fa-5x {
font-size: 5em;
}
.icon-6x, .fa-6x {
font-size: 6em;
}
.icon-7x, .fa-7x {
font-size: 7em;
}
.icon-9x, .fa-9x {
font-size: 9em;
}
.icon-10x, .fa-10x {
font-size: 10em;
}

File diff suppressed because one or more lines are too long