Compare commits
61
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2502a2355 | ||
|
|
2d60010f9e | ||
|
|
3275e5aeed | ||
|
|
a7e91ef499 | ||
|
|
638f6ef134 | ||
|
|
e9e9f0976c | ||
|
|
5707750f5b | ||
|
|
72c64dc6d1 | ||
|
|
f876a08429 | ||
|
|
f48c0cfac3 | ||
|
|
e262473f36 | ||
|
|
4a5c9ab1e6 | ||
|
|
e41c589225 | ||
|
|
870ca540c4 | ||
|
|
2e8f8dca1f | ||
|
|
8167b151d5 | ||
|
|
ad8a6e3c61 | ||
|
|
74f1501af6 | ||
|
|
217d78f214 | ||
|
|
16532faa5b | ||
|
|
ead55a8165 | ||
|
|
e943120dc6 | ||
|
|
dd978c05f7 | ||
|
|
348883603a | ||
|
|
5de8e01d77 | ||
|
|
5d623a1a62 | ||
|
|
69253693ce | ||
|
|
42066d4ae9 | ||
|
|
52f39fda0c | ||
|
|
9cb4deecd4 | ||
|
|
fcd7651841 | ||
|
|
09daba1dc1 | ||
|
|
66e5d649be | ||
|
|
78532a6832 | ||
|
|
1f633c3281 | ||
|
|
8658ea1d39 | ||
|
|
ce58b325c8 | ||
|
|
ed8e2565ff | ||
|
|
87af6a018c | ||
|
|
0e2aecb529 | ||
|
|
9bec808d38 | ||
|
|
55f9c0a679 | ||
|
|
03ce64a731 | ||
|
|
450000fadd | ||
|
|
44fb6b1be5 | ||
|
|
09c87661d3 | ||
|
|
0007425c86 | ||
|
|
2a15f3eab5 | ||
|
|
57f9c21a43 | ||
|
|
eff61a1481 | ||
|
|
4128fcf88e | ||
|
|
4353345b3e | ||
|
|
455b9d6d4e | ||
|
|
77685b491e | ||
|
|
f90df0f4bc | ||
|
|
93fc9316a4 | ||
|
|
26854b7207 | ||
|
|
8db748089b | ||
|
|
507e186713 | ||
|
|
5132278ee1 | ||
|
|
c64f825886 |
+1
-1
@@ -16,4 +16,4 @@ MAIL_PASSWORD=
|
||||
|
||||
SITE_URL=/
|
||||
UPLOAD_URL=/public/uploads
|
||||
THUMBNAILS_URL=/uploads/thumbnails
|
||||
THUMBNAIL_URL=/public/uploads/thumbnails
|
||||
@@ -5,27 +5,6 @@ use App\Http\Requests\Request;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
interface AdvancedContentModifier {
|
||||
/**
|
||||
* Save module-specific values into database
|
||||
*
|
||||
* @param Content $content
|
||||
* @param array $inputData
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function createNew(Content &$content, array $inputData);
|
||||
|
||||
/**
|
||||
* Method used for editing existing content page.
|
||||
*
|
||||
* Reason why it is separated from createNew() method is simple - we need to save history of changes.
|
||||
*
|
||||
* @param Content $content
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function edit(Content $content, $request);
|
||||
/**
|
||||
* Method called right after content page is marked as deleted
|
||||
*
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Content\DisplayPipeline;
|
||||
|
||||
use App\Models\Content\Content;
|
||||
|
||||
interface Pipeline {
|
||||
/**
|
||||
* Add new process into pipeline
|
||||
*
|
||||
* @param string $process
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function add($process);
|
||||
function run(Content $page);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Content\DisplayPipeline;
|
||||
|
||||
use App\Models\Content\Content;
|
||||
|
||||
interface Process {
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $page
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function handle(Content & $page);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Content\SavePipeline;
|
||||
|
||||
use App\Models\Content\Content;
|
||||
|
||||
interface Pipeline {
|
||||
/**
|
||||
* Add new process into pipeline
|
||||
*
|
||||
* @param string $process
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function add($process);
|
||||
|
||||
/**
|
||||
* Save content page
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*
|
||||
* @return Content
|
||||
*/
|
||||
function run(Content & $page, array $input);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Content\SavePipeline;
|
||||
|
||||
use App\Models\Content\Content;
|
||||
|
||||
interface Process {
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function handle(Content & $page, array & $input);
|
||||
}
|
||||
@@ -6,16 +6,6 @@ use App\Models\Content\Content;
|
||||
|
||||
interface AppHandler extends BaseModuleHandler
|
||||
{
|
||||
/**
|
||||
* Render given module into visitor area.
|
||||
*
|
||||
* @param Content $content DB model from table contents
|
||||
* @param array $parameters parameters used for modifications/custom settings of given model
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function render(Content $content, $parameters);
|
||||
|
||||
public static function getHistoryHandler();
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,28 +27,4 @@ interface TemplateHandler extends BaseModuleHandler
|
||||
* @return array
|
||||
*/
|
||||
public static function getPublicTemplatePaths();
|
||||
|
||||
/**
|
||||
* Prepare Content object to be rendered using Blade template
|
||||
*
|
||||
* @param Content $content
|
||||
*/
|
||||
public static function beforeRender(Content & $content);
|
||||
|
||||
/**
|
||||
* Modify input data into format which can be understood by edit template
|
||||
*
|
||||
* @param Content $content
|
||||
*/
|
||||
public static function beforePopulatingEditForm(Content & $content);
|
||||
|
||||
/**
|
||||
* Slightly modify Content object before saving into database.
|
||||
*
|
||||
* This way we can do almost whatever we want - even in template
|
||||
*
|
||||
* @param Content $content
|
||||
* @param $request
|
||||
*/
|
||||
public static function beforeSave(Content & $content, $request);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ interface Template
|
||||
|
||||
public function setModel(TemplateModel $model);
|
||||
|
||||
public function getPathToTemplate();
|
||||
public function getPathToTemplate($mode = null);
|
||||
|
||||
public function getForModule(ModuleModel $module);
|
||||
}
|
||||
@@ -20,19 +20,6 @@ abstract class Handler extends BaseHandler implements AppHandler
|
||||
return History::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render given module into visitor area.
|
||||
*
|
||||
* @param Content $content DB model from table contents
|
||||
* @param array $parameters parameters used for modifications/custom settings of given model
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function render(Content $content, $parameters)
|
||||
{
|
||||
return Controller::VisitorsView($content->template, ['page' => $content, 'extra' => $parameters]);
|
||||
}
|
||||
|
||||
public static function getExtendedFormSections()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Registrators;
|
||||
|
||||
use App\CMS\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\CMS\Exceptions\Enumerations\EnumerationExistsException;
|
||||
use App\CMS\Handlers\Contracts\SearchHandler;
|
||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\CMS\Handlers\Registrators\Items\SearchEngine;
|
||||
|
||||
@@ -22,16 +22,9 @@ class CurrentTemplate implements TemplateHandler
|
||||
{
|
||||
if (!self::$initialized) {
|
||||
self::$template = Cache::rememberForever('current-template', function () {
|
||||
$template = Module::where('is_template', true)
|
||||
return Module::where('is_template', true)
|
||||
->where('enabled', true)
|
||||
->first();
|
||||
|
||||
// todo remove after adding $casts into Module model
|
||||
if ($template) {
|
||||
$template->module_settings = json_decode($template->module_settings);
|
||||
}
|
||||
|
||||
return $template;
|
||||
});
|
||||
|
||||
|
||||
@@ -96,37 +89,4 @@ class CurrentTemplate implements TemplateHandler
|
||||
{
|
||||
return call_user_func([self::handler(), 'getPublicTemplatePaths']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare Content object to be rendered using Blade template
|
||||
*
|
||||
* @param Content $content
|
||||
*/
|
||||
public static function beforeRender(Content & $content)
|
||||
{
|
||||
call_user_func_array([self::handler(), 'beforeRender'], [&$content]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify input data into format which can be understood by edit template
|
||||
*
|
||||
* @param Content $content
|
||||
*/
|
||||
public static function beforePopulatingEditForm(Content & $content)
|
||||
{
|
||||
call_user_func_array([self::handler(), 'beforePopulatingEditForm'], [&$content]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slightly modify Content object before saving into database.
|
||||
*
|
||||
* This way we can do almost whatever we want - even in template
|
||||
*
|
||||
* @param Content $content
|
||||
* @param $request
|
||||
*/
|
||||
public static function beforeSave(Content & $content, $request)
|
||||
{
|
||||
call_user_func_array([self::handler(), 'beforeSave'], [&$content, $request]);
|
||||
}
|
||||
}
|
||||
@@ -29,11 +29,8 @@ class PageRenderer
|
||||
/**
|
||||
* @var $handler AppHandler
|
||||
*/
|
||||
// get handler
|
||||
$handler = new $page->moduleHandler;
|
||||
|
||||
$page->content = Shortcode::compile($page->content);
|
||||
|
||||
// render page
|
||||
return $handler->render($page, $parameters);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
use App\CMS\Repositories\Widgets\WidgetArea as WidgetAreaRepository;
|
||||
use App\Models\Widgets\WidgetArea;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
@@ -25,15 +27,16 @@ class WidgetAreas
|
||||
|
||||
protected static function loadWidgetArea($uniqueCode)
|
||||
{
|
||||
$widgets = Cache::remember('widget-' . $uniqueCode, setting('widgetCacheLifetime', 5), function () use ($uniqueCode) {
|
||||
$widgetArea = new WidgetArea();
|
||||
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);
|
||||
|
||||
return $widgetArea->getWidgets($uniqueCode)
|
||||
->get();
|
||||
});
|
||||
|
||||
WidgetArea::where('code', $uniqueCode)
|
||||
->increment('viewed');
|
||||
|
||||
self::saveRenderedWidgetArea($widgets);
|
||||
}
|
||||
|
||||
@@ -44,7 +47,7 @@ class WidgetAreas
|
||||
}
|
||||
|
||||
$widgets = Cache::remember('widgets', setting('widgetCacheLifetime', 5), function () {
|
||||
$widgetArea = new WidgetArea();
|
||||
$widgetArea = app(WidgetAreaRepository::class);
|
||||
return $widgetArea->getWidgets()
|
||||
->get();
|
||||
});
|
||||
@@ -58,7 +61,7 @@ class WidgetAreas
|
||||
*
|
||||
* @param $uniqueCode
|
||||
*
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public static function render($uniqueCode)
|
||||
{
|
||||
@@ -66,6 +69,8 @@ class WidgetAreas
|
||||
self::initWidgetAreas();
|
||||
}
|
||||
|
||||
// dd($uniqueCode);
|
||||
|
||||
if (!isset(self::$widgetAreas[$uniqueCode])) {
|
||||
self::loadWidgetArea($uniqueCode);
|
||||
}
|
||||
|
||||
@@ -37,32 +37,18 @@ class EditContent implements Interaction
|
||||
* @param array $data
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed|void
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($data, $parameters)
|
||||
{
|
||||
/**
|
||||
* @var $page Content
|
||||
*/
|
||||
list($page, $titlePhoto, $relatedFiles) = $parameters;
|
||||
list($page) = $parameters;
|
||||
|
||||
// let template to modify request and content page
|
||||
CurrentTemplate::beforeSave($page, $data);
|
||||
app('saveContentPipeline')->run($page, $data);
|
||||
|
||||
// upload file - if provided
|
||||
$data['titlePhoto'] = isset($data['existingTitlePhoto']) ? $data['existingTitlePhoto'] : null;
|
||||
|
||||
if (!is_null($titlePhoto)) {
|
||||
$file = $this->file->upload($titlePhoto);
|
||||
$data['titlePhoto'] = $file ? $file['filename'] : null;
|
||||
}
|
||||
|
||||
$page->update($data);
|
||||
$this->module->callOnString($page->moduleHandler, 'edit', [$page, $data]);
|
||||
|
||||
// move to interaction
|
||||
$keepAssigned = isset($data->keepAssigned) ? $data->keepAssigned : [];
|
||||
$page->uploadRelatedFiles($relatedFiles, $keepAssigned);
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,29 +43,14 @@ class NewContent implements Interaction
|
||||
*/
|
||||
public function handle($data, $parameters)
|
||||
{
|
||||
list($moduleHandler, $titlePhoto, $relatedFiles) = $parameters;
|
||||
|
||||
// upload file - if provided
|
||||
$file = !is_null($titlePhoto) ? $this->file->upload($titlePhoto) : null;
|
||||
list($moduleHandler) = $parameters;
|
||||
|
||||
$data['userId'] = \Auth::user()->id;
|
||||
$data['language'] = LaravelLocalization::getCurrentLocale();
|
||||
$data['titlePhoto'] = $file ? $file['filename'] : null;
|
||||
$data['moduleHandler'] = $moduleHandler;
|
||||
|
||||
$page = Content::create($data);
|
||||
|
||||
// save module-specific stuff
|
||||
$this->module->callOnString($moduleHandler, 'createNew', [&$page, $data]);
|
||||
|
||||
// let template to modify data and content page
|
||||
CurrentTemplate::beforeSave($page, $data);
|
||||
|
||||
// save content of page before (possible) uploading related files
|
||||
$page->save();
|
||||
|
||||
// upload files assigned to content page
|
||||
$page->uploadRelatedFiles($relatedFiles);
|
||||
$page = new Content();
|
||||
app('saveContentPipeline')->run($page, $data);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
@@ -31,22 +31,13 @@ class CreateDirectory implements Interaction
|
||||
{
|
||||
$data['parentDirectory'] = isset($data['parentDirectory']) ? $data['parentDirectory'] : null;
|
||||
|
||||
// todo this should probably go into validation, but we are not able to get $data in getValidationRules
|
||||
// check if created folder does not exist in current directory
|
||||
if ($this->repository->checkIfNameExists($data['name'], $data['parentDirectory'])) {
|
||||
throw new SubdirectoryExistsInDirectory();
|
||||
}
|
||||
|
||||
// todo use Directory::create() and rename columns/fields in request
|
||||
// create new database entry
|
||||
$directory = new Directory();
|
||||
$directory->name = $data['name'];
|
||||
$directory->parent_id = $data['parentDirectory'];
|
||||
$directory->user_id = \Auth::user()->id;
|
||||
$directory->description = $data['description'];
|
||||
$directory->save();
|
||||
|
||||
return $directory;
|
||||
return $this->repository->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\MenuItem;
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
use Nwidart\Menus\MenuItem;
|
||||
use Nwidart\Menus\Presenters\Presenter;
|
||||
|
||||
class FoundationDrilldownMenuPresenter extends Presenter
|
||||
{
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
use Nwidart\Menus\Presenters\Presenter;
|
||||
|
||||
class FoundationDropdownMenuPresenter extends Presenter
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\MenuItem;
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
use Nwidart\Menus\MenuItem;
|
||||
use Nwidart\Menus\Presenters\Presenter;
|
||||
|
||||
class MetismenuPresenter extends Presenter
|
||||
{
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\MenuItem;
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
use Nwidart\Menus\MenuItem;
|
||||
use Nwidart\Menus\Presenters\Presenter;
|
||||
|
||||
|
||||
class ProfileMenuPresenter extends Presenter
|
||||
{
|
||||
|
||||
+4
-8
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
namespace App\CMS\Modules\ServiceProviders;
|
||||
|
||||
abstract class ModuleServiceProvider extends ServiceProvider
|
||||
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
||||
|
||||
abstract class ServiceProvider extends LaravelServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
@@ -20,7 +20,6 @@ abstract class ModuleServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
@@ -35,7 +34,6 @@ abstract class ModuleServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConfig()
|
||||
@@ -50,7 +48,6 @@ abstract class ModuleServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerViews()
|
||||
@@ -69,7 +66,6 @@ abstract class ModuleServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerTranslations()
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '$Module$',
|
||||
'translatedName' => '$module$::$module$.name',
|
||||
'translatedDescription' => '$module$::$module$.description',
|
||||
'alias' => 'categories',
|
||||
'handler' => \Modules\$Module$\Handlers\$Module$Handler::class,
|
||||
'providers' => [\Modules\$Module$\Providers\$Module$ServiceProvider::class],
|
||||
'files' => ['Http/routes.php'],
|
||||
'order' => 0,
|
||||
];
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Modules\$ModuleNamespace$\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class $Entity$ extends Model {
|
||||
// ...
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\$ModuleNamespace$\Handlers;
|
||||
|
||||
use App\CMS\Contracts\Content\ContentTitles;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
class $Module$ContentHandler extends $Module$Handler implements ContentTitles
|
||||
{
|
||||
/**
|
||||
* Get translated title for pages overview of given type.
|
||||
* This value is used for rendering list of all content pages of given type in administration.
|
||||
* @return string
|
||||
*/
|
||||
public static function getOverviewTitle()
|
||||
{
|
||||
// TODO: Implement getOverviewTitle() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Title displayed above for for creating new content page
|
||||
* @return string
|
||||
*/
|
||||
public static function getCreateNewTitle()
|
||||
{
|
||||
// TODO: Implement getCreateNewTitle() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Title for form displayed for editin content page
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getEditTitle(Content $content)
|
||||
{
|
||||
// TODO: Implement getEditTitle() method.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\$ModuleNamespace$\Handlers;
|
||||
|
||||
use App\CMS\Handlers\Handler;
|
||||
use App\Models\User;
|
||||
|
||||
class $Module$Handler extends Handler
|
||||
{
|
||||
/**
|
||||
* Register admin menu
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public static function registerAdminMenu(User $user)
|
||||
{
|
||||
// register links in admin menu
|
||||
$menu = \Menu::instance('mainMenu');
|
||||
|
||||
$menu->dropdown(trans('$module$::$module$.name'), function ($submenu) use ($user) {
|
||||
$submenu->route('$module$.overview', trans('$module$::$module$.overview'), [], 20, ['icon' => 'fa fa-fw fa-list']);
|
||||
$submenu->route('$module$.new', trans('$module$::$module$.new'), [], 21, ['icon' => 'fa fa-fw fa-plus']);
|
||||
}, 15, ['icon' => 'fa fa-fw']);
|
||||
|
||||
|
||||
|
||||
// TODO: add admin menu entries
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this module support categories?
|
||||
* @return boolean
|
||||
*/
|
||||
public static function supportCategories()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\$ModuleNamespace$\Http\Controllers\Admin;
|
||||
|
||||
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;
|
||||
|
||||
class $Module$ extends Controller
|
||||
{
|
||||
/**
|
||||
* @var $Module$Repository
|
||||
*/
|
||||
private $$module$Repository;
|
||||
|
||||
public function __construct($Module$Repository $$module$Repository)
|
||||
{
|
||||
$this->$module$Repository = $$module$Repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$items = $Entity$Entity::all();
|
||||
|
||||
return view('$module$::admin/index', compact('items'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for updating entity
|
||||
*
|
||||
* @param $Entity$Entity $entity
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($Entity$Entity $entity)
|
||||
{
|
||||
return view('$module$::admin/update', compact('entity'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update existing entity
|
||||
*
|
||||
* @param Update$Entity$ $request
|
||||
* @param $Entity$Entity $item
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Update$Entity$ $request, $Entity$Entity $entity)
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
$this->$module$Repository->update($entity, $request->all());
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('$module$.$module.successfullyUpdated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for creating new entity
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create() {
|
||||
$entity = new $Entity$Entity();
|
||||
|
||||
return view('$module$::admin/create', compact('entity'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance of entity
|
||||
*/
|
||||
public function store(Create$Entity$ $request) {
|
||||
// ...
|
||||
|
||||
$this->$module$Repository->create($request->all());
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('$module$.$module.successfullyUpdated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete entity
|
||||
*
|
||||
* @param $Entity$ $entity
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($Entity$ $entity) {
|
||||
$entity->delete();
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('$module$.$module.successfullyDeleted'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Modules\$ModuleNamespace$\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class Create$Entity$ extends Request {
|
||||
public function rules()
|
||||
{
|
||||
return parent::rules();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Modules\$ModuleNamespace$\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class Update$Entity$ extends Request {
|
||||
public function rules()
|
||||
{
|
||||
return parent::rules();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
\Route::group([
|
||||
'prefix' => \LaravelLocalization::setLocale() . '/admin/$module$',
|
||||
'middleware' => ['admin'],
|
||||
'namespace' => 'Modules\$Module$\Http\Controllers\Admin'
|
||||
], function () {
|
||||
Route::get('/', '$Module$@index')
|
||||
->name('$module$.overview');
|
||||
|
||||
Route::get('/new', '$Module$@create')
|
||||
->name('$module$.new');
|
||||
|
||||
Route::post('/new', '$Module$@store')
|
||||
->name('$module$.postNew');
|
||||
|
||||
Route::get('/edit/{id}', '$Module$@edit')
|
||||
->name('$module$.edit');
|
||||
|
||||
Route::post('/edit/{id}', '$Module$@update')
|
||||
->name('$module$.postEdit');
|
||||
|
||||
Route::get('/delete/{id}', '$Module$@delete')
|
||||
->name('$module$.delete');
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\$Module$\Providers;
|
||||
|
||||
use App\CMS\Contracts\Modules\ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class $Module$ServiceProvider
|
||||
*
|
||||
* Service provider for module $Module$
|
||||
*
|
||||
* @package Modules\$Module$\Providers
|
||||
*/
|
||||
class $Module$ServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Set module Alias
|
||||
*/
|
||||
protected function setModuleAlias()
|
||||
{
|
||||
$this->alias = strtolower('$module$');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set path to module
|
||||
*/
|
||||
protected function setModulePath()
|
||||
{
|
||||
$this->path = __DIR__;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Modules\$ModuleNamespace$\Repositories;
|
||||
|
||||
use $EntityNamespace$\$Entity$ as $Entity$Entity;
|
||||
|
||||
class $Module$Repository {
|
||||
/**
|
||||
* Create new instance of entity
|
||||
*
|
||||
* @param $data
|
||||
*/
|
||||
public function create($data) {
|
||||
$Entity$Entity::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update entity
|
||||
*
|
||||
* @param $Entity$Entity $entity
|
||||
*/
|
||||
public function update($Entity$Entity $entity, $data) {
|
||||
$entity->update($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '$Module$',
|
||||
'new' => 'Vytvořit nový',
|
||||
'description' => '',
|
||||
'successfullyUpdated' => 'Úspěšně upraveno.',
|
||||
'successfullyCreated' => 'Úspěšně vytvořeno.',
|
||||
'successfullyDeleted' => 'Úspěšně smazáno.',
|
||||
'overview' => 'Přehled',
|
||||
'noItems' => 'Žádná data.',
|
||||
'save' => 'Uložit'
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('$module$::$module$.name'))
|
||||
|
||||
@section('content')
|
||||
@include('$module$::admin/form', ['action' => route('$module$.new')])
|
||||
@endsection
|
||||
@@ -0,0 +1,7 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('$module$::$module$.name'))
|
||||
|
||||
@section('content')
|
||||
@include('$module$::admin/form', ['action' => route('$module$.update')])
|
||||
@endsection
|
||||
@@ -0,0 +1,6 @@
|
||||
<form action="{{$action}}" method="post">
|
||||
|
||||
{{--...--}}
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="@lang('$module$::$module$.save')">
|
||||
</form>
|
||||
@@ -0,0 +1,17 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('$module$::$module$.overview'))
|
||||
|
||||
@section('content')
|
||||
@if (!empty($items))
|
||||
<table>
|
||||
@foreach($items as $item)
|
||||
|
||||
@endforeach
|
||||
</table>
|
||||
@else
|
||||
<div class="alert alert-info">
|
||||
<em>@trans('$module$::$module$.noItems')</em>
|
||||
</div>
|
||||
@endif
|
||||
@endsection
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace App\CMS\Pipeline;
|
||||
|
||||
use App\CMS\Pipeline\Exceptions\InvalidProcessType;
|
||||
|
||||
abstract class AbstractPipeline {
|
||||
protected $processes = [];
|
||||
protected $beforeStart = null;
|
||||
protected $beforeRender = null;
|
||||
protected $acceptedProcessInterface = null;
|
||||
|
||||
/**
|
||||
* check if given classname implements valid Process interface
|
||||
*
|
||||
* @param $classname
|
||||
*
|
||||
* @throws InvalidProcessType
|
||||
*/
|
||||
protected function checkValidProcess($classname)
|
||||
{
|
||||
if (is_null($this->acceptedProcessInterface))
|
||||
return;
|
||||
|
||||
if (!in_array($this->acceptedProcessInterface, class_implements($classname))) {
|
||||
throw new InvalidProcessType($classname);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new process into pipeline
|
||||
*
|
||||
* @param $process
|
||||
*
|
||||
* @return void
|
||||
* @throws InvalidProcessType
|
||||
*/
|
||||
function add($process)
|
||||
{
|
||||
$this->checkValidProcess($process);
|
||||
|
||||
$this->processes[] = $process;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $beforeStart
|
||||
*/
|
||||
public function setBeforeStart($beforeStart)
|
||||
{
|
||||
$this->checkValidProcess($beforeStart);
|
||||
|
||||
if (!is_null($this->beforeStart)) {
|
||||
array_unshift($this->processes, $this->beforeStart);
|
||||
}
|
||||
|
||||
$this->beforeStart = $beforeStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $beforeRender
|
||||
*/
|
||||
public function setBeforeRender($beforeRender)
|
||||
{
|
||||
$this->checkValidProcess($beforeRender);
|
||||
|
||||
if (!is_null($this->beforeRender)) {
|
||||
array_push($this->processes, $this->beforeRender);
|
||||
}
|
||||
|
||||
$this->beforeRender = $beforeRender;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace App\CMS\Pipeline\DisplayPipeline;
|
||||
|
||||
use App\CMS\Contracts\Content\DisplayPipeline\Pipeline;
|
||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
||||
use App\CMS\Pipeline\AbstractPipeline;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
class DisplayPipeline extends AbstractPipeline implements Pipeline
|
||||
{
|
||||
/**
|
||||
* DisplayPipeline constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->acceptedProcessInterface = Process::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run pipeline
|
||||
*
|
||||
* @param Content $page
|
||||
*
|
||||
* @return Content
|
||||
*/
|
||||
function run(Content $page)
|
||||
{
|
||||
$this->runBeforeStart($page);
|
||||
|
||||
foreach ($this->processes as $process) {
|
||||
/**
|
||||
* @var $run Process
|
||||
*/
|
||||
$run = new $process;
|
||||
$run->handle($page);
|
||||
}
|
||||
|
||||
$this->runBeforeRender($page);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
protected function runBeforeStart($page)
|
||||
{
|
||||
if (!is_null($this->beforeStart)) {
|
||||
$process = new $this->beforeStart;
|
||||
$process->handle($page);
|
||||
}
|
||||
}
|
||||
|
||||
protected function runBeforeRender($page)
|
||||
{
|
||||
if (!is_null($this->beforeRender)) {
|
||||
$process = new $this->beforeRender;
|
||||
$process->handle($page);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace App\CMS\Pipeline\DisplayPipeline\Process;
|
||||
|
||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
class AddViewedToPage implements Process {
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $page
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function handle(Content & $page)
|
||||
{
|
||||
$page->view();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace App\CMS\Pipeline\DisplayPipeline\Process;
|
||||
|
||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
||||
use App\Models\Content\Content;
|
||||
use Webwizo\Shortcodes\Facades\Shortcode;
|
||||
|
||||
class CompileShortcodes implements Process {
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $page
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function handle(Content & $page)
|
||||
{
|
||||
$page->pageContent = Shortcode::compile($page->pageContent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace App\CMS\Pipeline\Exceptions;
|
||||
|
||||
class InvalidProcessType extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace App\CMS\Pipeline\SavePipeline\Process;
|
||||
|
||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
class SaveCommonFields implements Process {
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function handle(Content & $page, array &$input)
|
||||
{
|
||||
($page->exists == false) ? $page = Content::create($input): $page->update($input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Pipeline\SavePipeline\Process;
|
||||
|
||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
||||
use App\Models\Content\Content;
|
||||
use App\Models\Content\ContentHasFile;
|
||||
use App\Models\FileManager\Directory;
|
||||
use App\Models\FileManager\File;
|
||||
|
||||
class UploadRelatedFiles implements Process
|
||||
{
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function handle(Content & $page, array & $input)
|
||||
{
|
||||
if (!isset($input['files'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$files = $input['files'];
|
||||
$assignedFiles = isset($input['keepAssigned']) ? $input['keepAssigned'] : [];
|
||||
|
||||
// check if any file was removed
|
||||
$this->removeRelatedFiles($page, $assignedFiles);
|
||||
|
||||
// allow uploading only on created pages
|
||||
if (!$page->id || !$files[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// find or create new directory for files assigned to content
|
||||
$directory = Directory::firstOrCreate([
|
||||
'name' => '.content_files',
|
||||
'hidden' => true
|
||||
]);
|
||||
$data = new \stdClass();
|
||||
$data->directoryId = $directory->id;
|
||||
|
||||
$fileModel = app(File::class);
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!$file) {
|
||||
continue;
|
||||
}
|
||||
$uploaded = $fileModel->upload($file, $data);
|
||||
|
||||
// add assignement
|
||||
ContentHasFile::create([
|
||||
'file_id' => $uploaded['id'],
|
||||
'content_id' => $page->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete files from association
|
||||
*
|
||||
* @param Content $page
|
||||
* @param $assignedFiles
|
||||
*/
|
||||
private function removeRelatedFiles(Content $page, $assignedFiles)
|
||||
{
|
||||
$allFiles = $page->files()
|
||||
->whereNotIn('id', array_keys($assignedFiles))
|
||||
->get();
|
||||
|
||||
foreach ($allFiles as $file) {
|
||||
ContentHasFile::where('content_id', $page->id)
|
||||
->where('file_id', $file->id)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace App\CMS\Pipeline\SavePipeline\Process;
|
||||
|
||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
||||
use App\CMS\Helpers\RootDirectory;
|
||||
use App\Models\Content\Content;
|
||||
use App\Models\FileManager\File;
|
||||
|
||||
class UploadTitlePhoto implements Process
|
||||
{
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function handle(Content & $page, array & $input)
|
||||
{
|
||||
$fileModel = app(File::class);
|
||||
$titlePhoto = isset($input['titlePhotoFile']) ? $input['titlePhotoFile'] : null;
|
||||
|
||||
// upload file - if provided
|
||||
$page->titlePhoto = isset($input['existingTitlePhoto']) ? $input['existingTitlePhoto'] : null;
|
||||
|
||||
if (!is_null($titlePhoto)) {
|
||||
$root = RootDirectory::get();
|
||||
$data = ['directoryId' => $root->id];
|
||||
|
||||
$file = $fileModel->upload($titlePhoto, (object)$data);
|
||||
|
||||
$page->titlePhoto = $file ? $file['filename'] : null;
|
||||
}
|
||||
|
||||
$page->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace App\CMS\Pipeline\SavePipeline;
|
||||
|
||||
use App\CMS\Contracts\Content\SavePipeline\Pipeline;
|
||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
||||
use App\CMS\Pipeline\AbstractPipeline;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
class SavePipeline extends AbstractPipeline implements Pipeline
|
||||
{
|
||||
/**
|
||||
* SavePipeline constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->acceptedProcessInterface = Process::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save content page
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*
|
||||
* @return Content
|
||||
*/
|
||||
function run(Content & $page, array $input)
|
||||
{
|
||||
$this->runBeforeStart($page, $input);
|
||||
|
||||
foreach ($this->processes as $process) {
|
||||
/**
|
||||
* @var $run Process
|
||||
*/
|
||||
$run = new $process;
|
||||
$run->handle($page, $input);
|
||||
}
|
||||
|
||||
$this->runAfter($page, $input);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run process as first - if specified
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*/
|
||||
protected function runBeforeStart(Content $page, array $input)
|
||||
{
|
||||
if (!is_null($this->beforeStart)) {
|
||||
app($this->beforeStart)->handle($page, $input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run some process in the end - if exists
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*/
|
||||
protected function runAfter(Content $page, array $input)
|
||||
{
|
||||
if (!is_null($this->beforeRender)) {
|
||||
app($this->beforeRender)->handle($page, $input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,6 @@ class Content extends Repository implements IContent
|
||||
return $this->getPageQuery()
|
||||
->where('isHomepage', 1)
|
||||
->first();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,8 +125,6 @@ class Content extends Repository implements IContent
|
||||
$query = $query->whereIn('contents.status', $statuses);
|
||||
}
|
||||
|
||||
$pages = $query->paginate(setting('paginatedResults', 20));
|
||||
|
||||
return $pages;
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Repositories\FileManager;
|
||||
|
||||
use App\CMS\Helpers\RootDirectory;
|
||||
@@ -25,7 +26,33 @@ class Directory
|
||||
return $exists->exists();
|
||||
}
|
||||
|
||||
public function update(DirectoryModel $directory, $data) {
|
||||
/**
|
||||
* Create new directory
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return DirectoryModel
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
$directory = new DirectoryModel();
|
||||
$directory->name = $data['name'];
|
||||
$directory->parent_id = $data['parentDirectory'];
|
||||
$directory->user_id = \Auth::user()->id;
|
||||
$directory->description = $data['description'];
|
||||
$directory->save();
|
||||
|
||||
return $directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update given directory
|
||||
*
|
||||
* @param DirectoryModel $directory
|
||||
* @param $data
|
||||
*/
|
||||
public function update(DirectoryModel $directory, $data)
|
||||
{
|
||||
$directory->name = $data['name'];
|
||||
$directory->description = $data['description'];
|
||||
$directory->save();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace App\CMS\Repositories\FileManager;
|
||||
|
||||
use App\Models\FileManager\File as FileModel;
|
||||
|
||||
class File {
|
||||
/**
|
||||
* Update given instance of File
|
||||
*
|
||||
* @param FileModel $file
|
||||
* @param $data
|
||||
*/
|
||||
public function update(FileModel $file, $data) {
|
||||
$file->update($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace App\CMS\Repositories\Users;
|
||||
|
||||
use App\CMS\Repositories\Repository;
|
||||
use App\Models\User as UserModel;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class User extends Repository {
|
||||
/**
|
||||
* Update given user
|
||||
*
|
||||
* @param UserModel $user
|
||||
* @param $data
|
||||
*/
|
||||
public function update(UserModel $user, $data) {
|
||||
// update username if set
|
||||
if (isset($data['username'])) {
|
||||
$user->username = $data['username'];
|
||||
}
|
||||
|
||||
// change name (if set)
|
||||
if (isset($data['name'])) {
|
||||
$user->name = $data['name'];
|
||||
}
|
||||
|
||||
if (isset($data['role'])) {
|
||||
$user->role = $data['role'];
|
||||
}
|
||||
|
||||
if (isset($data['status'])) {
|
||||
$user->status = $data['status'];
|
||||
}
|
||||
|
||||
if (isset($data['password'])) {
|
||||
$user->password = Hash::make($data['password']);
|
||||
}
|
||||
|
||||
$user->email = $data['email'];
|
||||
|
||||
$user->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new user
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return UserModel
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
// create new user
|
||||
$user = new UserModel();
|
||||
$user->name = $data['name'];
|
||||
$user->email = $data['email'];
|
||||
$user->username = $data['username'];
|
||||
$user->role = $data['role'];
|
||||
$user->password = Hash::make($data['password']);
|
||||
|
||||
// store user into database
|
||||
$user->save();
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Repositories\Widgets;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Widgets\Widget as WidgetModel;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class Widget
|
||||
{
|
||||
public function createNew(WidgetType $widgetType, Request $request)
|
||||
{
|
||||
$data = $request->except('_token');
|
||||
|
||||
// create new widget
|
||||
$widget = new WidgetModel();
|
||||
$widget->widget_type_handler = $widgetType->handler;
|
||||
$widget->user_id = \Auth::user()->id;
|
||||
$widget->name = $data['name'];
|
||||
$widget->description = $data['description'];
|
||||
$widget->container_class = $data['containerClass'];
|
||||
$widget->container_id = empty($data['containerId']) ? null : $data['containerId'];
|
||||
$widget->settings = call_user_func([$widgetType->handler, 'save'], $request);
|
||||
|
||||
// save into database
|
||||
$widget->save();
|
||||
|
||||
// fire event with newly created widget
|
||||
Event::fire(new \App\Events\CreateNewWidget($widget));
|
||||
|
||||
return $widget;
|
||||
}
|
||||
|
||||
public function edit(WidgetModel $widget, Request $request)
|
||||
{
|
||||
// update name
|
||||
$widget->name = $request->name;
|
||||
$widget->container_class = $request->containerClass;
|
||||
$widget->container_id = empty($request->containerId) ? null : $request->containerId;
|
||||
$widget->description = $request->description;
|
||||
|
||||
// try to save this widget
|
||||
$widget->settings = call_user_func([$widget->widget_type_handler, 'save'], $request);
|
||||
|
||||
// save into database
|
||||
$widget->save();
|
||||
|
||||
// fire event with editing widget
|
||||
Event::fire(new \App\Events\EditWidget($widget));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Repositories\Widgets;
|
||||
|
||||
use App\Events\CreateNewWidgetArea;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetArea as WidgetAreaModel;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class WidgetArea
|
||||
{
|
||||
public function getWidgets($uniqueCode = false)
|
||||
{
|
||||
$widgets = Widget::select('widgets.*', 'widgets.widget_type_handler', 'widget_areas.code as widget_area_code', 'widgets.name as widget_name', 'widgets.settings')
|
||||
->join('widget_in_widget_area', 'widget_in_widget_area.widget_id', '=', 'widgets.id')
|
||||
->join('widget_areas', 'widget_in_widget_area.widget_area_id', '=', 'widget_areas.id')
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->orderBy('widget_in_widget_area.position');
|
||||
if (!$uniqueCode) {
|
||||
$widgets = $widgets->where('widget_areas.viewed', '>=', setting('preloadFrequentedWidgetAreasTreshold', 10));
|
||||
} else {
|
||||
$widgets = $widgets->where('code', $uniqueCode);
|
||||
}
|
||||
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
public function update(\App\Models\Widgets\WidgetArea $area, Request $request) {
|
||||
$area->name = $request->name;
|
||||
$area->description = $request->description;
|
||||
$area->save();
|
||||
|
||||
// fire event with new widget area
|
||||
Event::fire(new \App\Events\EditWidgetArea($area));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance of widget area
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
$area = WidgetAreaModel::create([
|
||||
'code' => $request->code,
|
||||
'name' => $request->name,
|
||||
'description' => $request->description
|
||||
]);
|
||||
|
||||
// fire event with new widget area
|
||||
Event::fire(new CreateNewWidgetArea($area));
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Widgets\Menu;
|
||||
|
||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
||||
use App\CMS\Contracts\Widgets\PublicWidget;
|
||||
use App\CMS\Widgets\Contracts\WidgetRenderer;
|
||||
use App\CMS\Contracts\Widgets\WidgetRenderer;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content\Content;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
||||
use Modules\Blog\Article\Handlers\Article;
|
||||
|
||||
class Menu implements PublicWidget
|
||||
{
|
||||
@@ -76,6 +78,7 @@ class Menu implements PublicWidget
|
||||
$pages = Content::where('language', LaravelLocalization::getCurrentLocale())
|
||||
->whereIn('id', $ids)
|
||||
->whereIn('status', $allowedStatuses)
|
||||
->where('moduleHandler', '!=', Article::class)
|
||||
->get();
|
||||
$used = [];
|
||||
foreach ($pages as $page) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Widgets\Menu\Presenters;
|
||||
|
||||
use App\CMS\Contracts\Repositories\Content as ContentContract;
|
||||
@@ -6,9 +7,7 @@ use App\CMS\Contracts\Widgets\WidgetRenderer;
|
||||
use App\CMS\Widgets\Menu\Menu as WidgetMenu;
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class Menu implements WidgetRenderer
|
||||
@@ -36,7 +35,7 @@ class Menu implements WidgetRenderer
|
||||
return $a->order - $b->order;
|
||||
});
|
||||
|
||||
$route = Request::route()
|
||||
$routeName = Route::current()
|
||||
->getName();
|
||||
$parameters = Route::current()
|
||||
->parameters();
|
||||
@@ -55,7 +54,7 @@ class Menu implements WidgetRenderer
|
||||
}
|
||||
|
||||
$page = $pages[$pageId];
|
||||
$active = ($page->isHomepage && $route == 'page.index') || ($route == 'page.content' && isset($parameters['url']) && $parameters['url'] == $page->url);
|
||||
$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';
|
||||
@@ -83,15 +82,14 @@ class Menu implements WidgetRenderer
|
||||
$content = app(ContentContract::class);
|
||||
|
||||
// get list of all pages
|
||||
$pages = $content->getOverview();
|
||||
$widget->settings = new \stdClass();
|
||||
$widget->settings->links = [];
|
||||
|
||||
$pages = $content->getOverview()
|
||||
->get();
|
||||
|
||||
return view('admin.widgets.menu.new', [
|
||||
'type' => $type,
|
||||
'widget' => $widget,
|
||||
'pages' => $pages,
|
||||
'links' => []
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -110,7 +108,8 @@ class Menu implements WidgetRenderer
|
||||
$content = App::make(ContentContract::class);
|
||||
|
||||
// get list of all pages
|
||||
$pages = $content->getOverview();
|
||||
$pages = $content->getOverview()
|
||||
->get();
|
||||
|
||||
// make object from JSON
|
||||
if (!isset($widget->settings->links)) {
|
||||
@@ -124,8 +123,6 @@ class Menu implements WidgetRenderer
|
||||
return $a->order - $b->order;
|
||||
});
|
||||
|
||||
$widget->settings->links = (object)$links;
|
||||
|
||||
return view('admin.widgets.menu.edit', ['widget' => $widget, 'pages' => $pages]);
|
||||
return view('admin.widgets.menu.edit', ['widget' => $widget, 'pages' => $pages, 'links' => (object)$links]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Modules;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateNew extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:new
|
||||
{name : module name}
|
||||
{parentModule? : name of parent module}
|
||||
{--entity= : entity}';
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create new CMS module.';
|
||||
protected $moduleName;
|
||||
protected $moduleNamespace;
|
||||
protected $entity;
|
||||
protected $entityNamespace;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$defaultEntityNamespace = $this->loadArguments();
|
||||
$path = preg_replace('|/{2,}|i', '/', config('modules.paths.modules') . '/' . $this->moduleNamespace);
|
||||
|
||||
if (is_dir($path)) {
|
||||
$this->error('Module already exists in ' . $path);
|
||||
return;
|
||||
}
|
||||
|
||||
// copy stub files
|
||||
\File::copyDirectory(config('modules.paths.stubs'), $path);
|
||||
|
||||
$files = \File::allFiles($path);
|
||||
foreach ($files as $file) {
|
||||
$newName = str_replace('stub', 'php', $this->replacePlaceholders($file->getPathname()));
|
||||
|
||||
// ignore new entity when using existing entity
|
||||
if ($this->entityNamespace != $defaultEntityNamespace && Str::contains('Entities', $file)) {
|
||||
\File::delete($file);
|
||||
continue;
|
||||
}
|
||||
|
||||
// rename file
|
||||
\File::move($file, $newName);
|
||||
|
||||
// change its content
|
||||
$content = file_get_contents($newName);
|
||||
$content = $this->replacePlaceholders($content);
|
||||
file_put_contents($newName, $content);
|
||||
}
|
||||
|
||||
$this->info('Module successfully created.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and replace all placeholders in given content
|
||||
*
|
||||
* @param $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function replacePlaceholders($content)
|
||||
{
|
||||
$replace = [
|
||||
'$Module$' => $this->moduleName,
|
||||
'$ModuleNamespace$' => str_replace('/', '\\', $this->moduleNamespace),
|
||||
'$module$' => strtolower($this->moduleName),
|
||||
'$EntityNamespace$' => $this->entityNamespace,
|
||||
'$Entity$' => $this->entity
|
||||
];
|
||||
|
||||
foreach ($replace as $what => $for) {
|
||||
$content = str_replace($what, $for, $content);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load command arguments
|
||||
* @return string
|
||||
*/
|
||||
private function loadArguments()
|
||||
{
|
||||
$parent = $this->argument('parentModule');
|
||||
$this->moduleName = $moduleName = $this->argument('name');
|
||||
$this->moduleNamespace = trim($parent . '/' . $moduleName, '/');
|
||||
|
||||
$entity = $this->option('entity');
|
||||
|
||||
$defaultEntityNamespace = '\\Modules\\' . str_replace('/', '\\', $this->moduleNamespace) . '\Entities\\';
|
||||
|
||||
if (!empty($entity)) {
|
||||
$parts = explode('\\', $entity);
|
||||
$this->entity = $parts[count($parts) - 1];
|
||||
unset($parts[count($parts) - 1]);
|
||||
$this->entityNamespace = implode('\\', $parts);
|
||||
} else {
|
||||
$this->entityNamespace = $defaultEntityNamespace;
|
||||
$this->entity = $this->moduleName;
|
||||
}
|
||||
|
||||
return $defaultEntityNamespace;
|
||||
}
|
||||
}
|
||||
+3
-13
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands\Modules;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
@@ -12,7 +12,7 @@ class InstallAllModules extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'install-all-modules';
|
||||
protected $signature = 'module:install-all';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
@@ -20,16 +20,6 @@ class InstallAllModules extends Command
|
||||
*/
|
||||
protected $description = 'Crawl /modules directory and install all modules';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@@ -45,7 +35,7 @@ class InstallAllModules extends Command
|
||||
|
||||
// try to install each module
|
||||
try {
|
||||
$this->call('install-module', ['name' => $moduleName]);
|
||||
$this->call('module:install', ['name' => $moduleName]);
|
||||
} catch (\Exception $e) {
|
||||
$this->line('Module ' . $moduleName . ' already installed.');
|
||||
}
|
||||
+5
-5
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands\Modules;
|
||||
|
||||
use App\Models\Module;
|
||||
use App\ModuleManager\Installer;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
@@ -17,7 +18,7 @@ class InstallModule extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'install-module {name} {parentModuleId?}';
|
||||
protected $signature = 'module:install {name} {parentModuleId?}';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
@@ -156,12 +157,11 @@ class InstallModule extends Command
|
||||
$settings = [
|
||||
'staticName' => $this->moduleName,
|
||||
'providers' => $providers,
|
||||
'aliases' => isset($config['aliases']) ? $config['aliases'] : [],
|
||||
'order' => isset($config['order']) ? $config['order'] : 0,
|
||||
'files' => isset($config['files']) ? $config['files'] : []
|
||||
];
|
||||
|
||||
$module = Module::install($name, $alias, $description, $handler, $this->parentModuleId, $settings);
|
||||
$module = Installer::install($name, $alias, $description, $handler, $this->parentModuleId, $settings);
|
||||
}
|
||||
|
||||
// try to install submodules
|
||||
@@ -184,7 +184,7 @@ class InstallModule extends Command
|
||||
$submodule = str_replace($this->modulesPath . DIRECTORY_SEPARATOR, '', $submodulePath);
|
||||
|
||||
try {
|
||||
$this->call('install-module', ['name' => $submodule, 'parentModuleId' => $parentModule->id]);
|
||||
$this->call('module:install', ['name' => $submodule, 'parentModuleId' => $parentModule->id]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
@@ -12,7 +12,6 @@ class PublishTemplateResources extends Command
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'template:publish';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
@@ -27,6 +26,7 @@ class PublishTemplateResources extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->call('cache:clear');
|
||||
$this->call('vendor:publish', ['--tag' => 'module-views', '--force' => true]);
|
||||
$this->call('vendor:publish', ['--tag' => 'public-assets', '--force' => true]);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
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;
|
||||
@@ -43,14 +45,13 @@ class SetTemplate extends Command
|
||||
$config['staticName'] = $template;
|
||||
|
||||
if ($current) {
|
||||
$info = json_decode($current->module_settings);
|
||||
|
||||
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $info->staticName . '.');
|
||||
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $current->module_settings['staticName'] . '.');
|
||||
$confirm = $this->confirm('Uninstall it and install *' . trans($config['name']) . '*? All data associated with installed template will be lost!');
|
||||
|
||||
if ($confirm) {
|
||||
$this->line('Uninstalling ' . $current->name . '.');
|
||||
$current->uninstall();
|
||||
|
||||
Uninstaller::uninstall($current);
|
||||
} else {
|
||||
$this->line('Aborting installation.');
|
||||
return;
|
||||
@@ -58,7 +59,7 @@ class SetTemplate extends Command
|
||||
}
|
||||
|
||||
try {
|
||||
Module::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
|
||||
Installer::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
|
||||
return;
|
||||
@@ -72,6 +73,8 @@ 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\CMS\Helpers\CurrentTemplate;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class TemplateInfo extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'template:info';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Show details about currently set template';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$template = CurrentTemplate::get();
|
||||
|
||||
if (is_null($template)) {
|
||||
$this->error('No template set.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->line($template->name);
|
||||
$this->line($template->handler);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Console\Commands\Modules\CreateNew;
|
||||
use App\Console\Commands\PublishTemplateResources;
|
||||
use App\Console\Commands\TemplateInfo;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
@@ -16,14 +18,16 @@ class Kernel extends ConsoleKernel
|
||||
protected $commands = [
|
||||
Commands\NewUser::class,
|
||||
Commands\ChangePassword::class,
|
||||
Commands\InstallModule::class,
|
||||
Commands\InstallAllModules::class,
|
||||
CreateNew::class,
|
||||
Commands\Modules\InstallModule::class,
|
||||
Commands\Modules\InstallAllModules::class,
|
||||
Commands\TranslateDirectory::class,
|
||||
Commands\TranslateAll::class,
|
||||
Commands\InitDatabaseSchema::class,
|
||||
Commands\SetTemplate::class,
|
||||
Commands\AddLanguage::class,
|
||||
PublishTemplateResources::class
|
||||
PublishTemplateResources::class,
|
||||
TemplateInfo::class
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -35,7 +39,5 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\WidgetArea;
|
||||
use App\Models\Widgets\WidgetArea;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DeleteWidgetArea extends Event
|
||||
@@ -20,7 +20,6 @@ class DeleteWidgetArea extends Event
|
||||
*/
|
||||
public function __construct(WidgetArea $widgetArea)
|
||||
{
|
||||
//
|
||||
$this->widgetArea = $widgetArea;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
use App\Models\WidgetArea;
|
||||
use App\Models\Widgets\WidgetArea;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class EditWidgetArea extends Event
|
||||
{
|
||||
|
||||
@@ -12,11 +12,11 @@ class UploadFile extends Event
|
||||
/**
|
||||
* @var UploadedFile
|
||||
*/
|
||||
private $uploadedFile;
|
||||
public $uploadedFile;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
private $id;
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
|
||||
@@ -7,6 +7,8 @@ use App\CMS\Interactions\Admin\Content\ChangeStatus;
|
||||
use App\CMS\Interactions\Admin\Content\DeletePage;
|
||||
use App\CMS\Interactions\Admin\Content\SetHomepage;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Models\Content\Content;
|
||||
use App\Models\Content\ContentHistory;
|
||||
|
||||
class ContentActions extends Controller
|
||||
{
|
||||
@@ -25,15 +27,13 @@ class ContentActions extends Controller
|
||||
* This method is called in static page overview from quick actions. It checks if status is valid, if page exists
|
||||
* and updates status.
|
||||
*
|
||||
* @param $id
|
||||
* @param Content $page
|
||||
* @param $status
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function changeStatus($id, $status)
|
||||
public function changeStatus(Content $page, $status)
|
||||
{
|
||||
$page = $this->content->getOne($id);
|
||||
|
||||
Interaction::handle(ChangeStatus::class, ['status' => $status], $page);
|
||||
|
||||
// redirect back to overview with info for user
|
||||
@@ -45,14 +45,12 @@ class ContentActions extends Controller
|
||||
/**
|
||||
* Delete page
|
||||
*
|
||||
* @param $id
|
||||
* @param Content $page
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete($id)
|
||||
public function delete(Content $page)
|
||||
{
|
||||
$page = $this->content->getOne($id);
|
||||
|
||||
Interaction::handle(DeletePage::class, [], $page);
|
||||
|
||||
// redirect back to overview with info for user
|
||||
@@ -66,14 +64,12 @@ class ContentActions extends Controller
|
||||
/**
|
||||
* Sets page as homepage
|
||||
*
|
||||
* @param $id
|
||||
* @param Content $page
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function setHomepage($id)
|
||||
public function setHomepage(Content $page)
|
||||
{
|
||||
$page = $this->content->getOne($id);
|
||||
|
||||
Interaction::handle(SetHomepage::class, [], $page);
|
||||
|
||||
// redirect back to overview with info for user
|
||||
|
||||
@@ -5,6 +5,7 @@ use App\CMS\Contracts\Repositories\Content as IContent;
|
||||
use App\CMS\Contracts\Repositories\Module as IModule;
|
||||
use App\CMS\Enumerations\ContentStatuses;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Models\Module;
|
||||
|
||||
class ContentOverview extends Controller
|
||||
{
|
||||
@@ -26,20 +27,21 @@ class ContentOverview extends Controller
|
||||
/**
|
||||
* Overview for all content pages.
|
||||
*
|
||||
* @param null|int $moduleId
|
||||
* @param Module|null $module
|
||||
* @param null $status
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @internal param int|null $moduleId
|
||||
*/
|
||||
public function index($moduleId = null, $status = null)
|
||||
public function index(Module $module = null, $status = null)
|
||||
{
|
||||
// get module settings
|
||||
$module = $this->module->getOne($moduleId);
|
||||
$pageHeading = $this->module->getOverviewTitle($module);
|
||||
|
||||
// get pages for overview
|
||||
$handler = $module !== null ? $module->handler : null;
|
||||
$pages = $this->content->getOverview($handler, [$status]);
|
||||
$handler = $module->exists ? $module->handler : null;
|
||||
$pages = $this->content->getOverview($handler, [$status])
|
||||
->paginate(setting('paginatedResults', 20));
|
||||
|
||||
// get homepage - for checking if homepage is set and available
|
||||
$homepage = $this->content->getHomepage();
|
||||
|
||||
@@ -4,13 +4,14 @@ namespace App\Http\Controllers\Admin\Contents;
|
||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
||||
use App\CMS\Contracts\Repositories\Module as IModuleRepository;
|
||||
use App\CMS\Contracts\Repositories\Template as ITemplate;
|
||||
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
||||
use App\CMS\Enumerations\ContentStatuses;
|
||||
use App\Cms\Handlers\Interactions\Interaction;
|
||||
use App\Cms\Interactions\Admin\Content\NewContent;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\CreateNewContentRequest;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Module;
|
||||
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
||||
|
||||
/**
|
||||
* Class CreateNewContent
|
||||
@@ -67,9 +68,8 @@ class CreateNewContent extends Controller
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create($module)
|
||||
public function create(Module $module)
|
||||
{
|
||||
$module = $this->module->getOne($module);
|
||||
$statuses = ContentStatuses::getWithTranslations();
|
||||
$pageHeading = $this->module->getCreateContentTitle($module);
|
||||
$templates = $this->template->getForModule($module);
|
||||
@@ -85,7 +85,8 @@ class CreateNewContent extends Controller
|
||||
'module' => $module,
|
||||
'categories' => $categories,
|
||||
'page' => $page,
|
||||
'rootPages' => $this->content->getOverview(),
|
||||
'rootPages' => $this->content->getOverview()
|
||||
->get(),
|
||||
'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']),
|
||||
'formSections' => call_user_func([$module->handler, 'getExtendedFormInputsCreate']),
|
||||
]);
|
||||
@@ -94,20 +95,16 @@ class CreateNewContent extends Controller
|
||||
/**
|
||||
* Save new content page
|
||||
*
|
||||
* @param CreateNewContentRequest $request
|
||||
* @param $moduleId
|
||||
* @param CreateNewContentRequest|Request $request
|
||||
* @param Module $module
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @internal param $moduleId
|
||||
*/
|
||||
public function store(Request $request, $moduleId)
|
||||
public function store(Request $request, Module $module)
|
||||
{
|
||||
$module = $this->module->getOne($moduleId);
|
||||
|
||||
$titlePhoto = $request->file('titlePhoto');
|
||||
$relatedFiles = $request->all()['files'];
|
||||
|
||||
// create new page
|
||||
Interaction::handle(NewContent::class, $request->all(), $module->handler, $titlePhoto, $relatedFiles);
|
||||
Interaction::handle(NewContent::class, $request->all(), $module->handler);
|
||||
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
|
||||
@@ -17,6 +17,7 @@ use App\Models\Content\ContentHistory;
|
||||
use App\Models\FileManager\File;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
||||
use Modules\Categories\Repositories\Category;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class EditContent extends Controller
|
||||
@@ -58,7 +59,7 @@ class EditContent extends Controller
|
||||
* @param ICategory $category
|
||||
* @param ITemplate $template
|
||||
*/
|
||||
public function __construct(ContentHistory $history, File $file, IContent $content, IModuleRepository $module, ICategory $category, ITemplate $template)
|
||||
public function __construct(ContentHistory $history, File $file, IContent $content, IModuleRepository $module, Category $category, ITemplate $template)
|
||||
{
|
||||
$this->history = $history;
|
||||
$this->file = $file;
|
||||
@@ -71,14 +72,13 @@ class EditContent extends Controller
|
||||
/**
|
||||
* Display form for editing static page
|
||||
*
|
||||
* @param $id
|
||||
* @param Content $page
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(Content $page)
|
||||
{
|
||||
$statuses = ContentStatuses::getWithTranslations();
|
||||
$page = $this->content->getOne($id);
|
||||
|
||||
// get module ID
|
||||
$module = $this->module->getByHandler($page->moduleHandler);
|
||||
@@ -87,9 +87,6 @@ class EditContent extends Controller
|
||||
$categories = $this->category->getForModule($module);
|
||||
$history = $this->history->getStructuredHistoryOf($page);
|
||||
|
||||
// modify data for edit form according to installed template
|
||||
CurrentTemplate::beforePopulatingEditForm($page);
|
||||
|
||||
// render view
|
||||
return view('admin.content.edit', [
|
||||
'pageHeading' => $pageHeading,
|
||||
@@ -97,7 +94,7 @@ class EditContent extends Controller
|
||||
'page' => $page,
|
||||
'module' => $module,
|
||||
'categories' => $categories,
|
||||
'rootPages' => $this->content->getOverview(),
|
||||
'rootPages' => $this->content->getOverview()->get(),
|
||||
'templates' => $templates,
|
||||
'formSectionNames' => $this->module->call($module, 'getExtendedFormSections'),
|
||||
'formSections' => $this->module->call($module, 'getExtendedFormInputsEdit'),
|
||||
@@ -108,34 +105,16 @@ class EditContent extends Controller
|
||||
/**
|
||||
* Edit static page and save changes into history.
|
||||
*
|
||||
* @param EditContentRequest $request
|
||||
* @param $id
|
||||
* @param EditContentRequest|Request $request
|
||||
* @param Content $page
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @internal param $id
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, Content $page)
|
||||
{
|
||||
try {
|
||||
/**
|
||||
* @var $page Content
|
||||
*/
|
||||
$page = $this->content->getOne($id);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
|
||||
// log attempt of invalid edit
|
||||
Event::fire(new AttemptToEditInvalidContent($id));
|
||||
|
||||
// page for editing not found
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
->with('error', trans('admin/contents.invalidPage'));
|
||||
}
|
||||
|
||||
// edit page
|
||||
$titlePhoto = $request->file('titlePhoto');
|
||||
$relatedFiles = $request->all()['files'];
|
||||
|
||||
Interaction::handle(EditContentInteraction::class, $request->all(), $page, $titlePhoto, $relatedFiles);
|
||||
Interaction::handle(EditContentInteraction::class, $request->all(), $page);
|
||||
|
||||
// something was changed, inform user
|
||||
return redirect()
|
||||
|
||||
@@ -19,30 +19,31 @@ class History extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param Content $page
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getOverview($id)
|
||||
public function getOverview(Content $page)
|
||||
{
|
||||
// test if given content id is static page and if exists
|
||||
$content = Content::findOrFail($id);
|
||||
|
||||
$history = $this->history->getStructuredHistoryOf($content);
|
||||
$history = $this->history->getStructuredHistoryOf($page);
|
||||
|
||||
return view('admin/history.overview', [
|
||||
'history' => $history,
|
||||
'page' => $content
|
||||
'page' => $page
|
||||
]);
|
||||
}
|
||||
|
||||
public function getDiff($revision, $id)
|
||||
/**
|
||||
* @param ContentHistory $revision
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getDiff(ContentHistory $revision)
|
||||
{
|
||||
$change = $this->history->findOrFail($id);
|
||||
$diff = $this->history->getDiff($change);
|
||||
$diff = $this->history->getDiff($revision);
|
||||
|
||||
return view('admin/history.diff', [
|
||||
'change' => $change,
|
||||
'change' => $revision,
|
||||
'diff' => $diff
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\CMS\Interactions\Admin\FileManager\CreateDirectory;
|
||||
use App\CMS\Repositories\FileManager\Directory as DirectoryRepository;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Models\FileManager\Directory;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateNewDirectory extends Controller
|
||||
@@ -30,9 +31,10 @@ class CreateNewDirectory extends Controller
|
||||
/**
|
||||
* Create new directory
|
||||
*
|
||||
* @param Requests\CreateNewDirectoryRequest $request
|
||||
* @param Requests\CreateNewDirectoryRequest|Request $request
|
||||
*
|
||||
* @return $this|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
||||
* @internal param Directory $parentDirectory
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
@@ -5,19 +5,20 @@ namespace App\Http\Controllers\Admin\FileManager;
|
||||
use App\CMS\Repositories\FileManager\Directory as DirectoryRepository;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Http\Requests\EditDirectoryRequest;
|
||||
use App\Models\FileManager\Directory;
|
||||
|
||||
class EditDirectory extends Controller
|
||||
{
|
||||
/**
|
||||
* @param Requests\EditDirectoryRequest $request
|
||||
* @param EditDirectoryRequest $request
|
||||
* @param Directory $directory
|
||||
*
|
||||
* @return $this|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
||||
* @internal param $directoryId
|
||||
*
|
||||
*/
|
||||
public function update(Requests\EditDirectoryRequest $request, Directory $directory)
|
||||
public function update(EditDirectoryRequest $request, Directory $directory)
|
||||
{
|
||||
$repository = app(DirectoryRepository::class);
|
||||
if ($repository->checkIfNameExists($request->name, $directory->parent_id, $directory->id)) {
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\FileManager;
|
||||
|
||||
use App\CMS\Helpers\FileManager;
|
||||
use App\CMS\Helpers\RootDirectory;
|
||||
use App\CMS\Repositories\FileManager\File as FileRepository;
|
||||
use App\Events\EditFile;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\EditUploadedFileRequest;
|
||||
@@ -14,14 +15,12 @@ class EditUploadedFile extends Controller
|
||||
{
|
||||
/**
|
||||
* Edit form
|
||||
*
|
||||
* Render edit form for displaying details and updating given file
|
||||
*
|
||||
* @param File $file
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
* @internal param int $id file id
|
||||
*
|
||||
*/
|
||||
public function show(File $file)
|
||||
{
|
||||
@@ -35,7 +34,6 @@ class EditUploadedFile extends Controller
|
||||
|
||||
/**
|
||||
* Updates file
|
||||
*
|
||||
* User can change only keywords, original filename and description. Mime type, hash and other fields remain
|
||||
* unchanged
|
||||
*
|
||||
@@ -44,16 +42,11 @@ class EditUploadedFile extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @internal param $id
|
||||
*
|
||||
*/
|
||||
public function update(EditUploadedFileRequest $request, File $file)
|
||||
{
|
||||
// set values from form
|
||||
$file->name = $request->name;
|
||||
$file->keywords = $request->keywords;
|
||||
$file->description = $request->description;
|
||||
$file->directory_id = $request->directory_id;
|
||||
$file->save();
|
||||
$repository = app(FileRepository::class);
|
||||
$repository->update($file, $request->all());
|
||||
|
||||
// fire action
|
||||
Event::fire(new EditFile($file));
|
||||
|
||||
@@ -32,12 +32,12 @@ class UploadedFilesOverview extends Controller
|
||||
*/
|
||||
public function index(Directory $directory = null)
|
||||
{
|
||||
// include hidden directories?
|
||||
$includeHidden = Input::get('hidden');
|
||||
// dd($directory);
|
||||
|
||||
// include hidden directories?
|
||||
$subdirectories = $this->directoryRepository->getAllSubdirectories($directory);
|
||||
|
||||
if (!$includeHidden) {
|
||||
if (!Input::get('hidden', true)) {
|
||||
$subdirectories = $subdirectories->where('hidden', false);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\Templates;
|
||||
|
||||
use App\Cms\Repositories\Templates\Template as TemplateRepository;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\CopyTemplateRequest;
|
||||
use App\Models\Templates\Template;
|
||||
@@ -10,7 +11,6 @@ class CopyTemplate extends Controller
|
||||
{
|
||||
/**
|
||||
* Method for copying given template.
|
||||
*
|
||||
* This method is supposed to be called by POST method.
|
||||
*
|
||||
* @param CopyTemplateRequest $request
|
||||
@@ -32,15 +32,22 @@ class CopyTemplate extends Controller
|
||||
$namespace .= '::';
|
||||
}
|
||||
|
||||
$repository = app(TemplateRepository::class);
|
||||
$repository->setModel($template);
|
||||
|
||||
// get template absolute paths
|
||||
$realTemplatePath = $template->getPathToTemplate();
|
||||
$customTemplatePath = $template->getPathToTemplate(Template::CUSTOM_EDIT_DIRECTORY);
|
||||
$realTemplatePath = $repository->getPathToTemplate();
|
||||
$customTemplatePath = $repository->getPathToTemplate(TemplateRepository::CUSTOM_EDIT_DIRECTORY);
|
||||
$path = dirname($customTemplatePath);
|
||||
|
||||
// create file copy
|
||||
$data = file_get_contents($realTemplatePath);
|
||||
$written = file_put_contents($path . DIRECTORY_SEPARATOR . $newName . Template::TEMPLATE_SUFFIX, $data);
|
||||
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path, 0777, true);
|
||||
}
|
||||
|
||||
$written = file_put_contents($path . DIRECTORY_SEPARATOR . $newName . TemplateRepository::TEMPLATE_SUFFIX, $data);
|
||||
// were data written?
|
||||
if ($written === false) {
|
||||
return $this->copyFailed($request, $template);
|
||||
@@ -67,7 +74,6 @@ class CopyTemplate extends Controller
|
||||
* @param Template $template
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
||||
*
|
||||
*/
|
||||
private function copyFailed(CopyTemplateRequest $request, Template $template)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,21 @@ use Illuminate\Support\Facades\File;
|
||||
|
||||
class EditTemplate extends Controller
|
||||
{
|
||||
/**
|
||||
* @var TemplateRepositoryContract
|
||||
*/
|
||||
private $templateRepository;
|
||||
|
||||
/**
|
||||
* EditTemplate constructor.
|
||||
*
|
||||
* @param TemplateRepositoryContract $templateRepository
|
||||
*/
|
||||
public function __construct(TemplateRepositoryContract $templateRepository)
|
||||
{
|
||||
$this->templateRepository = $templateRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render form for editing template
|
||||
*
|
||||
@@ -19,18 +34,12 @@ class EditTemplate extends Controller
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getEdit($template)
|
||||
public function getEdit(Template $template)
|
||||
{
|
||||
/**
|
||||
* @var $template Template
|
||||
*/
|
||||
$template = Template::findOrFail($template);
|
||||
|
||||
$repo = app(TemplateRepositoryContract::class);
|
||||
$repo->setModel($template);
|
||||
$this->templateRepository->setModel($template);
|
||||
|
||||
// load template content
|
||||
$absolutePath = $repo->getPathToTemplate();
|
||||
$absolutePath = $this->templateRepository->getPathToTemplate();
|
||||
$content = @file_get_contents($absolutePath);
|
||||
|
||||
return view('admin.templates.edit', [
|
||||
@@ -45,15 +54,13 @@ class EditTemplate extends Controller
|
||||
* Save meta information about template and edited content
|
||||
*
|
||||
* @param EditTemplateRequest $request
|
||||
* @param $templateId
|
||||
* @param Template $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @internal param $templateId
|
||||
*/
|
||||
public function postEdit(EditTemplateRequest $request, $templateId)
|
||||
public function postEdit(EditTemplateRequest $request, Template $template)
|
||||
{
|
||||
// find template
|
||||
$template = Template::findOrFail($templateId);
|
||||
|
||||
// setup meta information
|
||||
$template->name = $request->name;
|
||||
|
||||
@@ -78,9 +85,11 @@ class EditTemplate extends Controller
|
||||
*/
|
||||
private function saveContent(Template $template, EditTemplateRequest $request)
|
||||
{
|
||||
$this->templateRepository->setModel($template);
|
||||
|
||||
// get templates with paths
|
||||
$originalTemplate = $template->getPathToTemplate();
|
||||
$customTemplate = $template->getPathToTemplate(Template::CUSTOM_EDIT_DIRECTORY);
|
||||
$originalTemplate = $this->templateRepository->getPathToTemplate();
|
||||
$customTemplate = $this->templateRepository->getPathToTemplate(TemplateRepositoryContract::CUSTOM_EDIT_DIRECTORY);
|
||||
|
||||
// get paths
|
||||
$originalDir = dirname($originalTemplate);
|
||||
|
||||
@@ -7,16 +7,21 @@ use App\Models\Templates\TemplatePath;
|
||||
|
||||
class TemplateOverview extends Controller
|
||||
{
|
||||
public function getPath($path)
|
||||
/**
|
||||
* Display overview of all templates in given path
|
||||
*
|
||||
* @param TemplatePath $templatePath
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getPath(TemplatePath $templatePath)
|
||||
{
|
||||
$path = TemplatePath::findOrFail($path);
|
||||
|
||||
return view('admin.templates.list', [
|
||||
'directory' => $path,
|
||||
'isWritable' => is_writable(base_path($path->path)),
|
||||
'templates' => $path->templates()
|
||||
'directory' => $templatePath,
|
||||
'isWritable' => is_writable(base_path($templatePath->path)),
|
||||
'templates' => $templatePath->templates()
|
||||
->get(),
|
||||
'subdirectories' => $path->subdirectories()
|
||||
'subdirectories' => $templatePath->subdirectories()
|
||||
->get()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Admin\Users;
|
||||
|
||||
use App\CMS\Enumerations\UserRoles;
|
||||
use App\CMS\Repositories\Users\User as UserRepository;
|
||||
use App\Events\CreateNewUser as CreateNewUserEvent;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\CreateNewUserRequest;
|
||||
@@ -28,28 +29,21 @@ class CreateNewUser extends Controller
|
||||
|
||||
/**
|
||||
* Create new user
|
||||
*
|
||||
* This method saves new user into database
|
||||
*
|
||||
* @param CreateNewUserRequest $request
|
||||
* @param UserRepository $userRepository
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
protected function postRegistration(CreateNewUserRequest $request)
|
||||
protected function postRegistration(CreateNewUserRequest $request, UserRepository $userRepository)
|
||||
{
|
||||
// when user did not provide any username, use his email
|
||||
$username = isset($request->username) && !empty($request->username) ? $request->username : $request->email;
|
||||
|
||||
// create new user
|
||||
$user = new User();
|
||||
$user->name = $request->name;
|
||||
$user->email = $request->email;
|
||||
$user->username = $username;
|
||||
$user->role = $request->role;
|
||||
$user->password = Hash::make($request->password);
|
||||
|
||||
// store user into database
|
||||
$user->save();
|
||||
$data = $request->all();
|
||||
$data['username'] = $username;
|
||||
$user = $userRepository->create($data);
|
||||
|
||||
// fire event
|
||||
Event::fire(new CreateNewUserEvent($user));
|
||||
|
||||
@@ -4,25 +4,44 @@ namespace App\Http\Controllers\Admin\Users;
|
||||
|
||||
use App\CMS\Enumerations\UserRoles;
|
||||
use App\CMS\Enumerations\UserStates;
|
||||
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\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class EditUser extends Controller
|
||||
{
|
||||
public function getEditUser($id = null)
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
private $userRepository;
|
||||
|
||||
/**
|
||||
* EditUser constructor.
|
||||
*
|
||||
* @param UserRepository $userRepository
|
||||
*/
|
||||
public function __construct(UserRepository $userRepository)
|
||||
{
|
||||
// when no user specified, lets assume we want to edit "me"
|
||||
if (!$id) {
|
||||
$id = Auth::user()->id;
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
// try to find given user
|
||||
$user = User::findOrFail($id);
|
||||
/**
|
||||
* Display form for editing user
|
||||
*
|
||||
* @param User|null $user
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getEditUser(User $user = null)
|
||||
{
|
||||
// when no user specified, lets assume we want to edit "me"
|
||||
if (!$user->exists()) {
|
||||
$user = Auth::user();
|
||||
}
|
||||
|
||||
$states = UserStates::getWithTranslations();
|
||||
$roles = UserRoles::getWithTranslations();
|
||||
@@ -35,49 +54,26 @@ class EditUser extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit user - store information
|
||||
*
|
||||
* @param EditUserRequest $request
|
||||
* @param $id
|
||||
* @param User $user
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @internal param $id
|
||||
*/
|
||||
public function postEdit(EditUserRequest $request, $id)
|
||||
public function postEdit(EditUserRequest $request, User $user)
|
||||
{
|
||||
$loggedUser = Auth::user();
|
||||
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
// non-admin user is trying to edit someone else
|
||||
if ($loggedUser->role != User::ROLE_ADMIN && $id != $loggedUser->id) {
|
||||
if ($loggedUser->role != User::ROLE_ADMIN && $user->id != $loggedUser->id) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans('auth.accessDenied'));
|
||||
}
|
||||
|
||||
// update username if set
|
||||
if (isset($request->username)) {
|
||||
$user->username = $request->username;
|
||||
}
|
||||
|
||||
// change name (if set)
|
||||
if (isset($request->name)) {
|
||||
$user->name = $request->name;
|
||||
}
|
||||
|
||||
if (isset($request->role)) {
|
||||
$user->role = $request->role;
|
||||
}
|
||||
|
||||
if (isset($request->status)) {
|
||||
$user->status = $request->status;
|
||||
}
|
||||
|
||||
if (isset($request->password)) {
|
||||
$user->password = Hash::make($request->password);
|
||||
}
|
||||
|
||||
$user->email = $request->email;
|
||||
|
||||
$user->save();
|
||||
$this->userRepository->update($user, $request->all());
|
||||
|
||||
// fire event about editing user
|
||||
Event::fire(new EditUserEvent($user));
|
||||
|
||||
@@ -22,18 +22,14 @@ class UserDetail extends Controller
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
public function getDetail($id = null)
|
||||
public function getDetail(User $user = null)
|
||||
{
|
||||
// when no user specified, lets assume we want to edit "me"
|
||||
if (!$id) {
|
||||
$id = Auth::user()->id;
|
||||
if (!$user->exists()) {
|
||||
$id = Auth::user();
|
||||
}
|
||||
|
||||
// try to find given user
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
$actions = $this->log->getUserActions($id, 10);
|
||||
|
||||
$actions = $this->log->getUserActions($user->id, 10);
|
||||
$roles = UserRoles::getWithTranslations();
|
||||
$states = UserStates::getWithTranslations();
|
||||
|
||||
|
||||
@@ -2,19 +2,34 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\Widgets\Areas;
|
||||
|
||||
use App\CMS\Repositories\Widgets\WidgetArea as WidgetAreaRepository;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\NewWidgetAreaRequest;
|
||||
use App\Models\Widgets\WidgetArea;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class CreateNewWidgetArea extends Controller
|
||||
{
|
||||
/**
|
||||
* @var WidgetAreaRepository
|
||||
*/
|
||||
private $widgetAreaRepository;
|
||||
|
||||
/**
|
||||
* CreateNewWidgetArea constructor.
|
||||
*
|
||||
* @param WidgetAreaRepository $widgetAreaRepository
|
||||
*/
|
||||
public function __construct(WidgetAreaRepository $widgetAreaRepository)
|
||||
{
|
||||
$this->widgetAreaRepository = $widgetAreaRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form for new widget area
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getNew()
|
||||
public function create()
|
||||
{
|
||||
return view('admin.widgets.area.new', ['area' => new WidgetArea()]);
|
||||
}
|
||||
@@ -24,18 +39,9 @@ class CreateNewWidgetArea extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postNew(NewWidgetAreaRequest $request)
|
||||
public function store(NewWidgetAreaRequest $request)
|
||||
{
|
||||
$parameters = [
|
||||
'code' => $request->code,
|
||||
'name' => $request->name,
|
||||
'description' => $request->description
|
||||
];
|
||||
|
||||
$area = WidgetArea::create($parameters);
|
||||
|
||||
// fire event with new widget area
|
||||
Event::fire(new \App\Events\CreateNewWidgetArea($area));
|
||||
$this->widgetAreaRepository->create($request);
|
||||
|
||||
// redirect with success notification
|
||||
return redirect()
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\Widgets\Areas;
|
||||
|
||||
use App\CMS\Repositories\Widgets\WidgetArea as WidgetAreaRepository;
|
||||
use App\Events\DeleteWidgetArea;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\EditWidgetAreaRequest;
|
||||
use App\Models\Widgets\Widget;
|
||||
@@ -13,22 +15,38 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class EditWidgetArea extends Controller
|
||||
{
|
||||
/**
|
||||
* @var WidgetAreaRepository
|
||||
*/
|
||||
private $widgetAreaRepository;
|
||||
|
||||
/**
|
||||
* EditWidgetArea constructor.
|
||||
*
|
||||
* @param WidgetAreaRepository $widgetAreaRepository
|
||||
*/
|
||||
public function __construct(WidgetAreaRepository $widgetAreaRepository)
|
||||
{
|
||||
$this->widgetAreaRepository = $widgetAreaRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for editing given widget area
|
||||
*
|
||||
* @param $id
|
||||
* @param WidgetArea $widgetArea
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
*/
|
||||
public function getEdit($id)
|
||||
public function edit(WidgetArea $widgetArea)
|
||||
{
|
||||
$area = WidgetArea::findOrFail($id);
|
||||
$associatedWidgetIds = WidgetInWidgetArea::getWidgetIdsFromArea($area->id);
|
||||
return view("test");
|
||||
$associatedWidgetIds = WidgetInWidgetArea::getWidgetIdsFromArea($widgetArea->id);
|
||||
$widgets = Widget::where('language', LaravelLocalization::getCurrentLocale())
|
||||
->paginate(25);
|
||||
|
||||
return view('admin.widgets.area.edit', [
|
||||
'area' => $area,
|
||||
'area' => $widgetArea,
|
||||
'widgets' => $widgets,
|
||||
'associatedWidgetIds' => $associatedWidgetIds
|
||||
]);
|
||||
@@ -36,26 +54,14 @@ class EditWidgetArea extends Controller
|
||||
|
||||
/**
|
||||
* @param EditWidgetAreaRequest $request
|
||||
* @param $id
|
||||
* @param WidgetArea $widgetArea
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
*/
|
||||
public function postEdit(EditWidgetAreaRequest $request, $id)
|
||||
public function update(EditWidgetAreaRequest $request, WidgetArea $widgetArea)
|
||||
{
|
||||
try {
|
||||
$area = WidgetArea::findOrFail($id);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->invalidArea();
|
||||
}
|
||||
|
||||
$area->name = $request->name;
|
||||
$area->description = $request->description;
|
||||
|
||||
$area->timestamps = true;
|
||||
$area->save();
|
||||
|
||||
// fire event with new widget area
|
||||
Event::fire(new \App\Events\EditWidgetArea($area));
|
||||
$this->widgetAreaRepository->update($widgetArea, $request);
|
||||
|
||||
return redirect()
|
||||
->route('widgetareas.overview')
|
||||
@@ -65,47 +71,28 @@ class EditWidgetArea extends Controller
|
||||
/**
|
||||
* Hard deletes widget area
|
||||
*
|
||||
* @param $id
|
||||
* @param WidgetArea $widgetArea
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteArea($id)
|
||||
public function delete(WidgetArea $widgetArea)
|
||||
{
|
||||
// try to find area
|
||||
try {
|
||||
$area = WidgetArea::findOrFail($id);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->invalidArea();
|
||||
}
|
||||
|
||||
// check if widget area is deletable
|
||||
if (!$area->deletable) {
|
||||
if (!$widgetArea->deletable) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans('admin/widgetAreas.notDeletableArea'));
|
||||
}
|
||||
|
||||
// delete area
|
||||
$area->delete();
|
||||
$widgetArea->delete();
|
||||
|
||||
// fire event with new widget area
|
||||
Event::fire(new \App\Events\DeleteWidgetArea($area));
|
||||
Event::fire(new DeleteWidgetArea($widgetArea));
|
||||
|
||||
// redirect and inform user
|
||||
return redirect()
|
||||
->route('widgetareas.overview')
|
||||
->with('success', trans('admin/widgetAreas.successfullyDeleted'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect user to overview with message about invalid widget area
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
private function invalidArea()
|
||||
{
|
||||
return redirect()
|
||||
->route('widgetareas.overview')
|
||||
->with('error', trans('admin/widgetAreas.invalidArea'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\Widgets;
|
||||
|
||||
use App\CMS\Repositories\Widgets\Widget;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\NewWidgetRequest;
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
|
||||
class CreateNewWidget extends Controller
|
||||
{
|
||||
@@ -23,14 +23,13 @@ class CreateNewWidget extends Controller
|
||||
/**
|
||||
* Form for new widget area
|
||||
*
|
||||
* @param $type
|
||||
* @param WidgetType $widgetType
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
*/
|
||||
public function getNew($type)
|
||||
public function getNew(WidgetType $widgetType)
|
||||
{
|
||||
$widgetType = WidgetType::findOrFail($type);
|
||||
|
||||
$presenter = call_user_func([$widgetType->handler, 'getPresenter']);
|
||||
|
||||
return call_user_func([$presenter, 'renderAddForm'], $widgetType);
|
||||
@@ -40,23 +39,22 @@ class CreateNewWidget extends Controller
|
||||
* Create new instance of given widget type
|
||||
*
|
||||
* @param NewWidgetRequest $request
|
||||
* @param $type
|
||||
*
|
||||
* @param WidgetType $widgetType
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postNew(NewWidgetRequest $request, $type)
|
||||
public function postNew(NewWidgetRequest $request, WidgetType $widgetType)
|
||||
{
|
||||
$widgetType = WidgetType::findOrFail($type);
|
||||
|
||||
// try to save this widget
|
||||
try {
|
||||
$this->widget->createNew($widgetType, $request);
|
||||
} catch (MissingParameterException $e) {
|
||||
// user omitted some value
|
||||
return $this->invalidWidget($type, $e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
// something went wrong
|
||||
return $this->invalidWidget($type, trans('admin/widgets.cannotSave', ['exception' => $e->getMessage()]));
|
||||
return redirect()
|
||||
->back()
|
||||
->withInput()
|
||||
->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
// redirect with success notification
|
||||
@@ -64,12 +62,4 @@ class CreateNewWidget extends Controller
|
||||
->route('widgets.overview')
|
||||
->with('success', trans('admin/widgets.successfullyCreated'));
|
||||
}
|
||||
|
||||
private function invalidWidget($widgetType, $error)
|
||||
{
|
||||
return redirect()
|
||||
->route('widgets.new', ['type' => $widgetType])
|
||||
->withInput()
|
||||
->with('error', $error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Widgets;
|
||||
|
||||
use App\CMS\Repositories\Widgets\Widget as WidgetRepository;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\EditWidgetRequest;
|
||||
use App\Models\Widgets\Widget;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EditWidget extends Controller
|
||||
{
|
||||
/**
|
||||
* @var WidgetRepository
|
||||
*/
|
||||
private $widgetRepository;
|
||||
|
||||
/**
|
||||
* EditWidget constructor.
|
||||
*
|
||||
* @param WidgetRepository $widgetRepository
|
||||
*/
|
||||
public function __construct(WidgetRepository $widgetRepository)
|
||||
{
|
||||
$this->widgetRepository = $widgetRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render edit form
|
||||
*
|
||||
* @param $id
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEdit($id)
|
||||
public function getEdit(Widget $widget)
|
||||
{
|
||||
$widget = Widget::findOrFail($id);
|
||||
$widget->settings = json_decode($widget->settings);
|
||||
|
||||
$presenter = call_user_func([$widget->widget_type_handler, 'getPresenter']);
|
||||
|
||||
return call_user_func([$presenter, 'renderEditForm'], $widget);
|
||||
@@ -30,24 +43,14 @@ class EditWidget extends Controller
|
||||
* Save changes into database
|
||||
*
|
||||
* @param EditWidgetRequest $request
|
||||
* @param $widget
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postEdit(EditWidgetRequest $request, $widget)
|
||||
public function postEdit(EditWidgetRequest $request, Widget $widget)
|
||||
{
|
||||
// create new widget
|
||||
$widget = Widget::findOrFail($widget);
|
||||
|
||||
// update name
|
||||
$widget->name = $request->name;
|
||||
$widget->container_class = $request->containerClass;
|
||||
$widget->container_id = empty($request->containerId) ? null : $request->containerId;
|
||||
$widget->description = $request->description;
|
||||
|
||||
// try to save this widget
|
||||
try {
|
||||
$widget->settings = json_encode(call_user_func([$widget->widget_type_handler, 'save'], $request));
|
||||
$this->widgetRepository->edit($widget, $request);
|
||||
} catch (MissingParameterException $e) {
|
||||
// user omitted some value
|
||||
return $this->invalidWidget($e->getMessage());
|
||||
@@ -56,12 +59,6 @@ class EditWidget extends Controller
|
||||
return $this->invalidWidget(trans('admin/widgets.cannotSave', ['exception' => $e->getMessage()]));
|
||||
}
|
||||
|
||||
// save into database
|
||||
$widget->save();
|
||||
|
||||
// fire event with editing widget
|
||||
Event::fire(new \App\Events\EditWidget($widget));
|
||||
|
||||
// redirect with success notification
|
||||
return redirect()
|
||||
->back()
|
||||
@@ -71,15 +68,12 @@ class EditWidget extends Controller
|
||||
/**
|
||||
* Deletes widget
|
||||
*
|
||||
* @param $id
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteWidget($id)
|
||||
public function deleteWidget(Widget $widget)
|
||||
{
|
||||
// create new widget
|
||||
$widget = Widget::findOrFail($id);
|
||||
|
||||
// check if widget area is deletable
|
||||
if (!$widget->deletable) {
|
||||
return redirect()
|
||||
|
||||
@@ -7,7 +7,7 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class WidgetsOverview extends Controller
|
||||
{
|
||||
public function getOverview()
|
||||
public function index()
|
||||
{
|
||||
$widgets = Widget::where('language', LaravelLocalization::getCurrentLocale())
|
||||
->paginate(25);
|
||||
|
||||
@@ -23,7 +23,7 @@ class Controller extends BaseController
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public static function VisitorsView($template, $data = [], $mergeData = [])
|
||||
public static function visitorsView($template, $data = [], $mergeData = [])
|
||||
{
|
||||
$view = Template::name($template);
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Http\Controllers\Visitor;
|
||||
|
||||
use App\CMS\Contracts\Repositories\Content;
|
||||
use App\CMS\Helpers\PageRenderer;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Content\Content as ContentModel;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -24,11 +23,20 @@ class ContentPage extends Controller
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load page by URL
|
||||
*
|
||||
* This method also caches content
|
||||
*
|
||||
* @param $url
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPage($url)
|
||||
{
|
||||
$contentModel = $this->content;
|
||||
$page = Cache::remember('content-' . $url, setting('contentCacheLifetime', 5), function () use ($contentModel, $url) {
|
||||
return $contentModel->getByURL($url);
|
||||
$contentRepository = $this->content;
|
||||
$page = Cache::remember('content-' . $url, setting('contentCacheLifetime', 5), function () use ($contentRepository, $url) {
|
||||
return $contentRepository->getByURL($url);
|
||||
});
|
||||
|
||||
// no page available
|
||||
@@ -42,7 +50,7 @@ class ContentPage extends Controller
|
||||
/**
|
||||
* Method used for rendering page for visitor
|
||||
*
|
||||
* @param Content $page
|
||||
* @param ContentModel $page
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
@@ -54,9 +62,10 @@ class ContentPage extends Controller
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// add one new "view" for page
|
||||
$page->view();
|
||||
$displayPipeline = app('displayPipeline');
|
||||
$page = $displayPipeline->run($page);
|
||||
|
||||
return Controller::visitorsView($page->template, ['page' => $page]);
|
||||
|
||||
return PageRenderer::render($page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class Homepage extends ContentPage
|
||||
{
|
||||
// try to find some homepage
|
||||
$contentModel = $this->content;
|
||||
$page = Cache::remember('hp', setting('homepageCacheLifetime', 5), function () use ($contentModel) {
|
||||
$page = Cache::remember('homepage', setting('homepageCacheLifetime', 5), function () use ($contentModel) {
|
||||
return $contentModel->getHomepage();
|
||||
});
|
||||
|
||||
|
||||
+2
-6
@@ -18,9 +18,7 @@ class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
@@ -33,7 +31,6 @@ class Kernel extends HttpKernel
|
||||
];
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
@@ -53,9 +50,7 @@ class Kernel extends HttpKernel
|
||||
];
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
@@ -66,6 +61,7 @@ class Kernel extends HttpKernel
|
||||
'throttle' => ThrottleRequests::class,
|
||||
'localize' => LaravelLocalizationRoutes::class,
|
||||
'localizationRedirect' => LaravelLocalizationRedirectFilter::class,
|
||||
'localeSessionRedirect' => LocaleSessionRedirect::class
|
||||
'localeSessionRedirect' => LocaleSessionRedirect::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
];
|
||||
}
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ Route::pattern('url', '[0-9\-a-z]+');
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
Route::group(['prefix' => LaravelLocalization::setLocale()], function () {
|
||||
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['bindings']], function () {
|
||||
/**
|
||||
* This route group serves to handle request in admin
|
||||
*/
|
||||
@@ -65,7 +65,7 @@ Route::group(['prefix' => LaravelLocalization::setLocale()], function () {
|
||||
->name('login');
|
||||
|
||||
// route for sitemap
|
||||
Route::get('sitemap.xml', 'Sitemap@getMap')
|
||||
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)
|
||||
|
||||
@@ -9,34 +9,34 @@ Route::group(['namespace' => 'Contents'], function () {
|
||||
->name('content.new');
|
||||
|
||||
// form for editing existing static page
|
||||
Route::get('content/edit/{id}', 'EditContent@edit')
|
||||
Route::get('content/edit/{page}', 'EditContent@edit')
|
||||
->name('content.edit');
|
||||
|
||||
// post method for creating new static page
|
||||
Route::post('content/new/{moduleId}', 'CreateNewContent@store')
|
||||
Route::post('content/new/{module}', 'CreateNewContent@store')
|
||||
->name('content.newPost');
|
||||
|
||||
// post method for creating new static page
|
||||
Route::post('content/edit/{id}', 'EditContent@update')
|
||||
Route::post('content/edit/{page}', 'EditContent@update')
|
||||
->name('content.editPost');
|
||||
|
||||
// change status of page (protected, public or draft)
|
||||
Route::get('content/status/{id}/{status}', 'ContentActions@changeStatus')
|
||||
Route::get('content/status/{page}/{status}', 'ContentActions@changeStatus')
|
||||
->name('content.changeStatus');
|
||||
|
||||
// set homepage
|
||||
Route::get('content/homepage/{id}', 'ContentActions@setHomepage')
|
||||
Route::get('content/homepage/{page}', 'ContentActions@setHomepage')
|
||||
->name('content.setHomepage');
|
||||
|
||||
// delete page
|
||||
Route::get('content/delete/{id}', 'ContentActions@delete')
|
||||
Route::get('content/delete/{page}', 'ContentActions@delete')
|
||||
->name('content.delete');
|
||||
|
||||
// history of changes for specified page
|
||||
Route::get('history/{id}', 'History@getOverview')
|
||||
Route::get('history/{page}', 'History@getOverview')
|
||||
->name('content.history');
|
||||
|
||||
// history of changes for specified page
|
||||
Route::get('history/{revision}/{id}', 'History@getDiff')
|
||||
Route::get('history/{revision}', 'History@getDiff')
|
||||
->name('history.diff');
|
||||
});
|
||||
@@ -5,9 +5,6 @@ Route::group(['namespace' => 'FileManager'], function () {
|
||||
->name('upload.overview');
|
||||
|
||||
// uploader methods
|
||||
Route::get('directories/new/{parentDirectory?}', 'CreateNewDirectory@create')
|
||||
->name('upload.newDirectory');
|
||||
|
||||
Route::get('directories/edit/{directory}', 'EditDirectory@edit')
|
||||
->name('upload.editDirectory');
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
// these routes are available only for user with role admin
|
||||
Route::group(['middleware' => 'onlyAdmin', 'namespace' => 'Templates'], function () {
|
||||
Route::get('templates/overview/path/{id}', 'TemplateOverview@getPath')
|
||||
Route::get('templates/overview/path/{templatePath}', 'TemplateOverview@getPath')
|
||||
->name('templates.overview');
|
||||
|
||||
Route::post('templates/copy', 'CopyTemplate@createCopy')
|
||||
->name('templates.postCopy');
|
||||
|
||||
Route::get('templates/edit/{id}', 'EditTemplate@getEdit')
|
||||
Route::get('templates/edit/{template}', 'EditTemplate@getEdit')
|
||||
->name('templates.edit');
|
||||
|
||||
Route::post('templates/edit/{id}', 'EditTemplate@postEdit')
|
||||
Route::post('templates/edit/{template}', 'EditTemplate@postEdit')
|
||||
->name('templates.postEdit');
|
||||
});
|
||||
@@ -10,15 +10,15 @@ Route::group(['namespace' => 'Users'], function () {
|
||||
->name('users.newPost');
|
||||
|
||||
// display form for edit of existing user
|
||||
Route::get('users/edit/{id}', 'EditUser@getEditUser')
|
||||
Route::get('users/edit/{user}', 'EditUser@getEditUser')
|
||||
->name('users.edit');
|
||||
|
||||
// display user detail in admin
|
||||
Route::get('users/detail/{id?}', 'UserDetail@getDetail')
|
||||
Route::get('users/detail/{user?}', 'UserDetail@getDetail')
|
||||
->name('users.detail');
|
||||
|
||||
// method for saving edited data of user
|
||||
Route::post('users/edit/{id}', 'EditUser@postEdit')
|
||||
Route::post('users/edit/{user}', 'EditUser@postEdit')
|
||||
->name('users.editPost');
|
||||
|
||||
// display list of all users registered into our system
|
||||
|
||||
@@ -3,35 +3,35 @@
|
||||
Route::group(['namespace' => 'Widgets'], function () {
|
||||
|
||||
// list of all installed widget types
|
||||
Route::get('widgets/overview', 'WidgetsOverview@getOverview')
|
||||
Route::get('widgets', 'WidgetsOverview@index')
|
||||
->name('widgets.overview');
|
||||
|
||||
// create new instance of widget of given type
|
||||
Route::get('widgets/new/{type}', 'CreateNewWidget@getNew')
|
||||
Route::get('widgets/new/{widgetType}', 'CreateNewWidget@getNew')
|
||||
->name('widgets.new');
|
||||
|
||||
Route::post('widgets/new/{type}', 'CreateNewWidget@postNew')
|
||||
Route::post('widgets/new/{widgetType}', 'CreateNewWidget@postNew')
|
||||
->name('widgets.postNew');
|
||||
|
||||
// edit widget settings
|
||||
Route::get('widgets/edit/{id}', 'EditWidget@getEdit')
|
||||
Route::get('widgets/edit/{widget}', 'EditWidget@getEdit')
|
||||
->name('widgets.edit');
|
||||
|
||||
// delete widget settings
|
||||
Route::get('widgets/delete/{id}', 'EditWidget@deleteWidget')
|
||||
Route::get('widgets/delete/{widget}', 'EditWidget@deleteWidget')
|
||||
->name('widgets.delete');
|
||||
|
||||
Route::post('widgets/edit/{id}', 'EditWidget@postEdit')
|
||||
Route::post('widgets/edit/{widget}', 'EditWidget@postEdit')
|
||||
->name('widgets.postEdit');
|
||||
|
||||
// display form for association of widget and widget area
|
||||
Route::get('widgets/associate/{widgetArea}', 'AssociateWidget@getList')
|
||||
->name('widgets.associate');
|
||||
|
||||
Route::get('widgets/deassociate/{widgetId}/{widgetArea}', 'AssociateWidget@deleteAssociation')
|
||||
Route::get('widgets/deassociate/{widget}/{widgetArea}', 'AssociateWidget@deleteAssociation')
|
||||
->name('widgets.deleteAssociation');
|
||||
|
||||
Route::get('widgets/associate/{widgetId}/{widgetArea}', 'AssociateWidget@makeAssociation')
|
||||
Route::get('widgets/associate/{widget}/{widgetArea}', 'AssociateWidget@makeAssociation')
|
||||
->name('widgets.makeAssociation');
|
||||
|
||||
Route::group(['namespace' => 'Areas'], function () {
|
||||
@@ -39,22 +39,22 @@ Route::group(['namespace' => 'Widgets'], function () {
|
||||
->name('widgetareas.overview');
|
||||
|
||||
// form for new widget area
|
||||
Route::get('widgets/areas/new', 'CreateNewWidgetArea@getNew')
|
||||
Route::get('widgets/areas/new', 'CreateNewWidgetArea@create')
|
||||
->name('widgetareas.new');
|
||||
|
||||
// form for new widget area
|
||||
Route::post('widgets/areas/new', 'CreateNewWidgetArea@postNew')
|
||||
Route::post('widgets/areas/new', 'CreateNewWidgetArea@store')
|
||||
->name('widgetareas.postNew');
|
||||
|
||||
// edit form for widget area
|
||||
Route::get('widgets/areas/edit/{id}', 'EditWidgetArea@getEdit')
|
||||
Route::get('widgets/areas/edit/{widgetArea}', 'EditWidgetArea@edit')
|
||||
->name('widgetareas.edit');
|
||||
|
||||
Route::post('widgets/areas/edit/{id}', 'EditWidgetArea@postEdit')
|
||||
Route::post('widgets/areas/edit/{widgetArea}', 'EditWidgetArea@update')
|
||||
->name('widgetareas.postEdit');
|
||||
|
||||
// edit form for widget area
|
||||
Route::get('widgets/areas/delete/{id}', 'EditWidgetArea@deleteArea')
|
||||
Route::get('widgets/areas/delete/{widgetArea}', 'EditWidgetArea@delete')
|
||||
->name('widgetareas.delete');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\UploadFile;
|
||||
use Illuminate\Support\Facades\File as FileFacade;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Constraint;
|
||||
use Intervention\Image\Facades\Image;
|
||||
use Symfony\Component\HttpFoundation\File\File as SymphonyFile;
|
||||
|
||||
class CreateImageThumbnail
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param UploadFile $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(UploadFile $event)
|
||||
{
|
||||
$uploadedFile = $event->uploadedFile;
|
||||
|
||||
// is uploaded file an image?
|
||||
if (!Str::startsWith($uploadedFile->getMimeType(), 'image')) {
|
||||
return;
|
||||
}
|
||||
// yes, create thumbnail
|
||||
$this->createThumbnail($uploadedFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create thumbnail of given image
|
||||
*
|
||||
* @param SymphonyFile $file
|
||||
*/
|
||||
private function createThumbnail(SymphonyFile $file)
|
||||
{
|
||||
// does thumbnail directory exist?
|
||||
if (!is_dir(config('app.thumbnail_path'))) {
|
||||
FileFacade::makeDirectory(config('app.thumbnail_path'));
|
||||
}
|
||||
|
||||
// get image instance
|
||||
$image = Image::make(config('app.upload_path') . DIRECTORY_SEPARATOR . $file->getFilename());
|
||||
|
||||
// resize image and keep aspect ration
|
||||
$image->resize(env('THUMBNAIL_WIDTH', setting('previewSize', 300)), null, function (Constraint $constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
});
|
||||
|
||||
// save thumbnail with lower quality
|
||||
$image->save(config('app.thumbnail_path') . DIRECTORY_SEPARATOR . $file->getFilename(), 75);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ use Modules\Categories\Entities\Category;
|
||||
*/
|
||||
class Content extends Model
|
||||
{
|
||||
use SoftDeletes, ModelTraits\Content, Nullable;
|
||||
use SoftDeletes, Nullable;
|
||||
public $timestamps = true;
|
||||
protected $fillable = [
|
||||
'userId',
|
||||
@@ -163,4 +163,10 @@ class Content extends Model
|
||||
|
||||
return parent::save($options);
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
$this->timestamps = false;
|
||||
$this->increment('viewed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
namespace App\Models\Content\ModelTraits;
|
||||
|
||||
use App\Models\Content\ContentHasFile;
|
||||
use App\Models\FileManager\Directory;
|
||||
use App\Models\FileManager\File;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
trait Content
|
||||
{
|
||||
/**
|
||||
* Upload and assign files to newly created content page
|
||||
*
|
||||
* @param $files
|
||||
* @param $assignedFiles
|
||||
* @param null $revisionId
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function uploadRelatedFiles($files, $assignedFiles = [], $revisionId = null)
|
||||
{
|
||||
$changed = 0;
|
||||
|
||||
// check if any file was removed
|
||||
if ($revisionId) {
|
||||
$changed += $this->removeRelatedFiles($revisionId, $assignedFiles);
|
||||
}
|
||||
|
||||
// allow uploading only on created pages
|
||||
if (!$this->id || !$files[0]) {
|
||||
return $changed;
|
||||
}
|
||||
|
||||
// find or create new directory for files assigned to content
|
||||
$directory = Directory::firstOrCreate([
|
||||
'name' => '.content_files',
|
||||
'hidden' => true
|
||||
]);
|
||||
$data = new \stdClass();
|
||||
$data->directoryId = $directory->id;
|
||||
|
||||
$fileModel = App::make(File::class);
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!$file) {
|
||||
continue;
|
||||
}
|
||||
$uploaded = $fileModel->upload($file, $data);
|
||||
|
||||
// add assignement
|
||||
ContentHasFile::create([
|
||||
'file_id' => $uploaded['id'],
|
||||
'content_id' => $this->id
|
||||
]);
|
||||
|
||||
if ($revisionId) {
|
||||
$this->saveHistory($revisionId, 'file', null, ['file' => $uploaded['file']->getClientOriginalName()]);
|
||||
}
|
||||
|
||||
$changed++;
|
||||
}
|
||||
|
||||
return $changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete files from association
|
||||
*
|
||||
* @param $revisionId
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function removeRelatedFiles($revisionId, $assignedFiles)
|
||||
{
|
||||
$allFiles = $this->files()
|
||||
->whereNotIn('id', $assignedFiles)
|
||||
->get();
|
||||
|
||||
foreach ($allFiles as $file) {
|
||||
$this->saveHistory($revisionId, 'file', $file->original_filename, ['file' => null]);
|
||||
|
||||
ContentHasFile::where('content_id', $this->id)
|
||||
->where('file_id', $file->id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
return count($allFiles);
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
$this->viewed++;
|
||||
$this->save(['timestamps' => false]);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ trait ContentHistory
|
||||
/**
|
||||
* Returns history grouped by revisions (edit_batches)
|
||||
*
|
||||
* @param Content $content
|
||||
* @param ContentModel $content
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
||||
+10
-1
@@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class Module extends Model
|
||||
{
|
||||
use ModelTraits\Module;
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'handler',
|
||||
@@ -23,4 +22,14 @@ class Module extends Model
|
||||
'manages_content',
|
||||
'is_template'
|
||||
];
|
||||
protected $casts = [
|
||||
'module_settings' => 'array',
|
||||
'is_template' => 'boolean',
|
||||
'has_submodules' => 'boolean'
|
||||
];
|
||||
|
||||
public function getRouteKeyName()
|
||||
{
|
||||
return 'alias';
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user