Author SHA1 Message Date
Michal Kváček 8098288139 FIX: fix path to admin routes 2018-09-20 00:14:53 +02:00
Michal Kváček cf90d1b91e FEATURE: make nested margin on subpages 2018-04-11 23:04:16 +02:00
Michal Kváček 8acfcabb3c FEATURE: add infinite content pages depth into overview 2018-04-11 22:48:00 +02:00
Michal Kváček b91b80debb FEATURE: allow infinite subpages depth 2018-04-11 22:36:25 +02:00
Michal Kváček ae29c49acf Merge branch 'master' of binarity.cz:/opt/git/internal/cms/minicms 2018-03-25 11:23:38 +02:00
Michal Kváček 7e4507e9e4 FEATURE: add template to menu widget 2018-03-25 11:23:12 +02:00
Peter Hrdlica f0bb159efb Merge branch 'master' of binarity.cz:/opt/git/internal/cms/minicms 2017-10-15 15:54:57 +02:00
Peter Hrdlica ddae98d233 multiselect component 2017-10-15 15:54:21 +02:00
Michal Kváček b1ca6e4cfb FEATURE: allow multiple ckEditor instances 2017-10-09 00:14:48 +02:00
Michal Kváček c69bd9bcf7 FEATURE: add bootstrap datepicker. All elements with .date class are now datepicker holders 2017-09-25 23:22:25 +02:00
Michal Kváček 271e7f5170 FIX: fix insanely low file previews 2017-09-25 15:29:54 +02:00
Michal Kváček 1ecef555ef FIX: fix minor bug in content overview and module installation 2017-09-25 14:37:30 +02:00
Michal Kváček 4ef5e3e3cd FEATURE: make top menu extendable 2017-09-25 11:20:57 +02:00
Michal Kváček 1388383bb6 FEATURE: update Font Awesome and add bottom border and margin to submenus in admin 2017-09-24 16:44:36 +02:00
Michal Kváček f1ff45cfb1 FIX: do not fire error when module service provider is not found. Log it and let it go 2017-09-24 13:57:03 +02:00
Michal Kváček 6d723f026d FIX: remove template service provider from core repository 2017-09-23 00:52:35 +02:00
Michal Kváček b99f70c269 FEATURE: move profiler into own repository 2017-09-23 00:51:24 +02:00
Michal Kváček 680edb14c1 Merge branch 'dev' into module_profiler 2017-09-23 00:45:51 +02:00
Michal Kváček ced920505a FIX #2556: fix user edit 2017-09-22 21:32:47 +02:00
Michal Kváček a1c4a19a59 FEATURE: add cache into public/.htaccess 2017-09-22 21:25:14 +02:00
Michal Kváček 62f73c51e6 FEATURE: add input for setting preview size and quality 2017-09-19 14:18:15 +02:00
Michal Kváček ba55702585 FEATURE: make own page for template overview 2017-09-15 13:32:09 +02:00
Michal Kváček 4d68156a73 FIX: add missing cache forget after disabling module 2017-09-14 20:32:21 +02:00
Michal Kváček f10847dede FIX: just another bugfix 2017-09-14 20:17:16 +02:00
Michal Kváček 73681a5a4d FIX: minor bugfix 2017-09-14 11:34:08 +02:00
Michal Kváček a2d83ce3fa REFACTORING: split javascripts 2017-09-14 10:14:11 +02:00
Michal Kváček a0c31c7a5f FIX: fix error in translation 2017-09-13 14:34:11 +02:00
Michal Kváček 422339b313 MAINTENANCE: update laravel, dependencies, fix few bugs 2017-09-13 14:02:39 +02:00
Michal Kváček 3fdae2669b FEATURE: add page ordering 2017-09-13 14:02:07 +02:00
Michal Kváček d90ca08ba6 FEATURE: add new relationship to Content model - only visible subpages 2017-09-08 00:33:46 +02:00
Michal Kváček e8cbc1b537 FIX: fix permissions for publishing content pages 2017-09-07 23:53:34 +02:00
Michal Kváček 983efad9f0 TESTING #1931: do something with tests.. Not really usefull 2017-09-02 00:35:52 +02:00
Michal Kváček 2d66cf672a FEATURE #2520: add template for creating new table 2017-09-01 23:49:34 +02:00
Michal Kváček a5b6f6fa0d FEATURE #2520: add commands for creating new migration and running migrations in modules 2017-09-01 23:25:26 +02:00
Michal Kváček c92ba41def FIX: fix registering service providers in templates 2017-08-26 22:34:40 +02:00
Michal Kváček 6468c8f49c FEATURE: conditionally publish views in module, fix confirm dialog for forms 2017-08-25 11:40:34 +02:00
Michal Kváček 8bae8a43f9 FEATURE: add SITE_URL into installer 2017-08-24 14:29:06 +02:00
Michal Kváček 0e535c3ed1 FIX: fix few bugs in generating new module 2017-08-24 14:28:52 +02:00
Michal Kváček ce183d4805 FEATURE #2503: add easier installer 2017-08-24 14:15:08 +02:00
Michal Kváček 8946ef7441 FEATURE: update dependencies 2017-08-24 03:52:21 +02:00
Michal Kváček 295e8927a9 FIX: lots of bugfixes 2017-08-24 03:48:17 +02:00
Michal Kváček 029d84fed1 FEATURE: remove unused tables (custom fields) from database 2017-08-24 03:17:49 +02:00
Michal Kváček 862f49771f FEATURE: move templates into their own repositories 2017-08-24 03:05:30 +02:00
Michal Kváček 5abd7d9151 FIX: fix content dependency on categories 2017-08-24 02:50:30 +02:00
Michal Kváček ac8e3aeacc FEATURE: do not require template to be set in admin 2017-08-24 02:08:28 +02:00
Michal Kváček 49bd38db50 FEATURE: hopefully last changes about permissions 2017-08-24 02:04:20 +02:00
Michal Kváček b35149ad67 FEATURE: add permissions into widgets and fix few bugs 2017-08-24 01:54:58 +02:00
Michal Kváček e0f5cba9a4 FEATURE: add form for setting default permissions and fix few bugs 2017-08-23 21:34:56 +02:00
Michal Kváček 0aaa626124 FEATURE: add another permissions 2017-08-22 23:27:23 +02:00
Michal Kváček 1050271915 Merge branch 'authorization' into separate_modules 2017-08-22 22:36:00 +02:00
Michal Kváček e0b5559b96 FEATURE: hide menu entry when no content modules are available 2017-08-22 22:35:48 +02:00
Michal Kváček 3955d7290f FEATURE: remove gallery and move it into own repository 2017-08-22 20:19:06 +02:00
Michal Kváček 81ef15b8d6 FEATURE: remove contact form and move it into own repository 2017-08-22 20:18:20 +02:00
Michal Kváček f06d9b35d8 FEATURE: remove static pages and move it into own repository 2017-08-22 20:16:56 +02:00
Michal Kváček c4c328d21d FEATURE: add /modules into .gitignore 2017-08-22 14:11:57 +02:00
Michal Kváček fc8b76960a FEATURE: move categories into own repository 2017-08-22 14:11:48 +02:00
Michal Kváček b2e99bef05 FEATURE: move module blog into own repository 2017-08-22 14:08:28 +02:00
Michal Kváček 7d847cbab9 FIX: fix few bugs in routes 2017-08-11 04:13:33 +02:00
Michal Kváček ef432702b4 FEATURE #2048: add missing policies 2017-08-11 02:57:54 +02:00
Michal Kváček 7f43316602 FEATURE #2048: another work done on permissions 2017-08-11 02:24:44 +02:00
Michal Kváček 335ec4a167 FEATURE #2048: prepare routes for ACL, add some more permissions 2017-08-11 02:07:31 +02:00
Michal Kváček cccdbda543 FEATURE #2048: add basics of permissions management 2017-08-10 23:18:53 +02:00
Michal Kváček f702ba3a29 FEATURE #1854: add widget settings 2017-08-10 21:27:39 +02:00
Michal Kváček 6af0c16a9a FEATURE #1853: move widget areas 'views' into middleware 2017-08-10 19:59:40 +02:00
Michal Kváček c2209538db FEATURE: refactorize code little bit more 2017-08-04 18:43:18 +02:00
Michal Kváček 25d9ded124 FIX: fix bug related to settings cache 2017-08-02 18:35:48 +02:00
Michal Kváček 3a1e4b9c5b FIX #2056: areYouSure now reacts also on changes in CKEditor 2017-08-02 14:10:37 +02:00
Michal Kváček 3d73bffa6e FIX: fix minor bug in user management 2017-08-02 13:52:19 +02:00
Michal Kváček a4c020daa0 FEATURE #2047: use laravel's authorization 2017-08-02 13:33:26 +02:00
Michal Kváček 67fb3c6945 FEATURE #2039 @15m: clean up the code 2017-08-02 10:39:15 +02:00
Michal Kváček 7d6a3737e3 FEATURE #2389 @20m: add deleting all data from profiler 2017-03-28 01:01:21 +02:00
Michal Kváček aa55ffe46a FEATURE #2389 @2h: group http request by url 2017-03-28 00:27:31 +02:00
Michal Kváček 848fa7b7cb Merge branch 'dev' into module_profiler 2017-03-27 21:24:31 +02:00
Michal Kváček 05c9e56973 FEATURE #2389 @2h: add request detail into profiler 2017-03-24 01:28:21 +01:00
Michal Kváček 52e02d67c6 Merge branch 'dev' into module_profiler 2017-03-23 23:18:01 +01:00
Michal Kváček 9c90e844b0 FEATURE: add simple view for requests and queries 2017-03-02 20:04:35 +01:00
Michal Kváček d99c046103 Merge branch 'dev' into module_profiler 2017-03-02 12:29:21 +01:00
Michal Kváček c027ffe2df FEATURE: add first basics of profiler 2017-02-22 08:54:26 +01:00
668 changed files with 12250 additions and 82096 deletions
+5 -4
View File
@@ -1,3 +1,6 @@
/modules
/templates
# published files from modules
/public/modules
/public/assets
@@ -9,9 +12,6 @@
**/views/**/custom/*
!**/views/**/custom/.gitkeep
# module config - generated in ModuleManager service provider
**/module.json
# uploaded files
/public/uploads/*
!/public/uploads/.gitkeep
@@ -32,4 +32,5 @@
/public/js
/public/fonts
/bower_components
.sass-cache
.sass-cache
!/resources/views/vendor/
+1 -1
View File
@@ -10,7 +10,7 @@ interface Module extends BaseRepository
public function getUpdateContentTitle(ModuleModel $module, ContentModel $content = null);
public function getOverviewTitle(ModuleModel $module);
public function getOverviewTitle(ModuleModel $module = null);
public function getByHandler($handler);
+1 -1
View File
@@ -9,7 +9,7 @@ class UserRoles extends BaseEnumeration
{
$roles = [
User::ROLE_ADMIN => 'admin/userManagement.role_' . User::ROLE_ADMIN,
User::ROLE_EDITOR => 'admin/userManagement.role_' . User::ROLE_EDITOR,
// User::ROLE_EDITOR => 'admin/userManagement.role_' . User::ROLE_EDITOR,
User::ROLE_VISITOR => 'admin/userManagement.role_' . User::ROLE_VISITOR
];
@@ -1,19 +1,17 @@
<?php
namespace App\CMS\Handlers;
use App\CMS\Contracts\Modules\AppHandler;
use App\Http\Controllers\Controller;
use App\Models\Content\Content;
use App\Models\FileManager\File;
/**
* Class Handler
*
* Handler is a class which handles module-specific behaviour which cannot be done by module itself, resp. cannot be
* done by some abstract magic.
*
* @package App\CMS\Handlers\
*/
abstract class Handler extends BaseHandler implements AppHandler
abstract class AdminHandler extends BaseHandler implements AppHandler
{
public static function getHistoryHandler()
{
@@ -22,26 +20,38 @@ abstract class Handler extends BaseHandler implements AppHandler
public static function getExtendedFormSections()
{
return [
$formParts = [
'basicInfo' => trans('admin/contents.basicInfo'),
'meta' => trans('admin/contents.metaOptions'),
'publication' => trans('admin/contents.publicationOptions'),
'appearance' => trans('admin/contents.appearance'),
'files' => trans('admin/contents.files')
];
if (\Auth::user()->cannot('upload', File::class)) {
unset($formParts['files']);
}
return $formParts;
}
public static function getExtendedFormInputsCreate()
{
return [
$formParts = [
'basicInfo' => 'admin.content.formParts.basicInformation',
'meta' => 'admin.content.formParts.metaInformation',
'publication' => 'admin.content.formParts.publicationSetup',
'appearance' => 'admin.content.formParts.appearance',
'files' => 'admin.content.formParts.files'
];
if (\Auth::user()->cannot('upload', File::class)) {
unset($formParts['files']);
}
return $formParts;
}
public static function getExtendedFormInputsEdit()
{
return self::getExtendedFormInputsCreate();
+89 -44
View File
@@ -1,16 +1,24 @@
<?php
namespace App\CMS\Handlers;
use App\CMS\Contracts\Modules\BaseModuleHandler;
use App\CMS\Enumerations\TemplatePathsHumanReadableRootOnly;
use App\CMS\Enumerations\WidgetTypes;
use App\CMS\Repositories\Module;
use App\Models\ActionLog\ActionLog;
use App\Models\Content\Content;
use App\Models\FileManager\File;
use App\Models\Settings;
use App\Models\Templates\Template;
use App\Models\User;
use App\Models\Widgets\Widget;
use App\Models\Widgets\WidgetArea;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
abstract class BaseHandler implements BaseModuleHandler
{
/**
* Register admin menu (or multiple ones)
*
* This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before
* starting any middleware..
*
@@ -25,84 +33,121 @@ abstract class BaseHandler implements BaseModuleHandler
}
// create instance of main menu
\Menu::create('mainMenu', function ($menu) {
\Menu::create('mainMenu', function ($menu) use ($user) {
// $menu->route('admin.dashboard', trans('admin/mainMenu.dashboard'), [], 10, ['icon' => 'fa fa-fw fa-dashboard']);
/**
* Content pages
*
* Submenus can be registered later
*/
$menu->dropdown(trans('admin/mainMenu.contentPages'), function ($sub) {
$sub->route('content.overview', trans('admin/mainMenu.contentPageOverview'), [], 10000, ['icon' => 'fa fa-fw fa-list']);
}, 20, ['icon' => 'fa fa-fw fa-database']);
$contentModules = app(Module::class)->getContentModules();
if ($user->can('manage', Content::class) && !$contentModules->isEmpty()) {
$menu->dropdown(trans('admin/mainMenu.contentPages'), function ($sub) {
$sub->route('content.order', trans('admin/mainMenu.contentOrder'), [], 999, ['icon' => 'fa fa-fw fa-reorder']);
$sub->route('content.overview', trans('admin/mainMenu.contentPageOverview'), [], 10000, ['icon' => 'fa fa-fw fa-list']);
}, 20, ['icon' => 'fa fa-fw fa-database']);
}
/**
* File manager
*/
$menu->route('upload.overview', trans('admin/mainMenu.fileManager'), [], 40, ['icon' => 'fa fa-fw fa-folder']);
if ($user->can('manage', File::class)) {
$menu->route('upload.overview', trans('admin/mainMenu.fileManager'), [], 40, ['icon' => 'fa fa-fw fa-folder']);
}
/**
* Widgets and widget areas
*/
$menu->dropdown(trans('admin/mainMenu.widgets'), function ($sub) {
// create list of all widget types
$widgets = WidgetTypes::getWithTranslations();
if ($user->can('manage', Widget::class) || $user->can('manage', WidgetArea::class)) {
$menu->dropdown(trans('admin/mainMenu.widgets'), function ($sub) use ($user) {
// create list of all widget types
$widgets = WidgetTypes::getWithTranslations();
if (!empty($widgets)) {
$sub->dropdown(trans('admin/mainMenu.newWidget'), function ($sub) use ($widgets) {
$i = 1;
foreach ($widgets as $type => $name) {
$sub->route('widgets.new', $name, ['type' => $type], $i++);
}
}, 10, ['icon' => 'fa fa-fw fa-plus']);
}
if (!empty($widgets) && $user->can('create', Widget::class)) {
$sub->dropdown(trans('admin/mainMenu.newWidget'), function ($sub) use ($widgets) {
$i = 1;
foreach ($widgets as $type => $name) {
$sub->route('widgets.new', $name, ['type' => $type], $i++);
}
}, 10, ['icon' => 'fa fa-fw fa-plus']);
}
if ($user->can('manage', Widget::class)) {
$sub->route('widgets.overview', trans('admin/mainMenu.widgetsOverview'), [], 20, ['icon' => 'fa fa-fw fa-list']);
}
$sub->route('widgets.overview', trans('admin/mainMenu.widgetsOverview'), [], 20, ['icon' => 'fa fa-fw fa-list']);
// menu for widget areas
$sub->dropdown(trans('admin/mainMenu.widgetAreas'), function ($sub) {
$sub->route('widgetareas.new', trans('admin/mainMenu.newWidgetArea'), [], 1, ['icon' => 'fa fa-fw fa-plus']);
$sub->route('widgetareas.overview', trans('admin/mainMenu.widgetAreaOverview'), [], 2, ['icon' => 'fa fa-fw fa-list']);
}, 50, ['icon' => 'fa fa-fw fa-object-group']);
}, 50, ['icon' => 'fa fa-fw fa-puzzle-piece']);
// menu for widget areas
if ($user->can('manage', WidgetArea::class)) {
$sub->dropdown(trans('admin/mainMenu.widgetAreas'), function ($sub) use ($user) {
if ($user->can('create', WidgetArea::class)) {
$sub->route('widgetareas.new', trans('admin/mainMenu.newWidgetArea'), [], 1, ['icon' => 'fa fa-fw fa-plus']);
}
$sub->route('widgetareas.overview', trans('admin/mainMenu.widgetAreaOverview'), [], 2, ['icon' => 'fa fa-fw fa-list']);
}, 50, ['icon' => 'fa fa-fw fa-object-group']);
}
}, 50, ['icon' => 'fa fa-fw fa-puzzle-piece']);
}
/**
* Divide system entries and other links in menu
*/
$menu->addDivider(9999);
$menu->dropdown(trans('admin/mainMenu.system'), function ($sub) {
$menu->dropdown(trans('admin/mainMenu.system'), function ($sub) use ($user) {
/**
* User management
*/
$sub->dropdown(trans('admin/mainMenu.userManagement'), function ($sub) {
$sub->route('users.new', trans('admin/mainMenu.newUser'), [], 10, ['icon' => 'fa fa-fw fa-user-plus']);
$sub->route('users.overview', trans('admin/mainMenu.usersOverview'), [], 30, ['icon' => 'fa fa-fw fa-users']);
}, 20, ['icon' => 'fa fa-fw fa-users']);
if ($user->can('manage', User::class)) {
$sub->dropdown(trans('admin/mainMenu.userManagement'), function ($sub) use ($user) {
if ($user->can('create', User::class)) {
$sub->route('users.new', trans('admin/mainMenu.newUser'), [], 10, ['icon' => 'fa fa-fw fa-user-plus']);
}
$sub->route('users.overview', trans('admin/mainMenu.usersOverview'), [], 30, ['icon' => 'fa fa-fw fa-users']);
}, 20, ['icon' => 'fa fa-fw fa-users']);
}
/**
* Templates
*/
$templatePaths = TemplatePathsHumanReadableRootOnly::getWithTranslations();
if (!empty($templatePaths)) {
$sub->dropdown(trans('admin/mainMenu.templates'), function ($sub) use ($templatePaths) {
$i = 1;
foreach ($templatePaths as $id => $name) {
$sub->route('templates.overview', $name, ['id' => $id], $i++);
}
}, 60, ['icon' => 'fa fa-fw fa-file-code-o']);
if ($user->can('manage', Template::class)) {
$sub->route('templates.index', trans('admin/mainMenu.templates'), [], 70, ['icon' => 'fa fa-fw fa-file-code-o']);
}
$sub->route('log.overview', trans('admin/mainMenu.actionLog'), [], 70, ['icon' => 'fa fa-fw fa-history']);
$sub->route('settings.overview', trans('admin/mainMenu.settings'), [], 80, ['icon' => 'fa fa-fw fa-gear']);
if ($user->can('manage', ActionLog::class)) {
$sub->route('log.overview', trans('admin/mainMenu.actionLog'), [], 70, ['icon' => 'fa fa-fw fa-history']);
}
if ($user->can('manage', Settings::class)) {
$sub->route('settings.overview', trans('admin/mainMenu.settings'), [], 80, ['icon' => 'fa fa-fw fa-gear']);
$sub->route('permissions.index', trans('admin/mainMenu.permissions'), [], 90, ['icon' => 'fa fa-fw fa-key']);
}
}, 10000, ['icon' => 'fa fa-fw fa-gears']);
});
\Menu::create('topMenu', function ($menu) use ($user) {
if (count(LaravelLocalization::getSupportedLocales()) > 1) {
$menu->dropdown(trans(LaravelLocalization::getCurrentLocaleName()), function ($menu) use ($user) {
foreach (LaravelLocalization::getSupportedLocales() as $localeCode => $properties) {
$menu->url(LaravelLocalization::getLocalizedURL($localeCode), $properties['native']);
}
});
}
if ($user->can('manage', Content::class)) {
$menu->route('page.index', '', [], 10, [
'icon' => 'fa fa-fw fa-globe',
'title' => trans('common.goToWeb'),
'target' => '_blank',
'data-toggle' => 'tooltip',
'data-placement' => 'left'
]);
}
});
// create menu with user profile
\Menu::create('profileMenu', function ($menu) {
$menu->route('users.detail', trans('admin/userManagement.profile'), [], 10, ['icon' => 'fa fa-fw fa-user icon']);
\Menu::create('profileMenu', function ($menu) use ($user) {
$menu->route('users.detail', trans('admin/userManagement.profile'), ['user' => $user], 10, ['icon' => 'fa fa-fw fa-user icon']);
$menu->addDivider(999);
$menu->route('logout', trans('admin/common.logout'), [], 1000, ['icon' => 'fa fa-fw fa-power-off icon']);
});
+3 -4
View File
@@ -17,8 +17,7 @@ class History implements HistoryHandler
switch ($changeset->column) {
case 'pageContent':
$route = route('history.diff', [
'revision' => $changeset->edit_batch,
'id' => $changeset->id
'revision' => $changeset->id
]);
return "(<a href='" . $route . "'>" . trans('admin/history.diff') . "</a>)";
@@ -48,8 +47,8 @@ class History implements HistoryHandler
break;
default:
return trans('admin/history.changedFromTo', [
'from' => is_null($changeset->old_value) ? trans('admin/history.emptyValue') : $changeset->old_value,
'to' => is_null($changeset->new_value) ? trans('admin/history.emptyValue') : $changeset->new_value,
'from' => empty($changeset->old_value) ? trans('admin/history.emptyValue') : $changeset->old_value,
'to' => empty($changeset->new_value) ? trans('admin/history.emptyValue') : $changeset->new_value,
]);
break;
}
@@ -15,6 +15,7 @@ class SettingExtension
* @var string view used for rendering given settings part
*/
protected $view;
protected $order;
/**
* SettingExtension constructor.
@@ -23,11 +24,12 @@ class SettingExtension
* @param string $name
* @param string $view
*/
public function __construct($id, $name, $view)
public function __construct($id, $name, $view, $order)
{
$this->id = $id;
$this->name = $name;
$this->view = $view;
$this->order = $order;
}
/**
@@ -53,4 +55,14 @@ class SettingExtension
{
return $this->view;
}
/**
* @return mixed
*/
public function getOrder()
{
return $this->order;
}
}
@@ -1,7 +1,8 @@
<?php
namespace App\CMS\Handlers\Registrators;
use App\CMS\Enumerations\Exceptions\EnumerationExistsException;
use App\CMS\Exceptions\Enumerations\EnumerationExistsException;
use App\CMS\Handlers\Registrators\Items\SettingExtension;
class SettingsExtensionRegistrator
@@ -22,12 +23,16 @@ class SettingsExtensionRegistrator
*
* @throws EnumerationExistsException
*/
public function register($sectionId, $sectionName, $sectionView)
public function register($sectionId, $sectionName, $sectionView, $order = null)
{
$this->checkIfRegistered($sectionId);
if (is_null($order)) {
$order = count($this->settingsExtensions);
}
// register new extension
$this->settingsExtensions[$sectionId] = new SettingExtension($sectionId, $sectionName, $sectionView);
$this->settingsExtensions[$sectionId] = new SettingExtension($sectionId, $sectionName, $sectionView, $order);
}
/**
@@ -44,14 +49,15 @@ class SettingsExtensionRegistrator
/**
* Getter for all registered extensions
*
* @return array
*/
public function get()
{
// sort registered extensions by key
ksort($this->settingsExtensions);
// sort registered extensions
uasort($this->settingsExtensions, function (SettingExtension $a, SettingExtension $b) {
return $a->getOrder() - $b->getOrder();
});
return $this->settingsExtensions;
}
@@ -207,6 +207,7 @@ class TemplateRegistrator
protected function registerTemplates($path, $templatePathId)
{
$templates = File::files($path);
$registeredTemplates = Templates::getWithTranslations();
foreach ($templates as $template) {
@@ -217,7 +218,6 @@ class TemplateRegistrator
// get all templates and template name (path/to/template.blade.php -> path.to.template)
$templateName = $this->getTemplateName($template);
$registeredTemplates = Templates::getWithTranslations();
if (!in_array($templateName, $registeredTemplates)) {
$params = [
@@ -316,4 +316,14 @@ class TemplateRegistrator
return $this->namespace . trim($templateName, '.');
}
public function deleteNonExistingPaths()
{
$paths = TemplatePath::all();
foreach ($paths as $path) {
if (!is_dir(base_path($path->path)))
\File::deleteDirectory($path->path);
}
}
}
+9 -1
View File
@@ -1,7 +1,10 @@
<?php
namespace App\CMS\Handlers\Search;
use App\Models\Content\Content as ContentModel;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
class Content extends Search
{
@@ -10,10 +13,15 @@ class Content extends Search
*
* @param string $term searched word
*
* @return array list of found objects
* @return array|\Illuminate\Database\Eloquent\Collection|Collection|static[]
*/
public function search($term)
{
if (Auth::user()
->cannot('manage', ContentModel::class)) {
return new Collection();
}
$token = $this->tokenize($term);
return ContentModel::where('pageContent', 'LIKE', $token)
+7
View File
@@ -1,7 +1,9 @@
<?php
namespace App\CMS\Handlers\Search;
use App\Models\FileManager\File;
use Illuminate\Support\Collection;
class Files extends Search
{
@@ -24,6 +26,11 @@ class Files extends Search
*/
public function search($term)
{
if (\Auth::user()
->cannot('manage', File::class)) {
return new Collection();
}
$token = $this->tokenize($term);
return File::where('original_filename', 'LIKE', $token)
@@ -3,11 +3,17 @@ namespace App\CMS\Handlers\Search\Presenters;
use App\CMS\Enumerations\ContentStatuses;
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
use App\Models\Content\Content;
class AdminContent implements SearchPresenterHandler
{
public function render($foundItems)
{
if (\Auth::user()
->cannot('manage', Content::class)) {
return null;
}
return view('admin.search.results.content', [
'pages' => $foundItems,
'statuses' => ContentStatuses::getWithTranslations(),
@@ -2,6 +2,7 @@
namespace App\CMS\Handlers\Search\Presenters;
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
use App\Models\FileManager\File;
class AdminFiles implements SearchPresenterHandler
{
@@ -14,6 +15,11 @@ class AdminFiles implements SearchPresenterHandler
*/
public function render($foundItems)
{
if (\Auth::user()
->cannot('manage', File::class)) {
return null;
}
return view('admin.fileManager.filesTiles', ['files' => $foundItems, 'hideDelete' => true]);
}
}
-37
View File
@@ -1,37 +0,0 @@
<?php
namespace App\CMS\Helpers;
use App\CMS\Handlers\Contracts\AppHandler;
use App\Models\Content\Content;
use Webwizo\Shortcodes\Facades\Shortcode;
/**
* Class PageRenderer
*
* Simple class for rendering page for visitor
*
* @package App\CMS\Helpers
*/
class PageRenderer
{
/**
* Render page
*
* @param Content $page
*
* @return mixed
*/
public static function render(Content $page)
{
// do something template-specific
$parameters = call_user_func_array([CurrentTemplate::handler(), 'beforeRender'], [&$page]);
/**
* @var $handler AppHandler
*/
$handler = new $page->moduleHandler;
// render page
return $handler->render($page, $parameters);
}
}
+1 -1
View File
@@ -79,7 +79,7 @@ class Settings
{
if (!self::$initialized) {
self::$settings = Cache::remember('settings', config('cache.settingCacheLifetime'), function () {
app(SettingsRepository::class)->getAll();
return app(SettingsRepository::class)->getAll();
});
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ trait Nullable {
* @return null|string
*/
public function nullableDate($date) {
return empty($date) ? null : Carbon::parse($date)->toDateTimeString();
return empty($date) ? null : Carbon::createFromFormat(config('app.date_format'), $date)->toDateTimeString();
}
/**
+10 -6
View File
@@ -3,7 +3,6 @@
namespace App\CMS\Helpers;
use App\CMS\Repositories\Widgets\WidgetArea as WidgetAreaRepository;
use App\Models\Widgets\WidgetArea;
use Illuminate\Support\Facades\Cache;
class WidgetAreas
@@ -27,9 +26,6 @@ class WidgetAreas
protected static function loadWidgetArea($uniqueCode)
{
WidgetArea::where('code', $uniqueCode)
->increment('viewed');
$widgets = Cache::remember('widget-area-' . $uniqueCode, setting('widgetCacheLifetime', 5), function () use ($uniqueCode) {
$widgetArea = app(\App\CMS\Repositories\Widgets\WidgetArea::class);
@@ -69,12 +65,20 @@ class WidgetAreas
self::initWidgetAreas();
}
// dd($uniqueCode);
if (!isset(self::$widgetAreas[$uniqueCode])) {
self::loadWidgetArea($uniqueCode);
}
echo isset(self::$widgetAreas[$uniqueCode]) ? self::$widgetAreas[$uniqueCode] : null;
}
/**
* Get list of loaded widgets and areas
*
* @return array
*/
public static function getLoadedWidgets()
{
return ['areas' => array_keys(self::$widgetAreas)];
}
}
@@ -1,83 +0,0 @@
<?php
namespace App\CMS\MenuPresenters;
use Nwidart\Menus\MenuItem;
use Nwidart\Menus\Presenters\Presenter;
class FoundationDrilldownMenuPresenter extends Presenter
{
/**
* {@inheritdoc }
*/
public function getOpenTagWrapper()
{
return PHP_EOL . '<ul class="vertical menu" data-drilldown>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getCloseTagWrapper()
{
return PHP_EOL . '</ul>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getMenuWithoutDropdownWrapper($item)
{
return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '">' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getActiveState(MenuItem $item)
{
$active = ' class="active"';
if (empty($item->getChilds())) {
// for direct menu input return if page is active
return \Request::is($item->getRequest()) ? $active : null;
} else {
// on nested menu inputs loop over children and in case any of them is active, mark active also root level
foreach ($item->getChilds() as $child) {
if ($this->getActiveState($child)) {
return $active;
}
}
}
return null;
}
/**
* {@inheritdoc }
*/
public function getDividerWrapper()
{
return '<li class="divider"></li>' . PHP_EOL;
}
public function getMultiLevelDropdownWrapper($item)
{
return $this->getMenuWithDropDownWrapper($item);
}
/**
* {@inheritdoc }
*/
public function getMenuWithDropDownWrapper($item)
{
$active = $this->getActiveState($item);
return '<li>
<a ' . $active . ' href="#">' . $item->getIcon() . ' ' . $item->title . '</a>
<ul class="vertical menu">
' . $this->getChildMenuItems($item) . '
</ul>
</li>' . PHP_EOL;
}
}
@@ -1,62 +0,0 @@
<?php
namespace App\CMS\MenuPresenters;
use Nwidart\Menus\Presenters\Presenter;
class FoundationDropdownMenuPresenter extends Presenter
{
/**
* {@inheritdoc }
*/
public function getOpenTagWrapper()
{
return PHP_EOL . '<ul class="vertical dropdown menu" data-dropdown-menu>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getCloseTagWrapper()
{
return PHP_EOL . '</ul>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getMenuWithoutDropdownWrapper($item)
{
$link = '<a href="' . $item->getUrl() . '">' . $item->getIcon() . ' ' . $item->title . '</a>';
return '<li' . $this->getActiveState($item) . '>' . $link . '</li>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getActiveState($item)
{
return \Request::is($item->getRequest()) || $item->hasActiveOnChild ? ' class="active"' : null;
}
/**
* {@inheritdoc }
*/
public function getDividerWrapper()
{
return '<li class="divider"></li>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getMenuWithDropDownWrapper($item)
{
return '<li>
<a href="#">' . $item->getIcon() . ' ' . $item->title . '</a>
<ul class="vertical menu">
' . $this->getChildMenuItems($item) . '
</ul>
</li>' . PHP_EOL;
}
}
@@ -1,10 +0,0 @@
<?php
namespace App\CMS\MenuPresenters;
class FoundationInitializedDropdownMenuPresenter extends FoundationDropdownMenuPresenter
{
public function getOpenTagWrapper()
{
return PHP_EOL . '<ul class="menu">' . PHP_EOL;
}
}
@@ -1,4 +1,5 @@
<?php
namespace App\CMS\MenuPresenters;
use Nwidart\Menus\MenuItem;
@@ -27,6 +28,10 @@ class MetismenuPresenter extends Presenter
*/
public function getMenuWithoutDropdownWrapper($item)
{
if (!is_string($item->getUrl())) {
return null;
}
return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '">' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
}
@@ -0,0 +1,16 @@
<?php
namespace App\CMS\MenuPresenters;
use Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter;
class TopMenuPresenter extends NavbarPresenter {
public function getOpenTagWrapper()
{
return '';
}
public function getCloseTagWrapper()
{
return '';
}
}
@@ -1,6 +1,6 @@
<?php
namespace App\ModuleManager;
namespace App\CMS\ModuleManager;
use App\CMS\Contracts\Modules\AppHandler;
use App\CMS\Contracts\Modules\TemplateHandler;
@@ -1,9 +1,10 @@
<?php
namespace App\ModuleManager\Providers;
namespace App\CMS\ModuleManager\Providers;
use App\Models\Module;
use Illuminate\Support\Facades\Cache;
use App\CMS\Repositories\Module as ModuleRepository;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
class ModuleManager extends ServiceProvider
@@ -15,16 +16,22 @@ class ModuleManager extends ServiceProvider
public function boot()
{
// this service provider needs published config - config is merged right after this service provider
$modules = Cache::rememberForever('enabled-modules', function () {
return Module::where('enabled', true)
->where('is_template', false)
->get();
});
try {
$modules = app(ModuleRepository::class)->all();
} catch (QueryException $e) {
return;
}
// iterate over all modules and enable or disable them
foreach ($modules as $module) {
if (isset($module->module_settings['providers']) && !empty($module->module_settings['providers'])) {
foreach ($module->module_settings['providers'] as $provider) {
if (!class_exists($provider)) {
Log::warning($provider.' does not exists. Skipping');
continue;
}
$this->app->register($provider);
}
}
@@ -32,7 +39,13 @@ class ModuleManager extends ServiceProvider
// include files (if any)
if (isset($module->module_settings['files']) && !empty($module->module_settings['files'])) {
foreach ($module->module_settings['files'] as $file) {
include config('modules.paths.modules') . '/' . $module->static_name . '/' . $file;
$path = config('modules.paths.modules') . '/' . $module->static_name . '/' . $file;
if (!file_exists($path)) {
$path = base_path($file);
}
@include_once $path;
}
}
}
@@ -1,5 +1,5 @@
<?php
namespace App\ModuleManager;
namespace App\CMS\ModuleManager;
use App\Models\Module;
use App\Models\Templates\TemplatePath;
@@ -13,6 +13,7 @@ abstract class ServiceProvider extends LaravelServiceProvider
protected $defer = false;
protected $alias = false;
protected $path = false;
protected $publishViews = true;
abstract protected function setModuleAlias();
@@ -59,7 +60,7 @@ abstract class ServiceProvider extends LaravelServiceProvider
return $path . '/modules/' . $this->alias;
}, \Config::get('view.paths')), [$sourcePath]), $this->alias);
if (is_dir($sourcePath)) {
if (is_dir($sourcePath) && $this->publishViews) {
$this->publishes([$sourcePath => $viewPath], 'module-views');
}
}
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class $MigrationName$ extends Migration
{
/**
* Run migration
*/
public function up()
{
Schema::create('$TableName$', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
/**
* Rollback migration
*/
public function down()
{
Schema::dropIfExists('$TableName$');
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class $MigrationName$ extends Migration
{
/**
* Run migration
*/
public function up()
{
Schema::table('$TableName$', function (Blueprint $table) {
});
}
/**
* Rollback migration
*/
public function down()
{
Schema::table('$TableName$', function (Blueprint $table) {
});
}
}
@@ -4,7 +4,7 @@ return [
'name' => '$Module$',
'translatedName' => '$module$::$module$.name',
'translatedDescription' => '$module$::$module$.description',
'alias' => 'categories',
'alias' => strtolower('$Module$'),
'handler' => \Modules\$Module$\Handlers\$Module$Handler::class,
'providers' => [\Modules\$Module$\Providers\$Module$ServiceProvider::class],
'files' => ['Http/routes.php'],
@@ -4,5 +4,7 @@ namespace Modules\$ModuleNamespace$\Entities;
use Illuminate\Database\Eloquent\Model;
class $Entity$ extends Model {
protected $table = 'contents';
// ...
}
@@ -2,10 +2,10 @@
namespace Modules\$ModuleNamespace$\Handlers;
use App\CMS\Handlers\Handler;
use App\CMS\Handlers\BaseHandler;
use App\Models\User;
class $Module$Handler extends Handler
class $Module$Handler extends BaseHandler
{
/**
* Register admin menu
@@ -6,7 +6,7 @@ use App\Http\Controllers\Admin\Controller;
use Modules\$ModuleNamespace$\Http\Requests\Update$Entity$;
use Modules\$ModuleNamespace$\Http\Requests\Create$Entity$;
use Modules\$ModuleNamespace$\Repositories\$Module$Repository;
use $EntityNamespace$\$Entity$ as $Entity$Entity;
use $EntityNamespace$$Entity$ as $Entity$Entity;
class $Module$ extends Controller
{
@@ -2,7 +2,7 @@
namespace Modules\$Module$\Providers;
use App\CMS\Contracts\Modules\ServiceProvider;
use App\CMS\Modules\ServiceProviders\ServiceProvider;
/**
* Class $Module$ServiceProvider
@@ -1,7 +1,7 @@
<?php
namespace Modules\$ModuleNamespace$\Repositories;
use $EntityNamespace$\$Entity$ as $Entity$Entity;
use $EntityNamespace$$Entity$ as $Entity$Entity;
class $Module$Repository {
/**
+5 -4
View File
@@ -1,4 +1,5 @@
<?php
namespace App\CMS\Repositories\Content;
use App\CMS\Contracts\Repositories\Content as IContent;
@@ -6,7 +7,6 @@ use App\CMS\Enumerations\ContentStatuses;
use App\CMS\Repositories\Repository;
use App\Models\Content\Content as ContentModel;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class Content extends Repository implements IContent
@@ -105,14 +105,15 @@ class Content extends Repository implements IContent
*/
public function getOverview($handler = null, $statuses = null)
{
$query = ContentModel::select('contents.*', 'modules.name AS module_name', 'modules.id AS module_id')
$query = ContentModel::select('contents.*')
->join('modules', 'modules.handler', '=', 'contents.moduleHandler')
->join('users', 'users.id', '=', 'contents.userId')
->addSelect(DB::raw('COALESCE(users.name, users.email) AS author_name'))
->addSelect('users.email AS author_email')
->whereNull('contents.deleted_at')
->whereNull('contents.parentId')
->where('contents.language', LaravelLocalization::getCurrentLocale())
->where('modules.enabled', 1)
->with('module', 'subpages', 'subpages.module', 'subpages.templateModel', 'templateModel')
->orderBy('contents.order')
->orderBy('contents.created_at', 'DESC');
// filter results using handler
+30 -3
View File
@@ -1,9 +1,11 @@
<?php
namespace App\CMS\Repositories;
use App\CMS\Contracts\Repositories\Module as IModule;
use App\Models\Content\Content;
use App\Models\Module as ModuleModel;
use Illuminate\Support\Facades\Cache;
class Module extends Repository implements IModule
{
@@ -26,6 +28,15 @@ class Module extends Repository implements IModule
}
}
public function getContentModules()
{
return Cache::remember('enabled-content-modules', setting('cacheModules', 3600), function () {
return ModuleModel::where('enabled', true)
->where('manages_content', true)
->get();
});
}
public function getCreateContentTitle(ModuleModel $module)
{
$pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]);
@@ -42,9 +53,14 @@ class Module extends Repository implements IModule
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
}
public function getOverviewTitle(ModuleModel $module)
public function getOverviewTitle(ModuleModel $module = null)
{
$pageHeading = 'admin/contents.overview';
if (is_null($module)) {
return $pageHeading;
}
$moduleHeading = $this->call($module, 'getOverviewTitle');
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
@@ -52,8 +68,19 @@ class Module extends Repository implements IModule
public function all()
{
return ModuleModel::where('enabled', true)
->get();
return Cache::remember('enabled-modules-and-template', setting('cacheModules', 3600), function () {
return ModuleModel::where('enabled', true)
->get();
});
}
public function getOnlyModules()
{
return Cache::remember('enabled-modules', setting('cacheModules', 3600), function () {
return ModuleModel::where('enabled', true)
->where('is_template', false)
->get();
});
}
public function getByHandler($handler)
@@ -0,0 +1,15 @@
<?php
namespace App\CMS\Repositories\Permissions;
use App\Models\Permissions\Permission as PermissionModel;
class Permission
{
public function getRootPermissions()
{
return PermissionModel::whereNull('parent_id')
->with('subpermissions')
->get();
}
}
@@ -3,6 +3,7 @@
namespace App\CMS\Repositories\Settings;
use App\Models\Settings as SettingsModel;
use Illuminate\Support\Facades\Cache;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class Settings
@@ -104,5 +105,7 @@ class Settings
$setting->value = $value;
empty($value) ? $setting->delete() : $setting->save();
}
Cache::forget('settings');
}
}
+7 -3
View File
@@ -1,10 +1,12 @@
<?php
namespace App\Cms\Repositories\Templates;
use App\CMS\Contracts\Repositories\Template as ITemplate;
use App\CMS\Repositories\Repository;
use App\Models\Module;
use App\Models\Templates\Template as TemplateModel;
use Illuminate\Support\Facades\Cache;
class Template extends Repository implements ITemplate
{
@@ -68,8 +70,10 @@ class Template extends Repository implements ITemplate
public function getForModule(Module $module)
{
return TemplateModel::where('module_id', $module->id)
->select(['template_name', 'name', 'description'])
->get();
return Cache::remember('templates-for-module-'.$module->id, setting('cacheModules', 3600), function () use ($module) {
return TemplateModel::where('module_id', $module->id)
->select(['template_name', 'name', 'description'])
->get();
});
}
}
+14 -13
View File
@@ -8,6 +8,7 @@ use App\CMS\Contracts\Widgets\WidgetRenderer;
use App\CMS\Widgets\Exceptions\MissingParameterException;
use App\Http\Requests\Request;
use App\Models\Content\Content;
use Illuminate\Support\Facades\Cache;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Modules\Blog\Article\Handlers\Article;
@@ -15,7 +16,6 @@ class Menu implements PublicWidget
{
/**
* Name getter
*
* @return string
*/
public static function getName()
@@ -25,7 +25,6 @@ class Menu implements PublicWidget
/**
* Getter for description
*
* @return string
*/
public static function getDescription()
@@ -35,7 +34,6 @@ class Menu implements PublicWidget
/**
* Getter for presenter/renderer of this widget
*
* @return WidgetRenderer
*/
public static function getPresenter()
@@ -75,16 +73,19 @@ class Menu implements PublicWidget
$allowedStatuses[] = IContent::STATUS_PROTECTED;
}
$pages = Content::where('language', LaravelLocalization::getCurrentLocale())
->whereIn('id', $ids)
->whereIn('status', $allowedStatuses)
->where('moduleHandler', '!=', Article::class)
->get();
$used = [];
foreach ($pages as $page) {
$used[$page->id] = $page;
}
return Cache::remember('widget-menu-content-pages', 5, function () use ($ids, $allowedStatuses) {
$pages = Content::where('language', LaravelLocalization::getCurrentLocale())
->whereIn('id', $ids)
->whereIn('status', $allowedStatuses)
->where('moduleHandler', '!=', Article::class)
->get();
return $used;
$used = [];
foreach ($pages as $page) {
$used[$page->id] = $page;
}
return $used;
});
}
}
+26 -13
View File
@@ -12,9 +12,10 @@ use Illuminate\Support\Facades\Route;
class Menu implements WidgetRenderer
{
public static $template = null;
/**
* Method used for displaying widget.
*
* This method renders some HTML code for displaying.
*
* @param Widget $widget
@@ -27,6 +28,11 @@ class Menu implements WidgetRenderer
$links = (array)$settings->links;
$pageIds = array_keys($links);
if (!self::$template) {
throw new \Exception('neni nastavena sablona');
return;
}
// get pages
$pages = WidgetMenu::selectContentPages($pageIds);
@@ -40,14 +46,15 @@ class Menu implements WidgetRenderer
$parameters = Route::current()
->parameters();
$code = '<ul class="menu ' . $widget->container_class . '"';
// $code = '<ul class="menu ' . $widget->container_class . '"';
if ($widget->container_id) {
$code .= ' id="' . e($widget->container_id) . '"';
}
// if ($widget->container_id) {
// $code .= ' id="' . e($widget->container_id) . '"';
// }
$code .= '>';
// $code .= '>';
$menuItems = [];
foreach ($links as $pageId => $link) {
if (!isset($pages[$pageId])) {
continue;
@@ -57,16 +64,22 @@ class Menu implements WidgetRenderer
$active = ($page->isHomepage && $routeName == 'page.index') || ($routeName == 'page.content' && isset($parameters['url']) && $parameters['url'] == $page->url);
$route = $page->isHomepage ? route('page.index') : route('page.content', ['url' => $page->url]);
$code .= '<li';
if ($active) {
$code .= ' class="is-active active"';
}
$code .= '><a href="' . $route . '">' . e($page->title) . '</a></li>';
$menuItems[] = compact('page', 'active', 'route');
// $code .= '<li';
// if ($active) {
// $code .= ' class="is-active active"';
}
// $code .= '><a href="' . $route . '">' . e($page->title) . '</a></li>';
// }
$code .= "</ul>";
// $code .= "</ul>";
return $code;
return view(self::$template, [
'containerClass' => $widget->container_class,
'containerId' => $widget->container_id,
'menuItems' => $menuItems
]);
}
/**
+1 -1
View File
@@ -30,7 +30,7 @@ class ChangePassword extends Command
$email = $this->argument('email');
try {
$user = User::where(['email' => $email])
->first();
->firstOrFail();
} catch (ModelNotFoundException $e) {
$this->error('Invalid user ' . $email . '.');
return;
+9 -6
View File
@@ -13,14 +13,14 @@ class InitDatabaseSchema extends Command
*
* @var string
*/
protected $signature = 'db:init {schema.sql}';
protected $signature = 'db:init';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
protected $description = 'Init database structure';
/**
* Create a new command instance.
@@ -39,13 +39,16 @@ class InitDatabaseSchema extends Command
*/
public function handle()
{
do {
$schema = $this->ask('Path to database schema file', 'database/schema.sql');
} while (!file_exists($schema));
$schema = $this->argument('schema.sql');
if (!file_exists($schema)) throw new NotFoundHttpException('File '.$schema.' does not exist.');
DB::unprepared(file_get_contents($schema));
$this->line('Successfully imported');
$this->call('migrate');
$this->call('db:seed');
$this->line('Database successfully initialized.');
}
}
+153
View File
@@ -0,0 +1,153 @@
<?php
namespace App\Console\Commands;
use App\Models\Language;
use Illuminate\Console\Command;
use Illuminate\Database\QueryException;
class InstallCMS extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'cms:install';
/**
* The console command description.
* @var string
*/
protected $description = 'Try to make installation of CMS as easy as possible';
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
// check and eventualy create .env file
if (!file_exists(base_path('.env'))) {
$this->createEnv();
$this->line('Rerun this script again, we need to load changes.');
return;
}
// install php dependencies
$parameters = env('APP_DEBUG') ? '' : '--no-dev';
exec('composer install ' . $parameters);
// init database
try {
// does exist something in laguages table? (Or event table itself?)
Language::all();
} catch (QueryException $e) {
// database is not initialized
$this->call('db:init');
}
// install npm dependencies
exec('npm install');
exec('bower install');
exec('gulp');
// change chmod of needed directories
$directories = ['bootstrap/cache', 'storage', 'public'];
foreach ($directories as $directory) {
$this->changeChmod($directory);
}
$this->line('Chmod changed');
// generate APP_KEY in .env
$this->call('key:generate');
// create user
$this->line('Creating admin user...');
do {
$email = $this->ask('E-mail for admin user');
} while (empty($email));
$this->call('user:new', compact('email'));
$this->line('All done. CMS should be prepared.');
}
/**
* Insert value into .env config file
*
* @param $envConstant
* @param $value
*/
private function setEnvConstant($envConstant, $value)
{
$content = file_get_contents(base_path('.env'));
$content = preg_replace('/' . $envConstant . '=(.*)/i', $envConstant . '=' . $value, $content);
file_put_contents(base_path('.env'), $content);
}
/**
* Create .env file with all needed constants
*/
private function createEnv()
{
\File::copy(base_path('.env.example'), base_path('.env'));
// set environment
do {
$env = $this->ask('Install environment: ', 'local');
} while (empty($env));
$this->setEnvConstant('APP_ENV', $env);
// set debugging
if ($env == 'local') {
$debug = 'true';
} else {
$debug = $this->confirm('Enable debugging?', true) ? 'true' : 'false';
}
$this->setEnvConstant('APP_DEBUG', $debug);
// setup database
$databaseFields = [
'DB_HOST' => 'Database server',
'DB_DATABASE' => 'Database name',
'DB_USERNAME' => 'Database user',
'DB_PASSWORD' => 'Password'
];
foreach ($databaseFields as $constant => $text) {
do {
$value = $this->ask($text);
} while (empty ($value));
$this->setEnvConstant($constant, $value);
}
// set app url
do {
$url = $this->ask('Application URL');
$url = trim($url, ' /');
} while (empty($url));
$this->setEnvConstant('SITE_URL', $url);
$this->setEnvConstant('UPLOAD_URL', $url . '/public/uploads');
$this->setEnvConstant('THUMBNAIL_URL', $url . '/public/uploads/thumbnails');
}
/**
* Recursively change chmod to 777 in given directory
*
* @param $directory
*/
private function changeChmod($directory)
{
@chmod($directory, 0777);
if (!is_dir($directory)) {
return;
}
$subdirectories = \File::allFiles($directory);
foreach ($subdirectories as $subdirectory) {
$this->changeChmod($subdirectory);
}
}
}
@@ -0,0 +1,106 @@
<?php
namespace App\Console\Commands\Modules;
use App\Models\Module;
use Illuminate\Console\Command;
class CreateMigration extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'module:make-migration {module?} {name?} {--t|table= : Table name} {--c|create : Use template for creating new table}';
/**
* The console command description.
* @var string
*/
protected $description = 'Make new migration for given module';
protected $migrationName;
protected $tableName;
protected $moduleName;
/**
* Execute the console command.
*/
public function handle()
{
$this->moduleName = $module = $this->argument('module');
$this->migrationName = $name = $this->argument('name');
$this->tableName = trim($this->option('table'), ' =');
$modules = Module::where('enabled', true)
->get()
->pluck('static_name', 'id')
->toArray();
while (is_null($module) || !in_array($module, $modules)) {
$module = $this->anticipate('Input valid module name', $modules);
}
$selectedModule = Module::where('static_name', $module)
->first();
$basePath = $selectedModule->is_template ? config('modules.path.template') : config('modules.paths.modules');
$path = $basePath . '/' . $module . '/Database/Migrations/';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
while (is_null($name)) {
$this->migrationName = $name = $this->ask('Input migration name');
}
$stubName = $this->option('create') ? 'create' : 'new';
$content = file_get_contents(config('modules.paths.stubs') . '/Migrations/' . $stubName . '.stub');
$content = $this->replacePlaceholders($content);
$migrationName = $path . $this->getMigrationName($name);
file_put_contents($migrationName, $content);
$this->line('Migration successfully created.', 'info');
}
/**
* Find and replace all placeholders in given content
*
* @param $content
*
* @return mixed
*/
private function replacePlaceholders($content)
{
$replace = [
'$MigrationName$' => studly_case($this->migrationName),
'$ModuleName$' => $this->moduleName,
'$TableName$' => $this->tableName
];
foreach ($replace as $what => $for) {
$content = str_replace($what, $for, $content);
}
return $content;
}
/**
* Get prefix for created migration
* @return false|string
*/
protected function getDatePrefix()
{
return date('Y_m_d_His');
}
/**
* @param $name
*
* @return string
*/
private function getMigrationName($name)
{
return $this->getDatePrefix() . '_' . snake_case($name) . '.php';
}
}
+7 -1
View File
@@ -38,8 +38,11 @@ class CreateNew extends Command
return;
}
if (!is_dir($path))
mkdir($path);
// copy stub files
\File::copyDirectory(config('modules.paths.stubs'), $path);
\File::copyDirectory(config('modules.paths.stubs').'/NewModule', $path);
$files = \File::allFiles($path);
foreach ($files as $file) {
@@ -61,6 +64,9 @@ class CreateNew extends Command
}
$this->info('Module successfully created.');
$this->call('module:install', ['name' => $this->moduleName]);
}
/**
@@ -39,6 +39,10 @@ class DisableModule extends Command
$module->enabled = false;
$module->save();
\Cache::forget('enabled-modules');
\Cache::forget('enabled-content-modules');
\Cache::forget('enabled-modules-and-template');
$this->line('Module ' . $module->static_name . ' disabled.');
}
}
@@ -43,6 +43,10 @@ class EnableModule extends Command
$module->enabled = true;
$module->save();
\Cache::forget('enabled-modules');
\Cache::forget('enabled-content-modules');
\Cache::forget('enabled-modules-and-template');
$this->line('Module ' . $module->static_name . ' enabled.');
}
}
+13 -12
View File
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Modules;
use App\CMS\ModuleManager\Installer;
use App\Models\Module;
use App\ModuleManager\Installer;
use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\Cache;
@@ -15,13 +15,11 @@ class InstallModule extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:install {name} {parentModuleId?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Custom installation of CMS module. Name given as directory name in /modules.';
@@ -31,7 +29,6 @@ class InstallModule extends Command
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
@@ -56,8 +53,9 @@ class InstallModule extends Command
// get config
$config = $this->loadConfig();
if (empty($config))
if (empty($config)) {
return;
}
// check if it is valid
$this->checkMandatoryFields($config);
@@ -69,14 +67,17 @@ class InstallModule extends Command
Cache::forget('enabled-modules');
Cache::forget('module-handler-to-id-enumeration');
exec('php artisan module:enable '.$name);
exec('php artisan cache:clear');
exec('composer dump-autoload');
// inform user
$this->line('Module ' . $name . ' successfuly installed');
$this->line('Module ' . $name . ' successfuly installed.');
}
/**
* Load config from Config/config.php in module files. We cannot use config() because the file have not published
* yet.
*
* @return array
* @throws FileNotFoundException
*/
@@ -85,8 +86,9 @@ class InstallModule extends Command
$basePath = $this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR;
$path = $basePath . 'Config' . DIRECTORY_SEPARATOR . 'config.php';
if (basename($basePath) == 'Database')
if (basename($basePath) == 'Database') {
return [];
}
// check if module has Config/config.php file
if (!file_exists($path)) {
@@ -121,7 +123,6 @@ class InstallModule extends Command
/**
* Installs module into database.
*
* This method calls Module::install, which handles specific installation of module. In this way we should be able
* to install any module even with some other database structures.
*
@@ -155,9 +156,9 @@ class InstallModule extends Command
if (is_null($module)) {
// insert module into database
$settings = [
'providers' => $providers,
'order' => isset($config['order']) ? $config['order'] : 0,
'files' => isset($config['files']) ? $config['files'] : []
'providers' => $providers,
'order' => isset($config['order']) ? $config['order'] : 0,
'files' => isset($config['files']) ? $config['files'] : []
];
$module = Installer::install($name, $alias, $this->moduleName, $description, $handler, $this->parentModuleId, $settings);
@@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands\Modules;
use App\Models\Module;
use Illuminate\Console\Command;
class RunMigrations extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'module:migrate {module?} {--rollback : Rollback one migration}';
/**
* The console command description.
* @var string
*/
protected $description = 'Run migrations for all modules or for one module';
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
$modules = Module::where('enabled', true);
if (!is_null($module = $this->argument('module'))) {
$modules = $modules->where('static_name', $module);
}
$modules = $modules->get();
if ($modules->isEmpty()) {
$this->error('No valid modules.');
return;
}
$command = $this->option('rollback') ? 'migrate:rollback' : 'migrate';
foreach ($modules as $module) {
$this->info('Migrating '.$module->static_name);
$basePath = $module->is_template ? config('modules.path.templates') : config('modules.paths.modules');
$path = $basePath . '/' . $module->static_name . '/Database/Migrations/';
$path = str_replace(base_path(), '', $path);
$this->call($command, ['--path' => $path]);
}
}
}
+6 -9
View File
@@ -3,6 +3,7 @@
namespace App\Console\Commands;
use App\CMS\Enumerations\UserRoles;
use App\Events\CreateNewUser;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
@@ -11,13 +12,11 @@ class NewUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:new {email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates new user';
@@ -27,13 +26,9 @@ class NewUser extends Command
*/
public function handle()
{
$email = $this->argument('email');
// check if username is really email
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->error($email . ' is not a valid e-mail!');
return;
}
do {
$email = $this->argument('email');
} while (!filter_var($email, FILTER_VALIDATE_EMAIL));
// ask for password
do {
@@ -63,6 +58,8 @@ class NewUser extends Command
$user->role = $role;
$user->save();
event(new CreateNewUser($user));
$this->info('User ' . $email . ' successfully created.');
}
}
+4 -4
View File
@@ -2,9 +2,9 @@
namespace App\Console\Commands;
use App\CMS\ModuleManager\Installer;
use App\CMS\ModuleManager\Uninstaller;
use App\Models\Module;
use App\ModuleManager\Installer;
use App\ModuleManager\Uninstaller;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -59,7 +59,7 @@ class SetTemplate extends Command
}
try {
Installer::install($config['name'], $config['alias'], $current->static_name, $config['description'], $config['handler'], false, $config);
Installer::install($config['name'], $config['alias'], $config['staticName'], $config['description'], $config['handler'], false, $config);
} catch (\Exception $e) {
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
return;
@@ -74,7 +74,7 @@ class SetTemplate extends Command
// run again artisan for publishing resources
// it cannot be done using $this->call, because we need to load different template into service providers
if ($publish) {
exec('php artisan vendor:publish');
exec('php artisan template:publish');
}
}
}
+7 -1
View File
@@ -2,6 +2,9 @@
namespace App\Console;
use App\Console\Commands\InstallCMS;
use App\Console\Commands\Modules\CreateMigration;
use App\Console\Commands\Modules\RunMigrations;
use App\Console\Commands\Modules\CreateNew;
use App\Console\Commands\Modules\DisableModule;
use App\Console\Commands\Modules\EnableModule;
@@ -32,7 +35,10 @@ class Kernel extends ConsoleKernel
Commands\SetTemplate::class,
Commands\AddLanguage::class,
PublishTemplateResources::class,
TemplateInfo::class
TemplateInfo::class,
InstallCMS::class,
CreateMigration::class,
RunMigrations::class
];
/**
@@ -33,7 +33,7 @@ class ContentOverview extends Controller
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @internal param int|null $moduleId
*/
public function index(Module $module = null, $status = null)
public function index(Module $module, $status = null)
{
// get module settings
$pageHeading = $this->module->getOverviewTitle($module);
@@ -46,10 +46,13 @@ class ContentOverview extends Controller
// get homepage - for checking if homepage is set and available
$homepage = $this->content->getHomepage();
$contentModules = app(\App\CMS\Repositories\Module::class)->getContentModules();
return view('admin.content.overview', [
'pages' => $pages,
'homepage' => $homepage,
'pageHeading' => $pageHeading,
'contentModules' => $contentModules,
'statuses' => ContentStatuses::getWithTranslations(),
'module' => isset($module) ? $module : null
]);
@@ -1,4 +1,5 @@
<?php
namespace App\Http\Controllers\Admin\Contents;
use App\CMS\Contracts\Repositories\Content as IContent;
@@ -11,13 +12,12 @@ use App\Http\Controllers\Admin\Controller;
use App\Http\Requests\CreateNewContentRequest;
use App\Http\Requests\Request;
use App\Models\Module;
use Illuminate\Support\Collection;
use Modules\Categories\Contracts\Repositories\Category as ICategory;
/**
* Class CreateNewContent
*
* Controller for creating new content page.
*
* @package App\Http\Controllers\Admin\Contents
*/
class CreateNewContent extends Controller
@@ -30,10 +30,6 @@ class CreateNewContent extends Controller
* @var IModuleRepository
*/
private $module;
/**
* @var ICategory
*/
private $category;
/**
* @var ITemplate
*/
@@ -41,23 +37,20 @@ class CreateNewContent extends Controller
/**
* CreateNewContent constructor.
*
* Sets File and Content models into class variables
*
* @param IContent|Content $content
* @param IModuleRepository $module
* @param ICategory $category
*
* @param ITemplate $template
*
* @internal param File $file
*/
public function __construct(IContent $content, IModuleRepository $module, ICategory $category, ITemplate $template)
public function __construct(IContent $content, IModuleRepository $module, ITemplate $template)
{
parent::__construct();
$this->content = $content;
$this->module = $module;
$this->category = $category;
$this->template = $template;
}
@@ -73,7 +66,11 @@ class CreateNewContent extends Controller
$statuses = ContentStatuses::getWithTranslations();
$pageHeading = $this->module->getCreateContentTitle($module);
$templates = $this->template->getForModule($module);
$categories = $this->category->getForModule($module);
$categories = new Collection();
if (class_exists(ICategory::class)) {
$categories = app(ICategory::class)->getForModule($module);
}
$page = $this->content->getOne();
@@ -1,4 +1,5 @@
<?php
namespace App\Http\Controllers\Admin\Contents;
use App\CMS\Contracts\Repositories\Content as IContent;
@@ -6,19 +7,15 @@ use App\CMS\Contracts\Repositories\Module as IModuleRepository;
use App\CMS\Contracts\Repositories\Template as ITemplate;
use App\CMS\Enumerations\ContentStatuses;
use App\Cms\Handlers\Interactions\Interaction;
use App\CMS\Helpers\CurrentTemplate;
use App\Cms\Interactions\Admin\Content\EditContent as EditContentInteraction;
use App\Events\AttemptToEditInvalidContent;
use App\Http\Controllers\Admin\Controller;
use App\Http\Requests\EditContentRequest;
use App\Http\Requests\Request;
use App\Models\Content\Content;
use App\Models\Content\ContentHistory;
use App\Models\FileManager\File;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Collection;
use Modules\Categories\Contracts\Repositories\Category as ICategory;
use Modules\Categories\Repositories\Category;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class EditContent extends Controller
{
@@ -38,10 +35,6 @@ class EditContent extends Controller
* @var IModuleRepository
*/
private $module;
/**
* @var ICategory
*/
private $category;
/**
* @var ITemplate
*/
@@ -49,7 +42,6 @@ class EditContent extends Controller
/**
* EditContent constructor.
*
* Load ContentHistory and File into this controller
*
* @param ContentHistory $history
@@ -59,13 +51,12 @@ class EditContent extends Controller
* @param ICategory $category
* @param ITemplate $template
*/
public function __construct(ContentHistory $history, File $file, IContent $content, IModuleRepository $module, Category $category, ITemplate $template)
public function __construct(ContentHistory $history, File $file, IContent $content, IModuleRepository $module, ITemplate $template)
{
$this->history = $history;
$this->file = $file;
$this->content = $content;
$this->module = $module;
$this->category = $category;
$this->template = $template;
}
@@ -84,9 +75,13 @@ class EditContent extends Controller
$module = $this->module->getByHandler($page->moduleHandler);
$pageHeading = $this->module->getUpdateContentTitle($module, $page);
$templates = $this->template->getForModule($module);
$categories = $this->category->getForModule($module);
$history = $this->history->getStructuredHistoryOf($page);
$categories = new Collection();
if (class_exists(ICategory::class)) {
$categories = app(ICategory::class)->getForModule($module);
}
// render view
return view('admin.content.edit', [
'pageHeading' => $pageHeading,
@@ -94,7 +89,8 @@ class EditContent extends Controller
'page' => $page,
'module' => $module,
'categories' => $categories,
'rootPages' => $this->content->getOverview()->get(),
'rootPages' => $this->content->getOverview()
->get(),
'templates' => $templates,
'formSectionNames' => $this->module->call($module, 'getExtendedFormSections'),
'formSections' => $this->module->call($module, 'getExtendedFormInputsEdit'),
@@ -121,4 +117,24 @@ class EditContent extends Controller
->route('content.overview')
->with('success', trans('admin/contents.successfullyEdited'));
}
public function order() {
$pages = $this->content->getOverview()->get();
return view('admin.content.order', compact('pages'));
}
public function setOrder(Request $request) {
$data = $request->get('page');
foreach ($data as $id => $order) {
Content::where('id', $id)->update(['order' => $order]);
}
// something was changed, inform user
return redirect()
->route('content.overview')
->with('success', trans('admin/contents.orderSuccessfullySet'));
}
}
@@ -2,13 +2,22 @@
namespace App\Http\Controllers\Admin\Dashboard;
use App\CMS\Contracts\Repositories\Module;
use App\Http\Controllers\Admin\Controller;
use Illuminate\Http\Request;
use App\Models\Content\Content;
use Illuminate\Support\Facades\Auth;
class Dashboard extends Controller
{
public function index(Request $request)
public function index()
{
return redirect()->route('content.overview');
$contentModules = app(Module::class)->getContentModules();
if (\Auth::user()
->can('manage', Content::class) && !$contentModules->isEmpty()) {
return redirect()->route('content.overview');
} else {
return redirect()->route('users.detail', ['user' => Auth::user()]);
}
}
}
@@ -1,8 +1,8 @@
<?php
namespace App\Http\Controllers\Admin\FileManager;
use App\CMS\Helpers\Path;
use App\CMS\Helpers\Template;
use App\Http\Controllers\Admin\Controller;
use App\Http\Requests\Request;
use App\Models\FileManager\File;
@@ -47,7 +47,7 @@ class UploadFile extends Controller
*/
private function internalUpload(Request $request)
{
// try {
try {
$uploadedFiles = [];
$files = $request->all()['files'];
@@ -62,9 +62,9 @@ class UploadFile extends Controller
return redirect()
->back()
->with('success', trans_choice('admin/fileManager.uploadSuccessfull', $successfullUploads));
// } catch (FileException $e) {
// return $this->invalidUpload('invalidFile');
// }
} catch (FileException $e) {
return $this->invalidUpload('invalidFile');
}
}
/**
@@ -30,14 +30,12 @@ class UploadedFilesOverview extends Controller
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Directory $directory = null)
public function index(Directory $directory)
{
// dd($directory);
// include hidden directories?
$subdirectories = $this->directoryRepository->getAllSubdirectories($directory);
if (!Input::get('hidden', true)) {
if (!Input::get('hidden', false)) {
$subdirectories = $subdirectories->where('hidden', false);
}
-87
View File
@@ -1,87 +0,0 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\LoginRequest;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
/**
* Class Login
*
* @package App\Http\Controllers\Admin
*
* @todo use trait ThrottlesLogins for disabling brutal-force password cracking
*/
class Login extends Controller
{
/**
* Display login form
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getLogin()
{
return view('admin.loginForm');
}
/**
* Login handler
*
* @param LoginRequest $request
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postLogin(LoginRequest $request)
{
$email = $request->email;
// try to find user
$user = User::where('email', $email)
->where('role', '!=', User::ROLE_VISITOR)
->where('status', User::STATE_ACTIVE)
->first();
if (!$user) {
return $this->loginFailed();
}
// try to log in user
if (Hash::check($request->password, $user->password)) {
Auth::login($user);
$redirect = $request->redirectTo ? $request->redirectTo : route('admin.dashboard');
return redirect()->intended($redirect);
}
// login invalid, redirect and inform the user
return $this->loginFailed();
}
/**
* Logs out user
*
* @return \Illuminate\Http\RedirectResponse
*/
public function logout()
{
// remove user information
\Auth::logout();
// redirect to login form with info about successfull logout
return redirect()
->route('login')
->with('success', trans('admin/common.logoutSuccessfull'));
}
private function loginFailed()
{
return redirect()
->route('login')
->with('error', trans('auth.failed'))
->withInput();
}
}
@@ -0,0 +1,43 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\Request;
use App\Models\Permissions\Permission;
class Permissions extends Controller
{
/**
* Display all permissions
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$permissions = Permission::whereNull('parent_id')->get();
return view('admin/permissions.index', compact('permissions'));
}
/**
* Setup default permissions
*
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse
*/
public function setDefault(Request $request)
{
Permission::where('default', true)
->update(['default' => false]);
$permissions = $request->permissions;
Permission::whereIn('string_id', array_keys($permissions))
->update(['default' => true]);
return redirect()
->back()
->with('success', trans('admin/permissions.defaultSuccessfullySet'));
}
}
+7 -3
View File
@@ -13,7 +13,6 @@ class Search extends Controller
{
/**
* Create form for searching
*
* @return $this|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getSearch()
@@ -37,7 +36,6 @@ class Search extends Controller
/**
* Method used for performing search.
*
* This method iterates over all registered search engines and returns results for each engine apart.
*
* @param string $term search text
@@ -60,10 +58,16 @@ class Search extends Controller
// try to find given term
$results = $search->search($term);
$content = $presenter->render($results);
if (is_null($content)) {
continue;
}
// create result object
$resultsParts[$search->getId()] = [
'name' => $search->getName(),
'content' => $presenter->render($results),
'content' => $content,
'count' => count($results)
];
}
+1
View File
@@ -52,6 +52,7 @@ class Settings extends Controller
*/
public function saveSettings(Requests\SaveSettingsRequest $request)
{
$this->settings->save($request->except(['_token']));
return redirect()
@@ -98,7 +98,7 @@ class EditTemplate extends Controller
// try to save content
if (!is_writable($customDir) && !is_writable($originalDir)) {
return redirect()
->route('templates.edit', ['id' => $request->id])
->route('templates.edit', ['id' => $template->id])
->withInput()
->with('warning', trans('admin/templates.cannotWriteContent'));
}
@@ -7,6 +7,16 @@ use App\Models\Templates\TemplatePath;
class TemplateOverview extends Controller
{
public function index()
{
$templatePaths = TemplatePath::with('subdirectories')
->whereNull('parent_id')
->get();
return view('admin.templates.index', compact('templatePaths'));
}
/**
* Display overview of all templates in given path
*
@@ -17,12 +27,8 @@ class TemplateOverview extends Controller
public function getPath(TemplatePath $templatePath)
{
return view('admin.templates.list', [
'directory' => $templatePath,
'isWritable' => is_writable(base_path($templatePath->path)),
'templates' => $templatePath->templates()
->get(),
'subdirectories' => $templatePath->subdirectories()
->get()
'directory' => $templatePath,
'isWritable' => is_writable(base_path($templatePath->path))
]);
}
}
+34 -1
View File
@@ -8,8 +8,11 @@ use App\CMS\Repositories\Users\User as UserRepository;
use App\Events\EditUser as EditUserEvent;
use App\Http\Controllers\Admin\Controller;
use App\Http\Requests\EditUserRequest;
use App\Http\Requests\Request;
use App\Models\Permissions\Permission;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
class EditUser extends Controller
@@ -39,7 +42,7 @@ class EditUser extends Controller
public function getEditUser(User $user = null)
{
// when no user specified, lets assume we want to edit "me"
if (!$user->exists()) {
if (!$user->exists) {
$user = Auth::user();
}
@@ -82,4 +85,34 @@ class EditUser extends Controller
->back()
->with('success', trans('admin/userManagement.userSuccessfullyEdited'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function setPermissions(Request $request, User $user)
{
$permissionIds = $request->get('permissions', []);
$permissions = Permission::whereIn('string_id', array_keys($permissionIds))
->get();
DB::transaction(function () use ($user, $permissions) {
// remove all permissions
$user->permissions()
->detach();
foreach ($permissions as $permission) {
$user->permissions()
->attach($permission->id);
}
});
return redirect()
->back()
->with('success', trans('admin/permissions.successfullySet'));
}
}
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Users;
use App\CMS\Enumerations\UserRoles;
use App\CMS\Enumerations\UserStates;
use App\Cms\Repositories\ActionLog\Actions;
use App\CMS\Repositories\Permissions\Permission;
use App\Http\Controllers\Admin\Controller;
use App\Models\ActionLog\ActionLog;
use App\Models\User;
@@ -25,19 +26,21 @@ class UserDetail extends Controller
public function getDetail(User $user = null)
{
// when no user specified, lets assume we want to edit "me"
if (!$user->exists()) {
$id = Auth::user();
if (!$user->exists) {
$user = Auth::user();
}
$actions = $this->log->getUserActions($user->id, 10);
$roles = UserRoles::getWithTranslations();
$states = UserStates::getWithTranslations();
$permissions = app(Permission::class)->getRootPermissions();
return view('admin.userManagement.detail', [
'user' => $user,
'statuses' => $states,
'roles' => $roles,
'actions' => $actions
'user' => $user,
'statuses' => $states,
'roles' => $roles,
'actions' => $actions,
'permissions' => $permissions
]);
}
}
@@ -40,7 +40,6 @@ class EditWidgetArea extends Controller
*/
public function edit(WidgetArea $widgetArea)
{
return view("test");
$associatedWidgetIds = WidgetInWidgetArea::getWidgetIdsFromArea($widgetArea->id);
$widgets = Widget::where('language', LaravelLocalization::getCurrentLocale())
->paginate(25);
@@ -1,17 +1,25 @@
<?php
namespace App\Http\Controllers\Admin\Widgets;
use App\Http\Controllers\Admin\Controller;
use App\Models\Widgets\Widget;
use App\Models\Widgets\WidgetType;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class WidgetsOverview extends Controller
{
/**
* Display list of all widgets
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$widgets = Widget::where('language', LaravelLocalization::getCurrentLocale())
->paginate(25);
return view('admin.widgets.overview', ['widgets' => $widgets]);
$widgetTypes = WidgetType::all();
return view('admin.widgets.overview', compact('widgetTypes', 'widgets'));
}
}
@@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
@@ -0,0 +1,46 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/admin';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function logout() {
Auth::logout();
return redirect()->route('login');
}
}
@@ -0,0 +1,73 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
*
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'g-recaptcha-response' => 'required|recaptcha',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
*
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'role' => User::ROLE_VISITOR,
'state' => User::STATE_ACTIVE,
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = '/admin';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
+17 -3
View File
@@ -14,7 +14,6 @@ class Controller extends BaseController
/**
* Custom wrapper for generating view.
*
* This method will be used for switching among templates.
*
* @param $template
@@ -25,8 +24,23 @@ class Controller extends BaseController
*/
public static function visitorsView($template, $data = [], $mergeData = [])
{
$view = Template::name($template);
$view = self::getView($template, $data, $mergeData);
return response(view($view, $data, $mergeData))->header('X-Powered-By', strrev('zc.ytiranib.www//:sptth | .o.r.s ytiranib | SMCiniM'));
return response($view)->header('X-Powered-By', strrev('zc.ytiranib.www//:sptth | .o.r.s ytiranib | SMCiniM'));
}
/**
* Get instance of view for passing into response
*
* @param $template
* @param $data
* @param $mergeData
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public static function getView($template, $data = [], $mergeData = [])
{
$view = Template::name($template);
return view($view, $data, $mergeData);
}
}
+2 -3
View File
@@ -1,9 +1,9 @@
<?php
namespace App\Http\Controllers;
namespace App\Http\Controllers\Visitor;
use App\CMS\Contracts\Repositories\Content;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class Sitemap extends Controller
{
@@ -24,7 +24,6 @@ class Sitemap extends Controller
/**
* Get sitemap for all content pages
*
* @return mixed
*/
public function getMap()
+12 -9
View File
@@ -2,8 +2,9 @@
namespace App\Http;
use App\Http\Middleware\TemplatePathInstaller;
use App\Http\Middleware\WidgetInstaller;
use App\Http\Middleware\TemplateChecker;
use App\Http\Middleware\Web\IncrementWidgetsViews;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
@@ -36,13 +37,15 @@ class Kernel extends HttpKernel
protected $middlewareGroups = [
'web' => [
CheckForMaintenanceMode::class,
TemplateChecker::class,
AddQueuedCookiesToResponse::class,
IncrementWidgetsViews::class,
],
'admin' => [
Middleware\Authenticate::class,
Middleware\AdminMenuRegistrator::class,
TemplatePathInstaller::class,
WidgetInstaller::class,
Middleware\Admin\Authenticate::class,
Middleware\Admin\AdminMenuRegistrator::class,
Middleware\Admin\TemplatePathInstaller::class,
Middleware\Admin\WidgetInstaller::class,
],
'api' => [
'throttle:60,1',
@@ -54,9 +57,9 @@ class Kernel extends HttpKernel
* @var array
*/
protected $routeMiddleware = [
'auth' => Middleware\Authenticate::class,
'onlyAdmin' => Middleware\RequireAdminRole::class,
'adminMenu' => Middleware\AdminMenuRegistrator::class,
'can' => Authorize::class,
'auth' => Middleware\Admin\Authenticate::class,
'adminMenu' => Middleware\Admin\AdminMenuRegistrator::class,
'guest' => Middleware\RedirectIfAuthenticated::class,
'throttle' => ThrottleRequests::class,
'localize' => LaravelLocalizationRoutes::class,
@@ -1,9 +1,9 @@
<?php
namespace App\Http\Middleware;
namespace App\Http\Middleware\Admin;
use App\CMS\Handlers\Handler;
use App\Models\Module;
use App\CMS\Handlers\AdminHandler;
use App\CMS\Repositories\Module as ModuleRepository;
use Closure;
use Illuminate\Support\Facades\Log;
@@ -26,15 +26,15 @@ class AdminMenuRegistrator
// create menu
$user = \Auth::user();
Handler::registerAdminMenu($user);
AdminHandler::registerAdminMenu($user);
$modules = Module::where('enabled', true)
->get();
$modules = app(ModuleRepository::class)->all();
// iterate over all enabled modules
foreach ($modules as $key => $module) {
if (!is_callable([$module->handler, 'registerAdminMenu']))
if (!is_callable([$module->handler, 'registerAdminMenu'])) {
continue;
}
// try to register menus
try {
@@ -0,0 +1,46 @@
<?php
namespace App\Http\Middleware\Admin;
use App\Models\User;
use Closure;
use Illuminate\Support\Facades\Auth;
class Authenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (!Auth::guard($guard)
->check() || Auth::user()->status != User::STATE_ACTIVE || Auth::user()->role == User::ROLE_VISITOR || 0) {
Auth::logout();
if ($request->ajax()) {
return response('Unauthorized.', 401);
}
// select right message
if (Auth::user() && Auth::user()->status != User::STATE_ACTIVE) {
$message = 'auth.userNotActive';
} elseif (Auth::user() && Auth::user()->role == User::ROLE_VISITOR) {
$message = 'auth.visitorInAdmin';
} else {
$message = 'auth.loginExpired';
}
return redirect()
->route('login')
->with('warning', trans($message));
}
return $next($request);
}
}
@@ -1,6 +1,6 @@
<?php
namespace App\Http\Middleware;
namespace App\Http\Middleware\Admin;
use App\CMS\Handlers\Registrators\TemplateRegistrator;
use Closure;
@@ -26,6 +26,8 @@ class TemplatePathInstaller
// install registered widgets
$registator->saveTemplates();
$registator->deleteNonExistingPaths();
return $next($request);
}
}
@@ -1,6 +1,6 @@
<?php
namespace App\Http\Middleware;
namespace App\Http\Middleware\Admin;
use App\CMS\Handlers\Registrators\WidgetRegistrator;
use Closure;
-33
View File
@@ -1,33 +0,0 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class Authenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (!Auth::guard($guard)->check()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
}
return redirect()
->route('login')
->with('redirectTo', $request->fullUrl());
}
return $next($request);
}
}
@@ -2,10 +2,10 @@
namespace App\Http\Middleware;
use App\Models\User;
use App\CMS\Helpers\CurrentTemplate;
use Closure;
class RequireAdminRole
class TemplateChecker
{
/**
* Handle an incoming request.
@@ -17,10 +17,10 @@ class RequireAdminRole
*/
public function handle($request, Closure $next)
{
if (\Auth::user()->role != User::ROLE_ADMIN) {
return redirect()
->back()
->with('error', trans('auth.accessDenied'));
$template = CurrentTemplate::get();
if (!$template) {
throw new \ErrorException('Template is not set, cannot continue');
}
return $next($request);
@@ -0,0 +1,36 @@
<?php
namespace App\Http\Middleware\Web;
use App\CMS\Helpers\WidgetAreas;
use App\Models\Widgets\WidgetArea;
use Closure;
class IncrementWidgetsViews
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request);
}
public function terminate($request, $response)
{
// if (!setting('useWidgetPreloading', false))
// return;
$widgets = WidgetAreas::getLoadedWidgets();
if (!empty($widgets['areas'])) {
WidgetArea::whereIn('code', $widgets['areas'])
->increment('viewed');
}
}
}
-75
View File
@@ -1,75 +0,0 @@
<?php
/**
* This routing groups is used for routing along public part of website
*/
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
Route::pattern('id', '\d+');
Route::pattern('url', '[0-9\-a-z]+');
/*******************************************************************************/
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['bindings']], function () {
/**
* This route group serves to handle request in admin
*/
Route::group([
'middleware' => ['admin'],
'namespace' => 'Admin',
'prefix' => 'admin'
], function () {
// include all routes in routes/admin subfolder
$files = ['contents', 'fileManager', 'settings', 'templates', 'users', 'widgets'];
foreach ($files as $file) {
require_once __DIR__ . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $file . '.php';
}
// display dashboard with some usefull information
Route::get('/', 'Dashboard\Dashboard@index')
->name('admin.dashboard');
// list of all actions
Route::get('actions', 'ActionLog\Overview@index')
->name('log.overview');
// search form with results
Route::get('search', 'Search@getSearch')
->name('search');
// logout method
Route::get('logout', 'Login@logout')
->name('logout');
});
/**************************************************************************************/
/**
* This section must be specified as last one
*/
Route::group(['middleware' => ['web']], function () {
// Homepage
Route::get('/', 'Visitor\Homepage@getIndex')
->name('page.index');
// display login form
Route::get('admin/login', 'Admin\Login@getLogin')
->name('loginForm');
// handle login
Route::post('admin/login', 'Admin\Login@postLogin')
->name('login');
// route for sitemap
Route::get('sitemap.xml', 'Visitor\Sitemap@getMap')
->name('sitemap');
// route for all content pages. This rule must be specified last (because it matches every route)
Route::get('{url}', 'Visitor\ContentPage@getPage')
->name('page.content');
});
});

Some files were not shown because too many files have changed in this diff Show More