Merge branch 'template_support' into doucovanineratovice.cz
This commit is contained in:
+4
-5
@@ -1,8 +1,8 @@
|
|||||||
APP_ENV=testing
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_ENV=
|
||||||
APP_KEY=ZKZAzM23wQ6BPji6zffBjaTzZ3yW7zKQ
|
APP_DEBUG=
|
||||||
|
|
||||||
DB_HOST=localhost
|
DB_HOST=
|
||||||
DB_DATABASE=
|
DB_DATABASE=
|
||||||
DB_USERNAME=
|
DB_USERNAME=
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
@@ -17,4 +17,3 @@ MAIL_PASSWORD=
|
|||||||
SITE_URL=/
|
SITE_URL=/
|
||||||
UPLOAD_URL=/public/uploads
|
UPLOAD_URL=/public/uploads
|
||||||
THUMBNAILS_URL=/uploads/thumbnails
|
THUMBNAILS_URL=/uploads/thumbnails
|
||||||
THEME=
|
|
||||||
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
# published files from modules
|
# published files from modules
|
||||||
/resources/views/modules
|
|
||||||
/public/modules
|
/public/modules
|
||||||
/resources/views/vendor
|
|
||||||
/public/assets
|
/public/assets
|
||||||
|
/resources/views/modules
|
||||||
|
/resources/views/visitor
|
||||||
|
/resources/views/vendor
|
||||||
|
|
||||||
# directories with custom templates
|
# directories with custom templates
|
||||||
**/views/**/custom/*
|
**/views/**/custom/*
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ class InstallModule extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
@@ -56,6 +54,9 @@ class InstallModule extends Command
|
|||||||
// get config
|
// get config
|
||||||
$config = $this->loadConfig();
|
$config = $this->loadConfig();
|
||||||
|
|
||||||
|
if (empty($config))
|
||||||
|
return;
|
||||||
|
|
||||||
// check if it is valid
|
// check if it is valid
|
||||||
$this->checkMandatoryFields($config);
|
$this->checkMandatoryFields($config);
|
||||||
|
|
||||||
@@ -78,6 +79,9 @@ class InstallModule extends Command
|
|||||||
$basePath = $this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR;
|
$basePath = $this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR;
|
||||||
$path = $basePath . 'Config' . DIRECTORY_SEPARATOR . 'config.php';
|
$path = $basePath . 'Config' . DIRECTORY_SEPARATOR . 'config.php';
|
||||||
|
|
||||||
|
if (basename($basePath) == 'Database')
|
||||||
|
return [];
|
||||||
|
|
||||||
// check if module has Config/config.php file
|
// check if module has Config/config.php file
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
$path = $basePath . 'info.php';
|
$path = $basePath . 'info.php';
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Module;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
|
class SetTemplate extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'template:set {template} {publish?}';
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Install template';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$template = $this->argument('template');
|
||||||
|
$publish = $this->argument('publish') !== 'no-publish';
|
||||||
|
|
||||||
|
$templatePath = app_path('../templates/' . $template);
|
||||||
|
if (!is_dir($templatePath) || !file_exists($templatePath . '/config.php')) {
|
||||||
|
throw new NotFoundHttpException('Invalid template ' . $template . '!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to find currently installed template
|
||||||
|
$current = Module::where('is_template', true)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
// install template
|
||||||
|
$config = @include $templatePath . '/config.php';
|
||||||
|
$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.'.');
|
||||||
|
$confirm = $this->ask('Uninstall it and install *' . trans($config['name']) . '*? All data associated with installed template will be lost! [y/n]');
|
||||||
|
|
||||||
|
if ($confirm === 'y') {
|
||||||
|
$this->line('Uninstalling ' . $current->name . '.');
|
||||||
|
$current->uninstall();
|
||||||
|
} else {
|
||||||
|
$this->line('Aborting installation.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Module::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// theme written
|
||||||
|
$this->line('Template successfully set up.');
|
||||||
|
|
||||||
|
if ($publish) {
|
||||||
|
$this->line('');
|
||||||
|
$this->line(' ** PUBLISHING ASSETS AND VIEWS **');
|
||||||
|
// publish assets and views for module and theme
|
||||||
|
$this->call('vendor:publish');
|
||||||
|
$this->call('vendor:publish', ['--tag' => ['public-assets'], '--force' => true]);
|
||||||
|
$this->call('vendor:publish', ['--tag' => ['module-views'], '--force' => true]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
||||||
|
|
||||||
class SetTheme extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'theme:set {theme_name}';
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Set theme for visitor area';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$theme = $this->argument('theme_name');
|
|
||||||
|
|
||||||
if (!is_dir(resource_path('views/visitor/' . $theme))) {
|
|
||||||
throw new NotFoundHttpException('Invalid theme ' . $theme . '!');
|
|
||||||
}
|
|
||||||
|
|
||||||
// load .env file
|
|
||||||
$envFile = base_path('.env');
|
|
||||||
$env = file_get_contents($envFile);
|
|
||||||
|
|
||||||
if (!Str::contains($env, 'THEME=')) {
|
|
||||||
$env = sprintf("%s\nTHEME=%s\n", $env, $theme);
|
|
||||||
} else {
|
|
||||||
$env = preg_replace('/THEME=(.*)/i', 'THEME=' . $theme, $env, -1, $cnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to write content
|
|
||||||
$bytesWritten = file_put_contents($envFile, $env);
|
|
||||||
|
|
||||||
// check if write was successfull
|
|
||||||
if (!$bytesWritten) {
|
|
||||||
throw new \Exception('Cannot write to ' . base_path('.env') . '. Add THEME=' . $theme . ' to your .env file manualy.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// theme written
|
|
||||||
$this->line('Theme successfully setup.');
|
|
||||||
$this->line('');
|
|
||||||
$this->line(' ** PUBLISHING ASSETS AND VIEWS **');
|
|
||||||
// publish assets and views for module and theme
|
|
||||||
$this->call('vendor:publish', ['--tag' => ['public-assets'], '--force' => true]);
|
|
||||||
$this->call('vendor:publish', ['--tag' => ['module-views'], '--force' => true]);
|
|
||||||
$this->call('vendor:publish');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -29,15 +29,32 @@ class TranslateAll extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->call('translate:dir', ['dir' => 'resources/lang']);
|
$this->call('translate:dir', ['dir' => 'resources/lang']);
|
||||||
|
|
||||||
$modules = File::directories('modules');
|
$this->crawlDirectory('modules');
|
||||||
foreach ($modules as $module) {
|
$this->crawlDirectory('templates', ['templates/Base']);
|
||||||
$this->call('translate:dir', ['dir' => $module.'/Resources/lang']);
|
$this->crawlDirectory('templates/Base');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crawl directories and search for directories with translations
|
||||||
|
*
|
||||||
|
* @param $directory
|
||||||
|
* @param array $ignoredDirectories
|
||||||
|
*/
|
||||||
|
protected function crawlDirectory($directory, $ignoredDirectories = [])
|
||||||
|
{
|
||||||
|
$directories = File::directories($directory);
|
||||||
|
foreach ($directories as $dir) {
|
||||||
|
|
||||||
|
if (in_array($dir, $ignoredDirectories)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->call('translate:dir', ['dir' => $dir . '/Resources/lang']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+13
-4
@@ -6,7 +6,7 @@ use Illuminate\Console\Command;
|
|||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class Translations extends Command
|
class TranslateDirectory extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
@@ -25,7 +25,6 @@ class Translations extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
@@ -33,11 +32,21 @@ class Translations extends Command
|
|||||||
$defaultLocales = config('app.fallback_locale');
|
$defaultLocales = config('app.fallback_locale');
|
||||||
$currentLocales = config('app.locale');
|
$currentLocales = config('app.locale');
|
||||||
|
|
||||||
$defaultLocalesDir = $dir . '/' . $defaultLocales;
|
$defaultLocalesDir = base_path($dir . '/' . $defaultLocales);
|
||||||
$currentLocalesDir = $dir . '/' . $currentLocales;
|
$currentLocalesDir = base_path($dir . '/' . $currentLocales);
|
||||||
|
|
||||||
if (!is_dir($defaultLocalesDir)) {
|
if (!is_dir($defaultLocalesDir)) {
|
||||||
// this is the place for checking for submodules
|
// this is the place for checking for submodules
|
||||||
|
|
||||||
|
$modulePath = dirname(dirname($dir));
|
||||||
|
|
||||||
|
// does exist directory with translations?
|
||||||
|
if (is_dir(base_path($modulePath . '/Resources/lang')) || file_exists(base_path($modulePath.DIRECTORY_SEPARATOR.'info.php'))) {
|
||||||
|
$modules = File::directories($modulePath);
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
$this->call('translate:dir', ['dir' => $module . '/Resources/lang']);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,10 +18,10 @@ class Kernel extends ConsoleKernel
|
|||||||
Commands\ChangePassword::class,
|
Commands\ChangePassword::class,
|
||||||
Commands\InstallModule::class,
|
Commands\InstallModule::class,
|
||||||
Commands\InstallAllModules::class,
|
Commands\InstallAllModules::class,
|
||||||
Commands\Translations::class,
|
Commands\TranslateDirectory::class,
|
||||||
Commands\TranslateAll::class,
|
Commands\TranslateAll::class,
|
||||||
Commands\InitDatabaseSchema::class,
|
Commands\InitDatabaseSchema::class,
|
||||||
Commands\SetTheme::class,
|
Commands\SetTemplate::class,
|
||||||
AddLanguage::class
|
AddLanguage::class
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Enumerations;
|
|
||||||
|
|
||||||
use App\Models\Content;
|
|
||||||
|
|
||||||
class ActiveContentStatuses extends BaseEnumeration
|
|
||||||
{
|
|
||||||
protected static function init()
|
|
||||||
{
|
|
||||||
foreach (ContentStatuses::getWithTranslations() as $key => $value) {
|
|
||||||
if ($key == Content::STATUS_DELETED) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
self::push($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,6 @@ class ContentStatuses extends BaseEnumeration
|
|||||||
{
|
{
|
||||||
$roles = [
|
$roles = [
|
||||||
Content::STATUS_DRAFT => 'admin/contents.status_' . Content::STATUS_DRAFT,
|
Content::STATUS_DRAFT => 'admin/contents.status_' . Content::STATUS_DRAFT,
|
||||||
Content::STATUS_DELETED => 'admin/contents.status_' . Content::STATUS_DELETED,
|
|
||||||
Content::STATUS_PROTECTED => 'admin/contents.status_' . Content::STATUS_PROTECTED,
|
Content::STATUS_PROTECTED => 'admin/contents.status_' . Content::STATUS_PROTECTED,
|
||||||
Content::STATUS_PUBLIC => 'admin/contents.status_' . Content::STATUS_PUBLIC
|
Content::STATUS_PUBLIC => 'admin/contents.status_' . Content::STATUS_PUBLIC
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class UserStates extends BaseEnumeration
|
|||||||
public static function init()
|
public static function init()
|
||||||
{
|
{
|
||||||
$items = [
|
$items = [
|
||||||
User::STATE_DELETED => 'admin/userManagement.status_' . User::STATE_DELETED,
|
|
||||||
User::STATE_BLOCKED => 'admin/userManagement.status_' . User::STATE_BLOCKED,
|
User::STATE_BLOCKED => 'admin/userManagement.status_' . User::STATE_BLOCKED,
|
||||||
User::STATE_ACTIVE => 'admin/userManagement.status_' . User::STATE_ACTIVE
|
User::STATE_ACTIVE => 'admin/userManagement.status_' . User::STATE_ACTIVE
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ class DeleteContent extends Event
|
|||||||
* @var Content
|
* @var Content
|
||||||
*/
|
*/
|
||||||
public $page;
|
public $page;
|
||||||
public $revision;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
@@ -20,9 +19,8 @@ class DeleteContent extends Event
|
|||||||
* @param Content $page
|
* @param Content $page
|
||||||
* @param $revision
|
* @param $revision
|
||||||
*/
|
*/
|
||||||
public function __construct(Content $page, $revision)
|
public function __construct(Content $page)
|
||||||
{
|
{
|
||||||
$this->page = $page;
|
$this->page = $page;
|
||||||
$this->revision = $revision;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ use App\Models\User;
|
|||||||
|
|
||||||
interface BaseModuleHandler
|
interface BaseModuleHandler
|
||||||
{
|
{
|
||||||
public static function getModuleId();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register admin menu (or multiple ones)
|
* Register admin menu (or multiple ones)
|
||||||
*
|
*
|
||||||
@@ -18,9 +16,10 @@ interface BaseModuleHandler
|
|||||||
public static function registerAdminMenu(User $user);
|
public static function registerAdminMenu(User $user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install module
|
* Install module.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* This method is called after inserting info about module into database. It can be called only using Artisan in
|
||||||
|
* CLI.
|
||||||
*/
|
*/
|
||||||
public static function install();
|
public static function install();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Handlers\Contracts;
|
||||||
|
|
||||||
|
use App\Models\Content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface ContentTitles
|
||||||
|
*
|
||||||
|
* Classes which implement this interface get the ability to rewrite default text on edit/create/overview of content
|
||||||
|
* page.
|
||||||
|
*
|
||||||
|
* @package App\Handlers\Contracts
|
||||||
|
*/
|
||||||
|
interface 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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title displayed above for for creating new content page
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getCreateNewTitle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title for form displayed for editin content page
|
||||||
|
*
|
||||||
|
* @param Content $content
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function getEditTitle(Content $content);
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Handlers\Contracts;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use App\Models\Content;
|
||||||
|
use App\Models\Module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface TemplateHandler
|
||||||
|
*
|
||||||
|
* Inerface used for registering template into CMS core.
|
||||||
|
*
|
||||||
|
* @package App\Handlers\Contracts
|
||||||
|
*/
|
||||||
|
interface TemplateHandler extends BaseModuleHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Uninstall template
|
||||||
|
*
|
||||||
|
* Delete some items in database, delete files etc.
|
||||||
|
*
|
||||||
|
* @param Module $template
|
||||||
|
*/
|
||||||
|
public static function uninstall(Module $template);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of registered templates and supported modules.
|
||||||
|
*
|
||||||
|
* Returned array is expected to be array of arrays with following items: module, namespace and templateName.
|
||||||
|
* Example:
|
||||||
|
* return [
|
||||||
|
* ['module' => 'Article', 'templateName' => 'article::template.name']
|
||||||
|
* ];
|
||||||
|
*
|
||||||
|
* When no "namespace" is specified, value strtolower(module) is used instaed.
|
||||||
|
*
|
||||||
|
* @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 $request
|
||||||
|
*/
|
||||||
|
public static function beforeSave(Content & $content, Request $request);
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
namespace App\Handlers;
|
namespace App\Handlers;
|
||||||
|
|
||||||
use App\Handlers\Contracts\AppHandler;
|
use App\Handlers\Contracts\AppHandler;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,6 +30,19 @@ abstract class Handler extends BaseHandler implements AppHandler
|
|||||||
return History::class;
|
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()
|
public static function getExtendedFormSections()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -187,7 +187,6 @@ class TemplateRegistrator
|
|||||||
$registeredTemplates = Templates::getWithTranslations();
|
$registeredTemplates = Templates::getWithTranslations();
|
||||||
|
|
||||||
if (!in_array($templateName, $registeredTemplates)) {
|
if (!in_array($templateName, $registeredTemplates)) {
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'template_name' => $templateName,
|
'template_name' => $templateName,
|
||||||
'name' => $templateName,
|
'name' => $templateName,
|
||||||
@@ -197,8 +196,6 @@ class TemplateRegistrator
|
|||||||
'editable' => 1
|
'editable' => 1
|
||||||
];
|
];
|
||||||
|
|
||||||
echo 'ukladam do db '.$templateName."\n";
|
|
||||||
|
|
||||||
// save template into database
|
// save template into database
|
||||||
$newTemplate = Template::create($params);
|
$newTemplate = Template::create($params);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Models\Module;
|
||||||
|
|
||||||
|
class CurrentTemplate
|
||||||
|
{
|
||||||
|
protected static $template;
|
||||||
|
protected static $initialized = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for currently set template
|
||||||
|
*
|
||||||
|
* @return Module
|
||||||
|
*/
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
if (!self::$initialized) {
|
||||||
|
self::$template = Module::where('is_template', true)
|
||||||
|
->where('enabled', true)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$template;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for getting template handler
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \ErrorException
|
||||||
|
*/
|
||||||
|
public static function handler()
|
||||||
|
{
|
||||||
|
$template = self::get();
|
||||||
|
|
||||||
|
if (!$template) {
|
||||||
|
throw new \ErrorException('No template selected, no handler available!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $template->handler;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Handlers\Contracts\AppHandler;
|
||||||
|
use App\Models\Content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PageRenderer
|
||||||
|
*
|
||||||
|
* Simple class for rendering page for visitor
|
||||||
|
*
|
||||||
|
* @package App\Helpers
|
||||||
|
*/
|
||||||
|
class PageRenderer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Render page
|
||||||
|
*
|
||||||
|
* @param Content $page
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function render(Content $page)
|
||||||
|
{
|
||||||
|
// decode module settings
|
||||||
|
$page->module_settings = json_decode($page->module_settings);
|
||||||
|
|
||||||
|
// do something template-specific
|
||||||
|
$parameters = call_user_func_array([CurrentTemplate::handler(), 'beforeRender'], [&$page]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $handler AppHandler
|
||||||
|
*/
|
||||||
|
// get handler
|
||||||
|
$handler = new $page->module_handler;
|
||||||
|
// render page
|
||||||
|
return $handler->render($page, $parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\Settings as SettingsModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Settings
|
||||||
|
*
|
||||||
|
* Helper class for easier obtaining system settings
|
||||||
|
*
|
||||||
|
* @package App\Helpers
|
||||||
|
*/
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array List of all used settings
|
||||||
|
*/
|
||||||
|
protected static $settings;
|
||||||
|
/**
|
||||||
|
* @var bool Are data already initialized?
|
||||||
|
*/
|
||||||
|
protected static $initialized = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for settings determined with key.
|
||||||
|
*
|
||||||
|
* @param string $key settings key
|
||||||
|
* @param string|null $default default value, which will be returned when given key does not exist
|
||||||
|
*
|
||||||
|
* @param null $exists
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
public static function get($key, $default = null, & $exists = null)
|
||||||
|
{
|
||||||
|
self::init();
|
||||||
|
|
||||||
|
if (isset(self::$settings->$key)) {
|
||||||
|
$exists = true;
|
||||||
|
return self::$settings->$key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$exists = false;
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all settings
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function all()
|
||||||
|
{
|
||||||
|
self::init();
|
||||||
|
|
||||||
|
return self::$settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize settings array
|
||||||
|
*/
|
||||||
|
private static function init()
|
||||||
|
{
|
||||||
|
if (!self::$initialized) {
|
||||||
|
$model = new SettingsModel();
|
||||||
|
self::$settings = $model->getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ class Template
|
|||||||
*
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public static function name($template)
|
public static function name($template, $throwExceptions = true)
|
||||||
{
|
{
|
||||||
$namespace = null;
|
$namespace = null;
|
||||||
if (strpos($template, '::')) {
|
if (strpos($template, '::')) {
|
||||||
@@ -21,10 +21,8 @@ class Template
|
|||||||
$namespace .= '::';
|
$namespace .= '::';
|
||||||
}
|
}
|
||||||
|
|
||||||
$theme = config('app.theme');
|
|
||||||
|
|
||||||
// list of prefixes
|
// list of prefixes
|
||||||
$prefixes = [$theme . '.custom.', $theme . '.', ''];
|
$prefixes = ['custom.', ''];
|
||||||
|
|
||||||
$view = null;
|
$view = null;
|
||||||
foreach ($prefixes as $prefix) {
|
foreach ($prefixes as $prefix) {
|
||||||
@@ -35,7 +33,11 @@ class Template
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($view)) {
|
if (is_null($view)) {
|
||||||
|
if ($throwExceptions) {
|
||||||
throw new InvalidArgumentException('Cannot find template for ' . $namespace . $template);
|
throw new InvalidArgumentException('Cannot find template for ' . $namespace . $template);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
@@ -59,6 +61,13 @@ class Template
|
|||||||
return config('app.upload_url') . '/' . $filename;
|
return config('app.upload_url') . '/' . $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get path to given asset
|
||||||
|
*
|
||||||
|
* @param $path
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public static function asset($path)
|
public static function asset($path)
|
||||||
{
|
{
|
||||||
if (env('APP_DEBUG')) {
|
if (env('APP_DEBUG')) {
|
||||||
@@ -75,6 +84,14 @@ class Template
|
|||||||
return config('app.url') . '/assets/' . config('app.theme') . '/' . $path;
|
return config('app.url') . '/assets/' . config('app.theme') . '/' . $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print date in configured format
|
||||||
|
*
|
||||||
|
* @param $datestamp
|
||||||
|
* @param bool $withTime
|
||||||
|
*
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
public static function date($datestamp, $withTime = true)
|
public static function date($datestamp, $withTime = true)
|
||||||
{
|
{
|
||||||
$timestamp = strtotime($datestamp);
|
$timestamp = strtotime($datestamp);
|
||||||
|
|||||||
@@ -12,3 +12,15 @@ function e($value)
|
|||||||
{
|
{
|
||||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for \App\Helpers\Settings::get()
|
||||||
|
*
|
||||||
|
* @param $key
|
||||||
|
* @param null $default
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
function setting($key, $default = null) {
|
||||||
|
return \App\Helpers\Settings::get($key, $default);
|
||||||
|
}
|
||||||
+4
-4
@@ -1,12 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\ActionLog;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Models\ActionLog;
|
use App\Models\ActionLog;
|
||||||
|
|
||||||
class ActionLogOverview extends Controller
|
class Overview extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var ActionLog
|
* @var ActionLog
|
||||||
@@ -20,6 +19,7 @@ class ActionLogOverview extends Controller
|
|||||||
*/
|
*/
|
||||||
public function __construct(ActionLog $log)
|
public function __construct(ActionLog $log)
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
}
|
}
|
||||||
|
|
||||||
+8
-1
@@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Contents;
|
||||||
|
|
||||||
use App\Enumerations\ContentStatuses;
|
use App\Enumerations\ContentStatuses;
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
use Illuminate\Support\Facades\Input;
|
use Illuminate\Support\Facades\Input;
|
||||||
@@ -32,11 +33,16 @@ class ContentOverview extends Controller
|
|||||||
{
|
{
|
||||||
$moduleFilterHandler = false;
|
$moduleFilterHandler = false;
|
||||||
$perPage = Input::get('perPage') ? Input::get('perPage') : 20;
|
$perPage = Input::get('perPage') ? Input::get('perPage') : 20;
|
||||||
|
$pageHeading = 'admin/contents.overview';
|
||||||
|
|
||||||
// does user want to filter results using module?
|
// does user want to filter results using module?
|
||||||
if (is_numeric($moduleId)) {
|
if (is_numeric($moduleId)) {
|
||||||
$module = Module::findOrFail($moduleId);
|
$module = Module::findOrFail($moduleId);
|
||||||
$moduleFilterHandler = $module->handler;
|
$moduleFilterHandler = $module->handler;
|
||||||
|
|
||||||
|
if (is_callable([$module->handler, 'getOverviewTitle'])) {
|
||||||
|
$pageHeading = call_user_func([$module->handler, 'getOverviewTitle']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get pages for overview
|
// get pages for overview
|
||||||
@@ -49,6 +55,7 @@ class ContentOverview extends Controller
|
|||||||
return view('admin.content.overview', [
|
return view('admin.content.overview', [
|
||||||
'pages' => $pages,
|
'pages' => $pages,
|
||||||
'homepage' => $homepage,
|
'homepage' => $homepage,
|
||||||
|
'pageHeading' => $pageHeading,
|
||||||
'statuses' => ContentStatuses::getWithTranslations(),
|
'statuses' => ContentStatuses::getWithTranslations(),
|
||||||
'module' => isset($module) ? $module : null
|
'module' => isset($module) ? $module : null
|
||||||
]);
|
]);
|
||||||
+42
-7
@@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Contents;
|
||||||
|
|
||||||
use App\Enumerations\ActiveContentStatuses;
|
use App\Enumerations\ContentStatuses;
|
||||||
use App\Events\CreateNewContent as CreateNewContentEvent;
|
use App\Events\CreateNewContent as CreateNewContentEvent;
|
||||||
|
use App\Helpers\CurrentTemplate;
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\CreateNewContentRequest;
|
use App\Http\Requests\CreateNewContentRequest;
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\File;
|
use App\Models\File;
|
||||||
@@ -14,6 +16,14 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|||||||
use Modules\Categories\Entities\Category;
|
use Modules\Categories\Entities\Category;
|
||||||
use Pingpong\Modules\Facades\Module as ModuleInstance;
|
use Pingpong\Modules\Facades\Module as ModuleInstance;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CreateNewContent
|
||||||
|
*
|
||||||
|
* Controller for creating new content page.
|
||||||
|
*
|
||||||
|
* @package App\Http\Controllers\Admin\Contents
|
||||||
|
*/
|
||||||
class CreateNewContent extends Controller
|
class CreateNewContent extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -25,6 +35,14 @@ class CreateNewContent extends Controller
|
|||||||
*/
|
*/
|
||||||
private $content;
|
private $content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreateNewContent constructor.
|
||||||
|
*
|
||||||
|
* Sets File and Content models into class variables
|
||||||
|
*
|
||||||
|
* @param File $file
|
||||||
|
* @param Content $content
|
||||||
|
*/
|
||||||
public function __construct(File $file, Content $content)
|
public function __construct(File $file, Content $content)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@@ -42,14 +60,21 @@ class CreateNewContent extends Controller
|
|||||||
public function getNew($moduleId)
|
public function getNew($moduleId)
|
||||||
{
|
{
|
||||||
$module = Module::findOrFail($moduleId);
|
$module = Module::findOrFail($moduleId);
|
||||||
$statuses = ActiveContentStatuses::getWithTranslations();
|
$statuses = ContentStatuses::getWithTranslations();
|
||||||
|
|
||||||
|
// set default page title
|
||||||
|
$pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]);
|
||||||
|
if (is_callable([$module->handler, 'getCreateNewTitle'])) {
|
||||||
|
$pageHeading = call_user_func([$module->handler, 'getCreateNewTitle']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get list of usable templates
|
||||||
$templates = Template::where('module_id', $moduleId)
|
$templates = Template::where('module_id', $moduleId)
|
||||||
->select(['template_name', 'name', 'description'])
|
->select(['template_name', 'name', 'description'])
|
||||||
->get();
|
->get();
|
||||||
$categoryModule = ModuleInstance::get('categories');
|
|
||||||
|
|
||||||
// add categories, if supported
|
// add categories, if supported
|
||||||
|
$categoryModule = ModuleInstance::get('categories');
|
||||||
$categories = [];
|
$categories = [];
|
||||||
if ($module->support_categories && $categoryModule->enabled()) {
|
if ($module->support_categories && $categoryModule->enabled()) {
|
||||||
$categories = Category::where('module_id', $moduleId)
|
$categories = Category::where('module_id', $moduleId)
|
||||||
@@ -61,6 +86,7 @@ class CreateNewContent extends Controller
|
|||||||
|
|
||||||
// render view
|
// render view
|
||||||
return view('admin.content.new', [
|
return view('admin.content.new', [
|
||||||
|
'pageHeading' => $pageHeading,
|
||||||
'contentStatuses' => $statuses,
|
'contentStatuses' => $statuses,
|
||||||
'templates' => $templates,
|
'templates' => $templates,
|
||||||
'moduleId' => $moduleId,
|
'moduleId' => $moduleId,
|
||||||
@@ -86,7 +112,6 @@ class CreateNewContent extends Controller
|
|||||||
*/
|
*/
|
||||||
public function postNew(CreateNewContentRequest $request, $moduleId)
|
public function postNew(CreateNewContentRequest $request, $moduleId)
|
||||||
{
|
{
|
||||||
$page = new Content();
|
|
||||||
try {
|
try {
|
||||||
$module = Module::findOrFail($moduleId);
|
$module = Module::findOrFail($moduleId);
|
||||||
} catch (NotFoundHttpException $e) {
|
} catch (NotFoundHttpException $e) {
|
||||||
@@ -96,6 +121,10 @@ class CreateNewContent extends Controller
|
|||||||
->with('error', trans('admin/contents.invalidModule'));
|
->with('error', trans('admin/contents.invalidModule'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create new page
|
||||||
|
$page = new Content();
|
||||||
|
$page->template = $request->template;
|
||||||
|
|
||||||
// setup basic info
|
// setup basic info
|
||||||
$page->user_id = \Auth::user()->id;
|
$page->user_id = \Auth::user()->id;
|
||||||
$page->language = LaravelLocalization::getCurrentLocale();
|
$page->language = LaravelLocalization::getCurrentLocale();
|
||||||
@@ -107,20 +136,26 @@ class CreateNewContent extends Controller
|
|||||||
$page->meta_description = $request->metaDescription;
|
$page->meta_description = $request->metaDescription;
|
||||||
$page->content = $request->pageContent;
|
$page->content = $request->pageContent;
|
||||||
$page->status = $request->status;
|
$page->status = $request->status;
|
||||||
$page->template = $request->template;
|
|
||||||
$page->module_handler = $module->handler;
|
$page->module_handler = $module->handler;
|
||||||
$page->category_id = (int)$request->category > 0 ? $request->category : null;
|
$page->category_id = (int)$request->category > 0 ? $request->category : null;
|
||||||
|
|
||||||
|
// is any parent page specified?
|
||||||
if ($request->parentPage) {
|
if ($request->parentPage) {
|
||||||
$page->parent_id = $request->parentPage;
|
$page->parent_id = $request->parentPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload file - if provided
|
// upload file - if provided
|
||||||
$page->uploadTitlePhoto($request);
|
$file = $page->uploadTitlePhoto($request);
|
||||||
|
|
||||||
|
$page->title_photo = $file ? $file['filename'] : null;
|
||||||
|
|
||||||
|
// let template to modify request and content page
|
||||||
|
call_user_func_array([CurrentTemplate::handler(), 'beforeSave'], [&$page, $request]);
|
||||||
|
|
||||||
// save module-specific stuff
|
// save module-specific stuff
|
||||||
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
|
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
|
||||||
|
|
||||||
|
// save content of page before (possible) uploading related files
|
||||||
$page->save();
|
$page->save();
|
||||||
|
|
||||||
// upload files assigned to content page
|
// upload files assigned to content page
|
||||||
+41
-27
@@ -1,14 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Contents;
|
||||||
|
|
||||||
use App\Enumerations\ContentStatuses;
|
use App\Enumerations\ContentStatuses;
|
||||||
use App\Enumerations\ModulesHandlerToId;
|
|
||||||
use App\Events\AttemptToEditInvalidContent;
|
use App\Events\AttemptToEditInvalidContent;
|
||||||
use App\Events\DeleteContent;
|
use App\Events\DeleteContent;
|
||||||
use App\Events\EditContent as EditContentEvent;
|
use App\Events\EditContent as EditContentEvent;
|
||||||
use App\Events\MakeDraftFromContent;
|
use App\Events\MakeDraftFromContent;
|
||||||
use App\Events\PublishContent;
|
use App\Events\PublishContent;
|
||||||
use App\Events\SetHomepage;
|
use App\Events\SetHomepage;
|
||||||
|
use App\Helpers\CurrentTemplate;
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\EditContentRequest;
|
use App\Http\Requests\EditContentRequest;
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
@@ -34,6 +35,14 @@ class EditContent extends Controller
|
|||||||
*/
|
*/
|
||||||
private $file;
|
private $file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EditContent constructor.
|
||||||
|
*
|
||||||
|
* Load ContentHistory and File into this controller
|
||||||
|
*
|
||||||
|
* @param ContentHistory $history
|
||||||
|
* @param File $file
|
||||||
|
*/
|
||||||
public function __construct(ContentHistory $history, File $file)
|
public function __construct(ContentHistory $history, File $file)
|
||||||
{
|
{
|
||||||
$this->history = $history;
|
$this->history = $history;
|
||||||
@@ -56,27 +65,38 @@ class EditContent extends Controller
|
|||||||
$page = Content::findOrFail($id);
|
$page = Content::findOrFail($id);
|
||||||
$page->module_settings = json_decode($page->module_settings);
|
$page->module_settings = json_decode($page->module_settings);
|
||||||
|
|
||||||
$allModules = ModulesHandlerToId::getWithTranslations();
|
// get module ID
|
||||||
$moduleId = $allModules[$page->module_handler];
|
$module = Module::where('handler', $page->module_handler)
|
||||||
$module = Module::findOrFail($moduleId);
|
->firstOrFail();
|
||||||
|
|
||||||
$templates = Template::where('module_id', $moduleId)
|
$pageHeading = trans('admin/contents.edit', ['name' => e($page->title)]);
|
||||||
|
if (is_callable([$module->handler, 'getCreateNewTitle'])) {
|
||||||
|
$pageHeading = call_user_func([$module->handler, 'getEditTitle'], $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get all Blade templates for rendering page
|
||||||
|
$templates = Template::where('module_id', $module->id)
|
||||||
->select(['template_name', 'name', 'description'])
|
->select(['template_name', 'name', 'description'])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
// get module for Categories - PingPong module
|
||||||
$categoryModule = ModuleInstance::get('categories');
|
$categoryModule = ModuleInstance::get('categories');
|
||||||
|
|
||||||
// add categories, if supported
|
// add categories, if supported
|
||||||
$categories = [];
|
$categories = [];
|
||||||
if ($module->support_categories && $categoryModule->enabled()) {
|
if ($module->support_categories && $categoryModule->enabled()) {
|
||||||
$categories = Category::where('module_id', $moduleId)
|
$categories = Category::where('module_id', $module->id)
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// modify data for edit form according to installed template
|
||||||
|
call_user_func_array([CurrentTemplate::handler(), 'beforePopulatingEditForm'], [&$page]);
|
||||||
|
|
||||||
$history = $this->history->getStructuredHistoryOf($page);
|
$history = $this->history->getStructuredHistoryOf($page);
|
||||||
|
|
||||||
// render view
|
// render view
|
||||||
return view('admin.content.edit', [
|
return view('admin.content.edit', [
|
||||||
|
'pageHeading' => $pageHeading,
|
||||||
'contentStatuses' => $statuses,
|
'contentStatuses' => $statuses,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'module' => $module,
|
'module' => $module,
|
||||||
@@ -118,12 +138,16 @@ class EditContent extends Controller
|
|||||||
->with('error', trans('admin/contents.invalidPage'));
|
->with('error', trans('admin/contents.invalidPage'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// upload file - if provided
|
||||||
|
$file = $page->uploadTitlePhoto($request);
|
||||||
|
|
||||||
|
// let template to modify request and content page
|
||||||
|
call_user_func_array([CurrentTemplate::handler(), 'beforeSave'], [&$page, $request]);
|
||||||
|
|
||||||
$request->url = Str::slug($request->url);
|
$request->url = Str::slug($request->url);
|
||||||
$request->parentPage = $request->parentPage ? $request->parentPage : null;
|
$request->parentPage = $request->parentPage ? $request->parentPage : null;
|
||||||
$request->titlePhotoFilename = $page->title_photo;
|
|
||||||
|
|
||||||
// upload file - if provided
|
$request->titlePhotoFilename = $file ? $file['filename'] : null;
|
||||||
$page->uploadTitlePhoto($request);
|
|
||||||
|
|
||||||
// array of fields in database and fields from request
|
// array of fields in database and fields from request
|
||||||
$fields = [
|
$fields = [
|
||||||
@@ -142,7 +166,8 @@ class EditContent extends Controller
|
|||||||
];
|
];
|
||||||
|
|
||||||
// save new values with history
|
// save new values with history
|
||||||
$data = self::getFields($request, $fields);
|
$data = self::getFields($request, array_values($fields));
|
||||||
|
|
||||||
list($revision, $changedColumns) = $page->updateWithHistory($fields, $data);
|
list($revision, $changedColumns) = $page->updateWithHistory($fields, $data);
|
||||||
|
|
||||||
$changedColumns += call_user_func_array([$page->module_handler, 'edit'], [&$page, $request, $revision]);
|
$changedColumns += call_user_func_array([$page->module_handler, 'edit'], [&$page, $request, $revision]);
|
||||||
@@ -178,7 +203,6 @@ class EditContent extends Controller
|
|||||||
{
|
{
|
||||||
// get possible statuses
|
// get possible statuses
|
||||||
$statuses = ContentStatuses::getWithTranslations();
|
$statuses = ContentStatuses::getWithTranslations();
|
||||||
unset($statuses[Content::STATUS_DELETED]);
|
|
||||||
|
|
||||||
// check if given status is valid
|
// check if given status is valid
|
||||||
if (!isset($statuses[$status])) {
|
if (!isset($statuses[$status])) {
|
||||||
@@ -241,23 +265,13 @@ class EditContent extends Controller
|
|||||||
|
|
||||||
// change url to something unique
|
// change url to something unique
|
||||||
$oldURL = $page->url;
|
$oldURL = $page->url;
|
||||||
$page->url = uniqid($page->url . '_deleted');
|
$page->delete();
|
||||||
$page->save();
|
|
||||||
|
|
||||||
list ($revision, $changedColumns) = $page->updateWithHistory(['status' => 'status'], ['status' => Content::STATUS_DELETED]);
|
|
||||||
|
|
||||||
// let module to delete some extra content created during page's life
|
// let module to delete some extra content created during page's life
|
||||||
call_user_func([$page->module_handler, 'delete'], $page);
|
call_user_func([$page->module_handler, 'delete'], $page);
|
||||||
|
|
||||||
// was something changed?
|
|
||||||
if ($changedColumns == 0) {
|
|
||||||
return redirect()
|
|
||||||
->route('content.edit', ['id' => $page->id])
|
|
||||||
->with('error', trans('admin/contents.nothingToEdit'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// trigger delete event
|
// trigger delete event
|
||||||
Event::fire(new DeleteContent($page, $revision));
|
Event::fire(new DeleteContent($page));
|
||||||
|
|
||||||
// redirect back to overview with info for user
|
// redirect back to overview with info for user
|
||||||
return redirect()
|
return redirect()
|
||||||
@@ -286,7 +300,7 @@ class EditContent extends Controller
|
|||||||
} catch (NotFoundHttpException $e) {
|
} catch (NotFoundHttpException $e) {
|
||||||
// page not found
|
// page not found
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('content.overview')
|
->back()
|
||||||
->with('error', trans('admin/contents.invalidPage'));
|
->with('error', trans('admin/contents.invalidPage'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +315,7 @@ class EditContent extends Controller
|
|||||||
// was something changed?
|
// was something changed?
|
||||||
if ($changedColumns == 0) {
|
if ($changedColumns == 0) {
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('content.overview')
|
->back()
|
||||||
->with('error', trans('admin/contents.nothingToEdit'));
|
->with('error', trans('admin/contents.nothingToEdit'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +324,7 @@ class EditContent extends Controller
|
|||||||
|
|
||||||
// redirect back to overview with info for user
|
// redirect back to overview with info for user
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('content.overview')
|
->back()
|
||||||
->with('success', trans('admin/contents.homepageSetup', [
|
->with('success', trans('admin/contents.homepageSetup', [
|
||||||
'name' => $page->title,
|
'name' => $page->title,
|
||||||
'url' => $page->url
|
'url' => $page->url
|
||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Contents;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\ContentHistory;
|
use App\Models\ContentHistory;
|
||||||
|
|
||||||
+2
-1
@@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\CustomFields;
|
||||||
|
|
||||||
use App\Enumerations\CustomFieldResources;
|
use App\Enumerations\CustomFieldResources;
|
||||||
use App\Enumerations\CustomFieldTypes;
|
use App\Enumerations\CustomFieldTypes;
|
||||||
use App\Events\CreateNewCustomField as CreateNewCustomFieldEvent;
|
use App\Events\CreateNewCustomField as CreateNewCustomFieldEvent;
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\NewCustomFieldRequest;
|
use App\Http\Requests\NewCustomFieldRequest;
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
+2
-3
@@ -1,11 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\CustomFields;
|
||||||
|
|
||||||
use App\Enumerations\CustomFieldResources;
|
use App\Enumerations\CustomFieldResources;
|
||||||
use App\Enumerations\CustomFieldTypes;
|
use App\Enumerations\CustomFieldTypes;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
|
|
||||||
class CustomFieldsOverview extends Controller
|
class CustomFieldsOverview extends Controller
|
||||||
+2
-3
@@ -1,13 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\CustomFields;
|
||||||
|
|
||||||
use App\Enumerations\CustomFieldResources;
|
use App\Enumerations\CustomFieldResources;
|
||||||
use App\Enumerations\CustomFieldTypes;
|
use App\Enumerations\CustomFieldTypes;
|
||||||
use App\Events\DeleteCustomField;
|
use App\Events\DeleteCustomField;
|
||||||
use App\Events\EditCustomField as EditCustomFieldEvent;
|
use App\Events\EditCustomField as EditCustomFieldEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Http\Requests\EditCustomFieldRequest;
|
use App\Http\Requests\EditCustomFieldRequest;
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Http\Requests;
|
|
||||||
use Illuminate\Support\Facades\Session;
|
|
||||||
|
|
||||||
class Dashboard extends Controller
|
|
||||||
{
|
|
||||||
public function getIndex(Request $request) {
|
|
||||||
|
|
||||||
return redirect()->route('content.overview');
|
|
||||||
|
|
||||||
// return view('admin.dashboard');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin\Dashboard;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class Dashboard extends Controller
|
||||||
|
{
|
||||||
|
public function getIndex(Request $request)
|
||||||
|
{
|
||||||
|
return redirect()->route('content.overview');
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\FileManager;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Models\Directory;
|
use App\Models\Directory;
|
||||||
|
|
||||||
@@ -30,8 +30,8 @@ class CreateNewDirectory extends Controller
|
|||||||
} else {
|
} else {
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('upload.overview', ['id' => $request->parentDirectory])
|
->route('upload.overview', ['id' => $request->parentDirectory])
|
||||||
->with('error', trans('admin/fileManager.subdirectoryExists'))
|
->withInput()
|
||||||
->withInput();
|
->with('error', trans('admin/fileManager.subdirectoryExists'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+5
-5
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\FileManager;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Models\Directory;
|
use App\Models\Directory;
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ class EditDirectory extends Controller
|
|||||||
* @param Requests\EditDirectoryRequest $request
|
* @param Requests\EditDirectoryRequest $request
|
||||||
* @param $directoryId
|
* @param $directoryId
|
||||||
*
|
*
|
||||||
* @return $this|\Illuminate\Http\JsonResponse
|
* @return $this|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function postEdit(Requests\EditDirectoryRequest $request, $directoryId)
|
public function postEdit(Requests\EditDirectoryRequest $request, $directoryId)
|
||||||
{
|
{
|
||||||
@@ -34,8 +34,8 @@ class EditDirectory extends Controller
|
|||||||
} else {
|
} else {
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('upload.overview', ['id' => $directoryId])
|
->route('upload.overview', ['id' => $directoryId])
|
||||||
->with('error', trans('admin/fileManager.subdirectoryExists'))
|
->withInput()
|
||||||
->withInput();
|
->with('error', trans('admin/fileManager.subdirectoryExists'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\FileManager;
|
||||||
|
|
||||||
use App\Events\EditFile;
|
use App\Events\EditFile;
|
||||||
use App\Helpers\FileManager;
|
use App\Helpers\FileManager;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\EditUploadedFileRequest;
|
use App\Http\Requests\EditUploadedFileRequest;
|
||||||
use App\Models\File;
|
use App\Models\File;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
+13
-31
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\FileManager;
|
||||||
|
|
||||||
use App\Models\File;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
|
use App\Models\File;
|
||||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||||
|
|
||||||
class UploadFile extends Controller
|
class UploadFile extends Controller
|
||||||
@@ -18,11 +19,12 @@ class UploadFile extends Controller
|
|||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads any file
|
* Uploads any file
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function postFile(Request $request)
|
public function postFile(Request $request)
|
||||||
{
|
{
|
||||||
@@ -38,12 +40,6 @@ class UploadFile extends Controller
|
|||||||
$uploadedFiles[] = $uploadedFile;
|
$uploadedFiles[] = $uploadedFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we do not want to redirect
|
|
||||||
if ($request->ajax()) {
|
|
||||||
return $this->jsonResponse($uploadedFiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
// upload was not performed via ajax, redirect user
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('upload.overview', ['directory' => $request->directoryId])
|
->route('upload.overview', ['directory' => $request->directoryId])
|
||||||
->with('success', trans_choice('admin/fileManager.uploadSuccessfull', $successfullUploads));
|
->with('success', trans_choice('admin/fileManager.uploadSuccessfull', $successfullUploads));
|
||||||
@@ -52,31 +48,17 @@ class UploadFile extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message and redirect to upload.overview when upload failed
|
||||||
|
*
|
||||||
|
* @param $message
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
protected function invalidUpload($message)
|
protected function invalidUpload($message)
|
||||||
{
|
{
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('upload.overview')
|
->route('upload.overview')
|
||||||
->with('error', trans('admin/fileManager.' . $message));
|
->with('error', trans('admin/fileManager.' . $message));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send response about uploaded file as JSON
|
|
||||||
*
|
|
||||||
* @param $uploadedFile
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
private function jsonResponse($uploadedFile)
|
|
||||||
{
|
|
||||||
$filename = $uploadedFile['file']->getFilename();
|
|
||||||
$url = config('app.upload_path') . DIRECTORY_SEPARATOR . $filename;
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'filename' => $filename,
|
|
||||||
'url' => $url,
|
|
||||||
'id' => $uploadedFile['id']
|
|
||||||
];
|
|
||||||
|
|
||||||
return response()->json($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+2
-4
@@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace App\Http\Controllers\Admin\FileManager;
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Models\Directory;
|
use App\Models\Directory;
|
||||||
use App\Models\File;
|
use App\Models\File;
|
||||||
use Illuminate\Support\Facades\Input;
|
use Illuminate\Support\Facades\Input;
|
||||||
@@ -17,6 +17,16 @@ use Illuminate\Support\Facades\Hash;
|
|||||||
*/
|
*/
|
||||||
class Login extends Controller
|
class Login extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Display login form
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function getLogin()
|
||||||
|
{
|
||||||
|
return view('admin.loginForm');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login handler
|
* Login handler
|
||||||
*
|
*
|
||||||
@@ -51,6 +61,23 @@ class Login extends Controller
|
|||||||
return $this->loginFailed();
|
return $this->loginFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs out user
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function logout()
|
||||||
|
{
|
||||||
|
|
||||||
|
// remove user information
|
||||||
|
\Auth::logout();
|
||||||
|
|
||||||
|
// redirect to login form with info about successfull logout
|
||||||
|
return redirect()
|
||||||
|
->route('login')
|
||||||
|
->with('success', trans('admin/common.logoutSuccessfull'));
|
||||||
|
}
|
||||||
|
|
||||||
private function loginFailed()
|
private function loginFailed()
|
||||||
{
|
{
|
||||||
return redirect()
|
return redirect()
|
||||||
|
|||||||
+2
-9
@@ -1,12 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Templates;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Http\Requests\CopyTemplateRequest;
|
use App\Http\Requests\CopyTemplateRequest;
|
||||||
use App\Models\Template;
|
use App\Models\Template;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class CopyTemplate extends Controller
|
class CopyTemplate extends Controller
|
||||||
{
|
{
|
||||||
@@ -28,11 +26,6 @@ class CopyTemplate extends Controller
|
|||||||
// get template path
|
// get template path
|
||||||
$template = Template::findOrFail($oldTemplateId);
|
$template = Template::findOrFail($oldTemplateId);
|
||||||
|
|
||||||
// @todo add check for uniqueness of template_name
|
|
||||||
|
|
||||||
// get template path
|
|
||||||
$template = Template::findOrFail($oldTemplateId);
|
|
||||||
|
|
||||||
$namespace = null;
|
$namespace = null;
|
||||||
if (strpos($template->template_name, '::')) {
|
if (strpos($template->template_name, '::')) {
|
||||||
list($namespace) = explode('::', $template->template_name);
|
list($namespace) = explode('::', $template->template_name);
|
||||||
+5
-2
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Templates;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
@@ -20,6 +20,9 @@ class EditTemplate extends Controller
|
|||||||
*/
|
*/
|
||||||
public function getEdit($template)
|
public function getEdit($template)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var $template Template
|
||||||
|
*/
|
||||||
$template = Template::findOrFail($template);
|
$template = Template::findOrFail($template);
|
||||||
$path = $template->getPath();
|
$path = $template->getPath();
|
||||||
|
|
||||||
@@ -89,7 +92,7 @@ class EditTemplate extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save new content only if something was changed
|
// save new content only if something was changed
|
||||||
if ($this->isContentDifferent($originalTemplate, $customTemplate, $request->templateContent)) {
|
if ($template->editable && $this->isContentDifferent($originalTemplate, $customTemplate, $request->templateContent)) {
|
||||||
|
|
||||||
// create directory for custom updates
|
// create directory for custom updates
|
||||||
if (!is_dir($customDir)) {
|
if (!is_dir($customDir)) {
|
||||||
+2
-4
@@ -1,11 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Templates;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Models\TemplatePath;
|
use App\Models\TemplatePath;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class TemplateOverview extends Controller
|
class TemplateOverview extends Controller
|
||||||
{
|
{
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Http\Requests\CreateNewUserRequest;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
|
|
||||||
class UserProfile extends Controller {
|
|
||||||
|
|
||||||
}
|
|
||||||
+2
-3
@@ -1,11 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Users;
|
||||||
|
|
||||||
use App\Enumerations\UserRoles;
|
use App\Enumerations\UserRoles;
|
||||||
use App\Events\CreateNewUser as CreateNewUserEvent;
|
use App\Events\CreateNewUser as CreateNewUserEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Http\Requests\CreateNewUserRequest;
|
use App\Http\Requests\CreateNewUserRequest;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
+3
-7
@@ -1,12 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Users;
|
||||||
|
|
||||||
use App\Enumerations\UserRoles;
|
use App\Enumerations\UserRoles;
|
||||||
use App\Enumerations\UserStates;
|
use App\Enumerations\UserStates;
|
||||||
use App\Events\EditUser as EditUserEvent;
|
use App\Events\EditUser as EditUserEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Http\Requests\EditUserRequest;
|
use App\Http\Requests\EditUserRequest;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@@ -22,11 +21,8 @@ class EditUser extends Controller
|
|||||||
$id = Auth::user()->id;
|
$id = Auth::user()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo add some authorization (e.g. via can/cannot methods)
|
|
||||||
|
|
||||||
// try to find given user
|
// try to find given user
|
||||||
$user = User::where('status', '!=', User::STATE_DELETED)
|
$user = User::findOrFail($id);
|
||||||
->findOrFail($id);
|
|
||||||
|
|
||||||
$states = UserStates::getWithTranslations();
|
$states = UserStates::getWithTranslations();
|
||||||
$roles = UserRoles::getWithTranslations();
|
$roles = UserRoles::getWithTranslations();
|
||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Users;
|
||||||
|
|
||||||
use App\Enumerations\UserRoles;
|
use App\Enumerations\UserRoles;
|
||||||
use App\Enumerations\UserStates;
|
use App\Enumerations\UserStates;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Models\ActionLog;
|
use App\Models\ActionLog;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
+3
-6
@@ -1,24 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Users;
|
||||||
|
|
||||||
use App\Enumerations\UserRoles;
|
use App\Enumerations\UserRoles;
|
||||||
use App\Enumerations\UserStates;
|
use App\Enumerations\UserStates;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
|
||||||
class UsersOverview extends Controller
|
class UsersOverview extends Controller
|
||||||
{
|
{
|
||||||
public function getOverview($status = null, $perPage = 12)
|
public function getOverview($status = null, $perPage = 12)
|
||||||
{
|
{
|
||||||
$users = User::where('status', '<>', User::STATE_DELETED)
|
$users = User::orderBy('id', 'desc');
|
||||||
->orderBy('id', 'desc');
|
|
||||||
|
|
||||||
// get statuses
|
// get statuses
|
||||||
$statuses = UserStates::getWithTranslations();
|
$statuses = UserStates::getWithTranslations();
|
||||||
$statuses[''] = trans('admin/userManagement.allStatuses');
|
$statuses[''] = trans('admin/userManagement.allStatuses');
|
||||||
unset($statuses[User::STATE_DELETED]);
|
|
||||||
|
|
||||||
// filter using status
|
// filter using status
|
||||||
if (!is_null($status) && isset($statuses[$status])) {
|
if (!is_null($status) && isset($statuses[$status])) {
|
||||||
+3
-4
@@ -1,9 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Widgets\Areas;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Http\Requests\NewWidgetAreaRequest;
|
use App\Http\Requests\NewWidgetAreaRequest;
|
||||||
use App\Models\WidgetArea;
|
use App\Models\WidgetArea;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
@@ -17,7 +16,7 @@ class CreateNewWidgetArea extends Controller
|
|||||||
*/
|
*/
|
||||||
public function getNew()
|
public function getNew()
|
||||||
{
|
{
|
||||||
return view('admin.widgets.area.new');
|
return view('admin.widgets.area.new', ['area' => new WidgetArea()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+16
-3
@@ -1,9 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Widgets\Areas;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Http\Requests\EditWidgetAreaRequest;
|
use App\Http\Requests\EditWidgetAreaRequest;
|
||||||
use App\Models\WidgetArea;
|
use App\Models\WidgetArea;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
@@ -11,6 +10,13 @@ use Illuminate\Support\Facades\Event;
|
|||||||
|
|
||||||
class EditWidgetArea extends Controller
|
class EditWidgetArea extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Display form for editing given widget area
|
||||||
|
*
|
||||||
|
* @param $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
public function getEdit($id)
|
public function getEdit($id)
|
||||||
{
|
{
|
||||||
$area = WidgetArea::findOrFail($id);
|
$area = WidgetArea::findOrFail($id);
|
||||||
@@ -61,6 +67,13 @@ class EditWidgetArea extends Controller
|
|||||||
return $this->invalidArea();
|
return $this->invalidArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if widget area is deletable
|
||||||
|
if (!$area->deletable) {
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('error', trans('admin/widgetAreas.notDeletableArea'));
|
||||||
|
}
|
||||||
|
|
||||||
// delete area
|
// delete area
|
||||||
$area->delete();
|
$area->delete();
|
||||||
|
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Widgets\Areas;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Models\WidgetArea;
|
use App\Models\WidgetArea;
|
||||||
|
|
||||||
+2
-3
@@ -1,11 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Widgets;
|
||||||
|
|
||||||
use App\Events\AssignWidget;
|
use App\Events\AssignWidget;
|
||||||
use App\Events\RemoveWidgetFromArea;
|
use App\Events\RemoveWidgetFromArea;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Models\Widget;
|
use App\Models\Widget;
|
||||||
use App\Models\WidgetArea;
|
use App\Models\WidgetArea;
|
||||||
use App\Models\WidgetInWidgetArea;
|
use App\Models\WidgetInWidgetArea;
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Widgets;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\NewWidgetRequest;
|
use App\Http\Requests\NewWidgetRequest;
|
||||||
use App\Models\Widget;
|
use App\Models\Widget;
|
||||||
use App\Models\WidgetType;
|
use App\Models\WidgetType;
|
||||||
+9
-1
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Widgets;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\EditWidgetRequest;
|
use App\Http\Requests\EditWidgetRequest;
|
||||||
use App\Models\Widget;
|
use App\Models\Widget;
|
||||||
use App\Widgets\Exceptions\MissingParameterException;
|
use App\Widgets\Exceptions\MissingParameterException;
|
||||||
@@ -79,6 +80,13 @@ class EditWidget extends Controller
|
|||||||
// create new widget
|
// create new widget
|
||||||
$widget = Widget::findOrFail($id);
|
$widget = Widget::findOrFail($id);
|
||||||
|
|
||||||
|
// check if widget area is deletable
|
||||||
|
if (!$widget->deletable) {
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('error', trans('admin/widgets.notDeletable'));
|
||||||
|
}
|
||||||
|
|
||||||
$widget->delete();
|
$widget->delete();
|
||||||
|
|
||||||
// redirect with success notification
|
// redirect with success notification
|
||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin\Widgets;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Models\Widget;
|
use App\Models\Widget;
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Visitor;
|
namespace App\Http\Controllers\Visitor;
|
||||||
|
|
||||||
|
use App\Helpers\PageRenderer;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
@@ -50,10 +50,9 @@ class ContentPage extends Controller
|
|||||||
throw new \Exception('Cannot access protected resources');
|
throw new \Exception('Cannot access protected resources');
|
||||||
}
|
}
|
||||||
|
|
||||||
// get handler
|
// add one new "view" for page
|
||||||
$handler = new $page->module_handler;
|
$page->view();
|
||||||
|
|
||||||
// render page
|
return PageRenderer::render($page);
|
||||||
return $handler->render($page, '');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ class Homepage extends ContentPage
|
|||||||
}
|
}
|
||||||
|
|
||||||
// render page
|
// render page
|
||||||
try {
|
// try {
|
||||||
return $this->renderPage($page);
|
return $this->renderPage($page);
|
||||||
} catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
return view('errors.homepageNotAvailable', ['exception' => $e, 'reason' => 'exception']);
|
// return view('errors.homepageNotAvailable', ['exception' => $e, 'reason' => 'exception']);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class EditTemplateRequest extends Request
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => 'required|max:128',
|
'name' => 'required|max:128',
|
||||||
'templateContent' => 'required'
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-221
@@ -24,235 +24,26 @@ Route::group([
|
|||||||
'prefix' => 'admin'
|
'prefix' => 'admin'
|
||||||
], function () {
|
], function () {
|
||||||
|
|
||||||
// these routes are available only for user with role admin
|
// include all routes in routes/admin subfolder
|
||||||
Route::group(['middleware' => 'onlyAdmin'], function () {
|
$files = ['contents', 'fileManager', 'settings', 'templates', 'users', 'widgets'];
|
||||||
// display form for creating new user
|
foreach ($files as $file) {
|
||||||
Route::get('users/new', 'CreateNewUser@getNewUser')
|
require_once __DIR__ . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $file . '.php';
|
||||||
->name('users.new');
|
}
|
||||||
|
|
||||||
// POST methods
|
|
||||||
// display form for creating new user
|
|
||||||
Route::post('users/new', 'CreateNewUser@postRegistration')
|
|
||||||
->name('users.newPost');
|
|
||||||
|
|
||||||
// display form for edit of existing user
|
|
||||||
Route::get('users/edit/{id}', 'EditUser@getEditUser')
|
|
||||||
->name('users.edit');
|
|
||||||
|
|
||||||
// form for adding new custom field
|
|
||||||
Route::get('customfields/new', 'CreateNewCustomField@getNew')
|
|
||||||
->name('customfields.new');
|
|
||||||
|
|
||||||
// form for editing custom field
|
|
||||||
Route::get('customfields/edit/{id}', 'EditCustomField@getEditCustomField')
|
|
||||||
->name('customfields.edit');
|
|
||||||
|
|
||||||
// form for adding new custom field
|
|
||||||
Route::post('customfields/new', 'CreateNewCustomField@postNew')
|
|
||||||
->name('customfields.newPost');
|
|
||||||
|
|
||||||
// form for editing custom field
|
|
||||||
Route::post('customfields/edit/{id}', 'EditCustomField@postEditCustomField')
|
|
||||||
->name('customfields.editPost');
|
|
||||||
|
|
||||||
Route::get('customfields/delete/{id}', 'EditCustomField@deleteCustomField')
|
|
||||||
->name('customfields.delete');
|
|
||||||
|
|
||||||
Route::get('templates/overview/path/{id}', 'TemplateOverview@getPath')
|
|
||||||
->name('templates.overview');
|
|
||||||
|
|
||||||
Route::post('templates/copy', 'CopyTemplate@createCopy')
|
|
||||||
->name('templates.postCopy');
|
|
||||||
|
|
||||||
// Route::get('templates/new/{pathId}', 'TemplateOverview@getPath')
|
|
||||||
// ->name('templates.new');
|
|
||||||
|
|
||||||
Route::get('templates/edit/{id}', 'EditTemplate@getEdit')
|
|
||||||
->name('templates.edit');
|
|
||||||
|
|
||||||
Route::post('templates/edit/{id}', 'EditTemplate@postEdit')
|
|
||||||
->name('templates.postEdit');
|
|
||||||
});
|
|
||||||
|
|
||||||
// list of all static pages
|
|
||||||
Route::get('content/overview/{moduleId?}/{status?}', 'ContentOverview@getOverview')
|
|
||||||
->name('content.overview');
|
|
||||||
|
|
||||||
// form for creating new static page
|
|
||||||
Route::get('content/new/{moduleId}', 'CreateNewContent@getNew')
|
|
||||||
->name('content.new');
|
|
||||||
|
|
||||||
// form for editing existing static page
|
|
||||||
Route::get('content/edit/{id}', 'EditContent@getEdit')
|
|
||||||
->name('content.edit');
|
|
||||||
|
|
||||||
// post method for creating new static page
|
|
||||||
Route::post('content/new/{moduleId}', 'CreateNewContent@postNew')
|
|
||||||
->name('content.newPost');
|
|
||||||
|
|
||||||
// post method for creating new static page
|
|
||||||
Route::post('content/edit/{id}', 'EditContent@postEdit')
|
|
||||||
->name('content.editPost');
|
|
||||||
|
|
||||||
// routes for quick actions
|
|
||||||
|
|
||||||
// change status of page (protected, public or draft)
|
|
||||||
Route::get('content/status/{id}/{status}', 'EditContent@changeStatus')
|
|
||||||
->name('content.changeStatus');
|
|
||||||
|
|
||||||
// set homepage
|
|
||||||
Route::get('content/homepage/{id}', 'EditContent@setHomepage')
|
|
||||||
->name('content.setHomepage');
|
|
||||||
|
|
||||||
// delete page
|
|
||||||
Route::get('content/delete/{id}', 'EditContent@deletePage')
|
|
||||||
->name('content.delete');
|
|
||||||
|
|
||||||
// these routes are available for all logged (authenticated) users
|
|
||||||
|
|
||||||
// display dashboard with some usefull information
|
// display dashboard with some usefull information
|
||||||
Route::get('/', 'Dashboard@getIndex')
|
Route::get('/', 'Dashboard\Dashboard@getIndex')
|
||||||
->name('admin.dashboard');
|
->name('admin.dashboard');
|
||||||
|
|
||||||
// display user detail in admin
|
|
||||||
Route::get('users/detail/{id?}', 'UserDetail@getDetail')
|
|
||||||
->name('users.detail');
|
|
||||||
|
|
||||||
// method for saving edited data of user
|
|
||||||
Route::post('users/edit/{id}', 'EditUser@postEdit')
|
|
||||||
->name('users.editPost');
|
|
||||||
|
|
||||||
// display list of all users registered into our system
|
|
||||||
Route::get('users/overview/{state?}/{perPage?}', 'UsersOverview@getOverview')
|
|
||||||
->name('users.overview');
|
|
||||||
|
|
||||||
// history of changes for specified page
|
|
||||||
Route::get('history/{id}', 'History@getOverview')
|
|
||||||
->name('content.history');
|
|
||||||
|
|
||||||
// history of changes for specified page
|
|
||||||
Route::get('history/{revision}/{id}', 'History@getDiff')
|
|
||||||
->name('history.diff');
|
|
||||||
|
|
||||||
// list of all actions
|
// list of all actions
|
||||||
Route::get('actions', 'ActionLogOverview@getOverview')
|
Route::get('actions', 'ActionLog\Overview@getOverview')
|
||||||
->name('log.overview');
|
->name('log.overview');
|
||||||
|
|
||||||
// routes for widget areas
|
// search form with results
|
||||||
Route::get('widgets/areas/overview', 'WidgetAreaOverview@getOverview')
|
|
||||||
->name('widgetareas.overview');
|
|
||||||
|
|
||||||
// form for new widget area
|
|
||||||
Route::get('widgets/areas/new', 'CreateNewWidgetArea@getNew')
|
|
||||||
->name('widgetareas.new');
|
|
||||||
|
|
||||||
// form for new widget area
|
|
||||||
Route::post('widgets/areas/new', 'CreateNewWidgetArea@postNew')
|
|
||||||
->name('widgetareas.postNew');
|
|
||||||
|
|
||||||
// edit form for widget area
|
|
||||||
Route::get('widgets/areas/edit/{id}', 'EditWidgetArea@getEdit')
|
|
||||||
->name('widgetareas.edit');
|
|
||||||
|
|
||||||
Route::post('widgets/areas/edit/{id}', 'EditWidgetArea@postEdit')
|
|
||||||
->name('widgetareas.postEdit');
|
|
||||||
|
|
||||||
// edit form for widget area
|
|
||||||
Route::get('widgets/areas/delete/{id}', 'EditWidgetArea@deleteArea')
|
|
||||||
->name('widgetareas.delete');
|
|
||||||
|
|
||||||
// list of all installed widget types
|
|
||||||
Route::get('widgets/overview', 'WidgetsOverview@getOverview')
|
|
||||||
->name('widgets.overview');
|
|
||||||
|
|
||||||
// create new instance of widget of given type
|
|
||||||
Route::get('widgets/new/{type}', 'CreateNewWidget@getNew')
|
|
||||||
->name('widgets.new');
|
|
||||||
|
|
||||||
Route::post('widgets/new/{type}', 'CreateNewWidget@postNew')
|
|
||||||
->name('widgets.postNew');
|
|
||||||
|
|
||||||
// edit widget settings
|
|
||||||
Route::get('widgets/edit/{id}', 'EditWidget@getEdit')
|
|
||||||
->name('widgets.edit');
|
|
||||||
|
|
||||||
// delete widget settings
|
|
||||||
Route::get('widgets/delete/{id}', 'EditWidget@deleteWidget')
|
|
||||||
->name('widgets.delete');
|
|
||||||
|
|
||||||
Route::post('widgets/edit/{id}', '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')
|
|
||||||
->name('widgets.deleteAssociation');
|
|
||||||
|
|
||||||
Route::get('widgets/associate/{widgetId}/{widgetArea}', 'AssociateWidget@makeAssociation')
|
|
||||||
->name('widgets.makeAssociation');
|
|
||||||
|
|
||||||
// uploader methods
|
|
||||||
Route::get('directories/new/{id?}', 'CreateNewDirectory@getNew')
|
|
||||||
->name('upload.newDirectory');
|
|
||||||
|
|
||||||
Route::get('directories/edit/{id}', 'EditDirectory@getEdit')
|
|
||||||
->name('upload.editDirectory');
|
|
||||||
|
|
||||||
Route::post('directories/edit/{id}', 'EditDirectory@postEdit')
|
|
||||||
->name('upload.postEditDirectory');
|
|
||||||
|
|
||||||
Route::get('files/overview/{id?}/{type?}/{subtype?}', 'UploadedFilesOverview@getOverview')
|
|
||||||
->name('upload.overview');
|
|
||||||
|
|
||||||
route::post('directories/new', 'CreateNewDirectory@postNew')
|
|
||||||
->name('upload.postNewDirectory');
|
|
||||||
|
|
||||||
Route::get('upload/detail/{id}', 'EditUploadedFile@getDetail')
|
|
||||||
->name('upload.detail');
|
|
||||||
|
|
||||||
Route::post('upload/detail/{id}', 'EditUploadedFile@postEdit')
|
|
||||||
->name('upload.postEdit');
|
|
||||||
|
|
||||||
Route::get('upload/delete/{id}', 'EditUploadedFile@deleteFile')
|
|
||||||
->name('upload.delete');
|
|
||||||
|
|
||||||
// uploader methods
|
|
||||||
Route::post('upload/file', 'UploadFile@postFile')
|
|
||||||
->name('upload.postFile');
|
|
||||||
|
|
||||||
Route::post('upload/image', 'UploadFile@postImage')
|
|
||||||
->name('upload.postImage');
|
|
||||||
|
|
||||||
// form with settings
|
|
||||||
Route::get('settings', 'Settings@getOverview')
|
|
||||||
->name('settings.overview');
|
|
||||||
|
|
||||||
Route::post('settings', 'Settings@saveSettings')
|
|
||||||
->name('settings.save');
|
|
||||||
|
|
||||||
Route::get('search', 'Search@getSearch')
|
Route::get('search', 'Search@getSearch')
|
||||||
->name('search');
|
->name('search');
|
||||||
|
|
||||||
// custom fields
|
|
||||||
// ------------------------------
|
|
||||||
|
|
||||||
// list of all custom fields
|
|
||||||
Route::get('customfields/overview', 'CustomFieldsOverview@getOverview')
|
|
||||||
->name('customfields.overview');
|
|
||||||
|
|
||||||
// logout method
|
// logout method
|
||||||
Route::get('logout', function () {
|
Route::get('logout', 'Login@logout')
|
||||||
|
|
||||||
// remove user information
|
|
||||||
\Auth::logout();
|
|
||||||
|
|
||||||
// redirect to login form with info about successfull logout
|
|
||||||
return redirect()
|
|
||||||
->route('login')
|
|
||||||
->with('success', trans('admin/common.logoutSuccessfull'));
|
|
||||||
})
|
|
||||||
->name('logout');
|
->name('logout');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -264,13 +55,12 @@ Route::group([
|
|||||||
|
|
||||||
Route::group(['middleware' => ['web']], function () {
|
Route::group(['middleware' => ['web']], function () {
|
||||||
|
|
||||||
|
// Homepage
|
||||||
Route::get('/', 'Visitor\Homepage@getIndex')
|
Route::get('/', 'Visitor\Homepage@getIndex')
|
||||||
->name('page.index');
|
->name('page.index');
|
||||||
|
|
||||||
// display login form
|
// display login form
|
||||||
Route::get('admin/login', function () {
|
Route::get('admin/login', 'Admin\Login@getLogin')
|
||||||
return view('admin.loginForm');
|
|
||||||
})
|
|
||||||
->name('loginForm');
|
->name('loginForm');
|
||||||
|
|
||||||
// handle login
|
// handle login
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
Route::group(['namespace' => 'Contents'], function () {
|
||||||
|
// list of all static pages
|
||||||
|
Route::get('content/overview/{moduleId?}/{status?}', 'ContentOverview@getOverview')
|
||||||
|
->name('content.overview');
|
||||||
|
|
||||||
|
// form for creating new static page
|
||||||
|
Route::get('content/new/{moduleId}', 'CreateNewContent@getNew')
|
||||||
|
->name('content.new');
|
||||||
|
|
||||||
|
// form for editing existing static page
|
||||||
|
Route::get('content/edit/{id}', 'EditContent@getEdit')
|
||||||
|
->name('content.edit');
|
||||||
|
|
||||||
|
// post method for creating new static page
|
||||||
|
Route::post('content/new/{moduleId}', 'CreateNewContent@postNew')
|
||||||
|
->name('content.newPost');
|
||||||
|
|
||||||
|
// post method for creating new static page
|
||||||
|
Route::post('content/edit/{id}', 'EditContent@postEdit')
|
||||||
|
->name('content.editPost');
|
||||||
|
|
||||||
|
// change status of page (protected, public or draft)
|
||||||
|
Route::get('content/status/{id}/{status}', 'EditContent@changeStatus')
|
||||||
|
->name('content.changeStatus');
|
||||||
|
|
||||||
|
// set homepage
|
||||||
|
Route::get('content/homepage/{id}', 'EditContent@setHomepage')
|
||||||
|
->name('content.setHomepage');
|
||||||
|
|
||||||
|
// delete page
|
||||||
|
Route::get('content/delete/{id}', 'EditContent@deletePage')
|
||||||
|
->name('content.delete');
|
||||||
|
|
||||||
|
// history of changes for specified page
|
||||||
|
Route::get('history/{id}', 'History@getOverview')
|
||||||
|
->name('content.history');
|
||||||
|
|
||||||
|
// history of changes for specified page
|
||||||
|
Route::get('history/{revision}/{id}', 'History@getDiff')
|
||||||
|
->name('history.diff');
|
||||||
|
});
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
Route::group(['namespace' => 'FileManager'], function () {
|
||||||
|
|
||||||
|
Route::get('files/overview/{id?}/{type?}/{subtype?}', 'UploadedFilesOverview@getOverview')
|
||||||
|
->name('upload.overview');
|
||||||
|
|
||||||
|
// uploader methods
|
||||||
|
Route::get('directories/new/{id?}', 'CreateNewDirectory@getNew')
|
||||||
|
->name('upload.newDirectory');
|
||||||
|
|
||||||
|
Route::get('directories/edit/{id}', 'EditDirectory@getEdit')
|
||||||
|
->name('upload.editDirectory');
|
||||||
|
|
||||||
|
Route::post('directories/edit/{id}', 'EditDirectory@postEdit')
|
||||||
|
->name('upload.postEditDirectory');
|
||||||
|
|
||||||
|
route::post('directories/new', 'CreateNewDirectory@postNew')
|
||||||
|
->name('upload.postNewDirectory');
|
||||||
|
|
||||||
|
Route::get('upload/detail/{id}', 'EditUploadedFile@getDetail')
|
||||||
|
->name('upload.detail');
|
||||||
|
|
||||||
|
Route::post('upload/detail/{id}', 'EditUploadedFile@postEdit')
|
||||||
|
->name('upload.postEdit');
|
||||||
|
|
||||||
|
Route::get('upload/delete/{id}', 'EditUploadedFile@deleteFile')
|
||||||
|
->name('upload.delete');
|
||||||
|
|
||||||
|
// uploader methods
|
||||||
|
Route::post('upload', 'UploadFile@postFile')
|
||||||
|
->name('upload.postFile');
|
||||||
|
});
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
// form with settings
|
||||||
|
Route::get('settings', 'Settings@getOverview')
|
||||||
|
->name('settings.overview');
|
||||||
|
|
||||||
|
Route::post('settings', 'Settings@saveSettings')
|
||||||
|
->name('settings.save');
|
||||||
@@ -0,0 +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')
|
||||||
|
->name('templates.overview');
|
||||||
|
|
||||||
|
Route::post('templates/copy', 'CopyTemplate@createCopy')
|
||||||
|
->name('templates.postCopy');
|
||||||
|
|
||||||
|
Route::get('templates/edit/{id}', 'EditTemplate@getEdit')
|
||||||
|
->name('templates.edit');
|
||||||
|
|
||||||
|
Route::post('templates/edit/{id}', 'EditTemplate@postEdit')
|
||||||
|
->name('templates.postEdit');
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
Route::group(['namespace' => 'Users'], function () {
|
||||||
|
// display form for creating new user
|
||||||
|
Route::get('users/new', 'CreateNewUser@getNewUser')
|
||||||
|
->name('users.new');
|
||||||
|
|
||||||
|
// POST methods
|
||||||
|
// display form for creating new user
|
||||||
|
Route::post('users/new', 'CreateNewUser@postRegistration')
|
||||||
|
->name('users.newPost');
|
||||||
|
|
||||||
|
// display form for edit of existing user
|
||||||
|
Route::get('users/edit/{id}', 'EditUser@getEditUser')
|
||||||
|
->name('users.edit');
|
||||||
|
|
||||||
|
// display user detail in admin
|
||||||
|
Route::get('users/detail/{id?}', 'UserDetail@getDetail')
|
||||||
|
->name('users.detail');
|
||||||
|
|
||||||
|
// method for saving edited data of user
|
||||||
|
Route::post('users/edit/{id}', 'EditUser@postEdit')
|
||||||
|
->name('users.editPost');
|
||||||
|
|
||||||
|
// display list of all users registered into our system
|
||||||
|
Route::get('users/overview/{state?}/{perPage?}', 'UsersOverview@getOverview')
|
||||||
|
->name('users.overview');
|
||||||
|
});
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
// routes for widget areas
|
||||||
|
Route::group(['namespace' => 'Widgets'], function () {
|
||||||
|
|
||||||
|
// list of all installed widget types
|
||||||
|
Route::get('widgets/overview', 'WidgetsOverview@getOverview')
|
||||||
|
->name('widgets.overview');
|
||||||
|
|
||||||
|
// create new instance of widget of given type
|
||||||
|
Route::get('widgets/new/{type}', 'CreateNewWidget@getNew')
|
||||||
|
->name('widgets.new');
|
||||||
|
|
||||||
|
Route::post('widgets/new/{type}', 'CreateNewWidget@postNew')
|
||||||
|
->name('widgets.postNew');
|
||||||
|
|
||||||
|
// edit widget settings
|
||||||
|
Route::get('widgets/edit/{id}', 'EditWidget@getEdit')
|
||||||
|
->name('widgets.edit');
|
||||||
|
|
||||||
|
// delete widget settings
|
||||||
|
Route::get('widgets/delete/{id}', 'EditWidget@deleteWidget')
|
||||||
|
->name('widgets.delete');
|
||||||
|
|
||||||
|
Route::post('widgets/edit/{id}', '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')
|
||||||
|
->name('widgets.deleteAssociation');
|
||||||
|
|
||||||
|
Route::get('widgets/associate/{widgetId}/{widgetArea}', 'AssociateWidget@makeAssociation')
|
||||||
|
->name('widgets.makeAssociation');
|
||||||
|
|
||||||
|
Route::group(['namespace' => 'Areas'], function () {
|
||||||
|
Route::get('widgets/areas/overview', 'WidgetAreaOverview@getOverview')
|
||||||
|
->name('widgetareas.overview');
|
||||||
|
|
||||||
|
// form for new widget area
|
||||||
|
Route::get('widgets/areas/new', 'CreateNewWidgetArea@getNew')
|
||||||
|
->name('widgetareas.new');
|
||||||
|
|
||||||
|
// form for new widget area
|
||||||
|
Route::post('widgets/areas/new', 'CreateNewWidgetArea@postNew')
|
||||||
|
->name('widgetareas.postNew');
|
||||||
|
|
||||||
|
// edit form for widget area
|
||||||
|
Route::get('widgets/areas/edit/{id}', 'EditWidgetArea@getEdit')
|
||||||
|
->name('widgetareas.edit');
|
||||||
|
|
||||||
|
Route::post('widgets/areas/edit/{id}', 'EditWidgetArea@postEdit')
|
||||||
|
->name('widgetareas.postEdit');
|
||||||
|
|
||||||
|
// edit form for widget area
|
||||||
|
Route::get('widgets/areas/delete/{id}', 'EditWidgetArea@deleteArea')
|
||||||
|
->name('widgetareas.delete');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -22,7 +22,6 @@ class LogDeleteContent extends Logger
|
|||||||
'id' => $event->page->id,
|
'id' => $event->page->id,
|
||||||
'url' => $event->page->url,
|
'url' => $event->page->url,
|
||||||
'title' => $event->page->title,
|
'title' => $event->page->title,
|
||||||
'revision' => $event->revision
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->saveLog($parameters);
|
$this->saveLog($parameters);
|
||||||
|
|||||||
+18
-8
@@ -5,6 +5,7 @@ namespace App\Models;
|
|||||||
use App\Enumerations\ContentStatuses;
|
use App\Enumerations\ContentStatuses;
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
@@ -15,6 +16,7 @@ use Modules\Categories\Entities\Category;
|
|||||||
*/
|
*/
|
||||||
class Content extends Model
|
class Content extends Model
|
||||||
{
|
{
|
||||||
|
use SoftDeletes;
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'user_id',
|
'user_id',
|
||||||
@@ -38,7 +40,6 @@ class Content extends Model
|
|||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
protected $subpages = [];
|
protected $subpages = [];
|
||||||
protected $subpagesInit = false;
|
protected $subpagesInit = false;
|
||||||
const STATUS_DELETED = 'deleted';
|
|
||||||
const STATUS_DRAFT = 'draft';
|
const STATUS_DRAFT = 'draft';
|
||||||
const STATUS_PROTECTED = 'protected';
|
const STATUS_PROTECTED = 'protected';
|
||||||
const STATUS_PUBLIC = 'public';
|
const STATUS_PUBLIC = 'public';
|
||||||
@@ -59,8 +60,7 @@ class Content extends Model
|
|||||||
*/
|
*/
|
||||||
public function getPageQuery()
|
public function getPageQuery()
|
||||||
{
|
{
|
||||||
return Content::where('status', '!=', Content::STATUS_DELETED)
|
return Content::where('status', '!=', Content::STATUS_DRAFT);
|
||||||
->where('status', '!=', Content::STATUS_DRAFT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,6 +179,7 @@ class Content extends Model
|
|||||||
* @param bool $handler
|
* @param bool $handler
|
||||||
* @param bool $status
|
* @param bool $status
|
||||||
* @param bool $joinAuthor
|
* @param bool $joinAuthor
|
||||||
|
* @param bool $joinParent
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -186,9 +187,10 @@ class Content extends Model
|
|||||||
{
|
{
|
||||||
$query = DB::table('contents')
|
$query = DB::table('contents')
|
||||||
->select('contents.*', 'modules.name AS module_name', 'modules.id AS module_id')
|
->select('contents.*', 'modules.name AS module_name', 'modules.id AS module_id')
|
||||||
->where('contents.status', '<>', self::STATUS_DELETED)
|
|
||||||
->where('contents.language', LaravelLocalization::getCurrentLocale())
|
|
||||||
->join('modules', 'modules.handler', '=', 'contents.module_handler')
|
->join('modules', 'modules.handler', '=', 'contents.module_handler')
|
||||||
|
->whereNull('contents.deleted_at')
|
||||||
|
->where('contents.language', LaravelLocalization::getCurrentLocale())
|
||||||
|
->where('modules.enabled', 1)
|
||||||
->orderBy('created_at', 'DESC');
|
->orderBy('created_at', 'DESC');
|
||||||
|
|
||||||
// filter results using handler
|
// filter results using handler
|
||||||
@@ -293,10 +295,10 @@ class Content extends Model
|
|||||||
public function uploadTitlePhoto(Request $request)
|
public function uploadTitlePhoto(Request $request)
|
||||||
{
|
{
|
||||||
if ($request->hasFile('titlePhoto')) {
|
if ($request->hasFile('titlePhoto')) {
|
||||||
$file = $this->file->upload($request->file('titlePhoto'), $request);
|
return $this->file->upload($request->file('titlePhoto'), $request);
|
||||||
|
|
||||||
$this->title_photo = $file['filename'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -435,4 +437,12 @@ class Content extends Model
|
|||||||
// save history
|
// save history
|
||||||
ContentHistory::create($history);
|
ContentHistory::create($history);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function view()
|
||||||
|
{
|
||||||
|
$this->timestamps = false;
|
||||||
|
$this->viewed++;
|
||||||
|
$this->save();
|
||||||
|
$this->timestamps = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-3
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Handlers\Contracts\TemplateHandler;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
@@ -20,7 +21,8 @@ class Module extends Model
|
|||||||
'module_settings',
|
'module_settings',
|
||||||
'enabled',
|
'enabled',
|
||||||
'support_categories',
|
'support_categories',
|
||||||
'manages_content'
|
'manages_content',
|
||||||
|
'is_template'
|
||||||
];
|
];
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|
||||||
@@ -45,6 +47,7 @@ class Module extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
$managesContent = $handler ? in_array('App\Handlers\Contracts\AppHandler', class_implements($handler)) : false;
|
$managesContent = $handler ? in_array('App\Handlers\Contracts\AppHandler', class_implements($handler)) : false;
|
||||||
|
$isTemplate = $handler ? in_array(TemplateHandler::class, class_implements($handler)) : false;
|
||||||
$supportCategories = $managesContent ? call_user_func([$handler, 'supportCategories']) : false;
|
$supportCategories = $managesContent ? call_user_func([$handler, 'supportCategories']) : false;
|
||||||
|
|
||||||
if ($parentModuleId) {
|
if ($parentModuleId) {
|
||||||
@@ -62,8 +65,9 @@ class Module extends Model
|
|||||||
'support_categories' => $supportCategories,
|
'support_categories' => $supportCategories,
|
||||||
'alias' => $alias,
|
'alias' => $alias,
|
||||||
'module_settings' => json_encode($settings),
|
'module_settings' => json_encode($settings),
|
||||||
'parent_id' => $parentModuleId,
|
'parent_id' => $parentModuleId ? $parentModuleId : null,
|
||||||
'enabled' => 1
|
'enabled' => 1,
|
||||||
|
'is_template' => $isTemplate
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// install something module-specific
|
// install something module-specific
|
||||||
@@ -73,4 +77,51 @@ class Module extends Model
|
|||||||
|
|
||||||
return $module;
|
return $module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete module from database and uninstall its dependencies
|
||||||
|
*
|
||||||
|
* @throws \ErrorException
|
||||||
|
*/
|
||||||
|
public function uninstall()
|
||||||
|
{
|
||||||
|
// check if user does not want to install module in runtime
|
||||||
|
if (!App::runningInConsole()) {
|
||||||
|
throw new \ErrorException('Modules can be uninstalled only via Artisan!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete everything in /resources/views/visitor
|
||||||
|
if ($this->is_template) {
|
||||||
|
$this->deleteDirectory(resource_path('views/visitor'));
|
||||||
|
$this->deleteDirectory(public_path('assets'));
|
||||||
|
|
||||||
|
// delete all template paths
|
||||||
|
TemplatePath::getQuery()->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->handler && is_callable([$this->handler, 'uninstall'])) {
|
||||||
|
call_user_func([$this->handler, 'uninstall'], $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete directory when uninstalling module.
|
||||||
|
*
|
||||||
|
* @param $directory
|
||||||
|
*
|
||||||
|
* @throws \ErrorException
|
||||||
|
*/
|
||||||
|
private function deleteDirectory($directory)
|
||||||
|
{
|
||||||
|
if (!is_dir($directory))
|
||||||
|
return;
|
||||||
|
|
||||||
|
$success = \File::deleteDirectory($directory, true);
|
||||||
|
|
||||||
|
if (!$success) {
|
||||||
|
throw new \ErrorException('Cannot delete ' . $directory);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
-2
@@ -6,6 +6,7 @@ use App\Helpers\Gravatar;
|
|||||||
use Illuminate\Auth\Authenticatable;
|
use Illuminate\Auth\Authenticatable;
|
||||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticableInterface;
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticableInterface;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Foundation\Auth\Access\Authorizable;
|
use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,8 +14,8 @@ use Illuminate\Foundation\Auth\Access\Authorizable;
|
|||||||
*/
|
*/
|
||||||
class User extends Model implements AuthenticableInterface
|
class User extends Model implements AuthenticableInterface
|
||||||
{
|
{
|
||||||
use Authenticatable, Authorizable;
|
use SoftDeletes, Authenticatable, Authorizable;
|
||||||
public $timestamps = false;
|
public $timestamps = true;
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'email',
|
'email',
|
||||||
'username',
|
'username',
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
// ignore running from artisan
|
// ignore running from artisan
|
||||||
if (App::runningInConsole()) {
|
if (App::runningInConsole()) {
|
||||||
$this->publishViewResources();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,13 +37,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$this->registerTemplates();
|
$this->registerTemplates();
|
||||||
$this->registerSettings();
|
$this->registerSettings();
|
||||||
$this->registerSearch();
|
$this->registerSearch();
|
||||||
|
|
||||||
// check if given template is valid
|
|
||||||
$theme = config('app.theme');
|
|
||||||
$themeDir = resource_path('views/visitor/' . $theme);
|
|
||||||
if (!$theme || empty($theme) || !is_dir($themeDir)) {
|
|
||||||
throw new InvalidArgumentException('No or invalid theme set! Use artisan theme:set or edit .env file manually and include THEME option, please');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,10 +111,10 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
/**
|
/**
|
||||||
* @var $registrator TemplateRegistrator
|
* @var $registrator TemplateRegistrator
|
||||||
*/
|
*/
|
||||||
$registrator = $this->app->make('registerTemplateDir');
|
// $registrator = $this->app->make('registerTemplateDir');
|
||||||
$registrator->setBaseDirectory('resources/views/visitor');
|
// $registrator->setBaseDirectory('resources/views/visitor');
|
||||||
|
|
||||||
$registrator->register(config('app.theme'), 'admin/templates.core');
|
// $registrator->register(config('app.theme'), 'admin/templates.core');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,37 +141,5 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$registrator->register(new Files(), new AdminFiles(), SearchEngineRegistrator::ADMIN);
|
$registrator->register(new Files(), new AdminFiles(), SearchEngineRegistrator::ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Publish all public assets from all themes
|
|
||||||
*/
|
|
||||||
private function publishViewResources()
|
|
||||||
{
|
|
||||||
$theme = config('app.theme');
|
|
||||||
$themeDir = resource_path('views/visitor/' . $theme);
|
|
||||||
|
|
||||||
// publish assets if exists for current theme
|
|
||||||
if (is_dir($themeDir . '/' . Template::ASSETS_DIRECTORY)) {
|
|
||||||
$this->publishes([$themeDir . '/' . Template::ASSETS_DIRECTORY => public_path('assets/' . $theme)], 'public-assets');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_dir($themeDir . '/' . Template::MODULES_DIRECTORY)) {
|
|
||||||
$this->publishModuleViews($themeDir . '/' . Template::MODULES_DIRECTORY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function publishModuleViews($themeModules)
|
|
||||||
{
|
|
||||||
$theme = config('app.theme');
|
|
||||||
$modules = File::directories($themeModules);
|
|
||||||
|
|
||||||
$moduleViews = [];
|
|
||||||
foreach ($modules as $module) {
|
|
||||||
$moduleName = strtolower(basename($module));
|
|
||||||
$moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($moduleViews)) {
|
|
||||||
$this->publishes($moduleViews, 'module-views');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ class GlobalViewDataProvider extends ServiceProvider
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings = new Settings();
|
// $settings = new Settings();
|
||||||
|
//
|
||||||
foreach ($settings->getForView() as $key => $value) {
|
// foreach ($settings->getForView() as $key => $value) {
|
||||||
view()->share($key, $value);
|
// view()->share($key, $value);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$this->extendBlade();
|
$this->extendBlade();
|
||||||
}
|
}
|
||||||
@@ -73,6 +73,14 @@ class GlobalViewDataProvider extends ServiceProvider
|
|||||||
return preg_replace($pattern, $code, $view);
|
return preg_replace($pattern, $code, $view);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// shortcut for displaying Gravatar
|
||||||
|
Blade::extend(function ($view) {
|
||||||
|
$pattern = $this->createPattern('gravatar');
|
||||||
|
$code = '<?php echo \App\Helpers\Gravatar::img($2); ?>';
|
||||||
|
|
||||||
|
return preg_replace($pattern, $code, $view);
|
||||||
|
});
|
||||||
|
|
||||||
// shortcut for assets (placed in /public/assets/<theme>
|
// shortcut for assets (placed in /public/assets/<theme>
|
||||||
Blade::extend(function ($view) {
|
Blade::extend(function ($view) {
|
||||||
$pattern = $this->createPattern('asset');
|
$pattern = $this->createPattern('asset');
|
||||||
|
|||||||
@@ -5,18 +5,13 @@ use Illuminate\Support\Facades\App;
|
|||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
use Symfony\Component\Translation\Translator;
|
|
||||||
|
|
||||||
class LaravelLocalizationServiceProvider extends ServiceProvider
|
class LaravelLocalizationServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$languages = DB::table('languages')
|
$languages = DB::table('languages')
|
||||||
->get();
|
->get();
|
||||||
} catch (\Exception $e) {
|
|
||||||
$languages = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$supportedLocales = [];
|
$supportedLocales = [];
|
||||||
if (empty($languages)) {
|
if (empty($languages)) {
|
||||||
@@ -28,11 +23,7 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
|
|||||||
];
|
];
|
||||||
|
|
||||||
// create default language
|
// create default language
|
||||||
try {
|
|
||||||
Language::create($supportedLocales[config('app.locale')]);
|
Language::create($supportedLocales[config('app.locale')]);
|
||||||
} catch (\Exception $e) {
|
|
||||||
// ignore, table languages probably does not exist.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($languages as $language) {
|
foreach ($languages as $language) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
@@ -15,16 +14,31 @@ class ModuleManager extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
// ignore running from artisan
|
// this service provider needs published config - config is merged right after this service provider
|
||||||
if (App::runningInConsole()) {
|
try {
|
||||||
|
$modules = Module::where('enabled', true)
|
||||||
|
->get();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// ignore error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this service provider needs published config - config is merged right after this service provider
|
|
||||||
$modules = Module::get();
|
|
||||||
|
|
||||||
// iterate over all modules and enable or disable them
|
// iterate over all modules and enable or disable them
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
|
|
||||||
|
$module->module_settings = json_decode($module->module_settings);
|
||||||
|
|
||||||
|
if ($module->is_template) {
|
||||||
|
|
||||||
|
if (isset($module->module_settings->providers) && !empty($module->module_settings->providers)) {
|
||||||
|
foreach ($module->module_settings->providers as $provider) {
|
||||||
|
$this->app->register($provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$this->createModulesJson($module);
|
$this->createModulesJson($module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +61,7 @@ class ModuleManager extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
private function createModulesJson(Module $module)
|
private function createModulesJson(Module $module)
|
||||||
{
|
{
|
||||||
$config = json_decode($module->module_settings);
|
$config = $module->module_settings;
|
||||||
|
|
||||||
if (is_null($config)) {
|
if (is_null($config)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ use Pingpong\Modules\Json;
|
|||||||
class SubmodulesManager extends ServiceProvider
|
class SubmodulesManager extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Register the service provider.
|
* Boot submodules
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function boot()
|
||||||
{
|
{
|
||||||
$enabledModules = \Module::enabled();
|
$enabledModules = \Module::enabled();
|
||||||
|
|
||||||
@@ -52,4 +52,14 @@ class SubmodulesManager extends ServiceProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the service provider.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
// TODO: Implement register() method.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Handlers\Registrators\TemplateRegistrator;
|
||||||
|
use App\Models\Module;
|
||||||
|
use App\Models\Template;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
class TemplateServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
private function getTemplate()
|
||||||
|
{
|
||||||
|
// select template
|
||||||
|
try {
|
||||||
|
$template = Module::where('is_template', true)
|
||||||
|
->where('enabled', true)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($template) {
|
||||||
|
$template->settings = json_decode($template->module_settings);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
// ignore running from artisan
|
||||||
|
if (App::runningInConsole()) {
|
||||||
|
$this->publishViewResources();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$template = $this->getTemplate();
|
||||||
|
|
||||||
|
if (!$template) {
|
||||||
|
throw new \ErrorException('Template is not set, cannot continue');
|
||||||
|
}
|
||||||
|
|
||||||
|
// include files
|
||||||
|
$files = isset($template->settings->files) ? $template->settings->files : [];
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
include_once $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// register templates
|
||||||
|
$publicTemplates = call_user_func([$template->handler, 'getPublicTemplatePaths']);
|
||||||
|
|
||||||
|
if (!is_array($publicTemplates)) {
|
||||||
|
throw new \ErrorException($template->handler . '::getPublicTemplatePaths() must return array!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($publicTemplates)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $registrator TemplateRegistrator
|
||||||
|
*/
|
||||||
|
$registrator = $this->app->make('registerTemplateDir');
|
||||||
|
foreach ($publicTemplates as $template) {
|
||||||
|
// setup some global variables
|
||||||
|
$module = strtolower($template['module']);
|
||||||
|
$namespace = isset($template['namespace']) ? $template['namespace'] : strtolower($template['module']);
|
||||||
|
try {
|
||||||
|
$registrator->setBaseDirectory('resources/views/modules/' . $module);
|
||||||
|
$registrator->setNamespace($namespace);
|
||||||
|
$registrator->setModuleId(call_user_func([config($module . '.handler'), 'getModuleId']));
|
||||||
|
|
||||||
|
// register path with current template name
|
||||||
|
$registrator->register('visitor', $template['templateName']);
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
// ignore this exception
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the service provider.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish all public assets from all themes
|
||||||
|
*/
|
||||||
|
private function publishViewResources()
|
||||||
|
{
|
||||||
|
$template = $this->getTemplate();
|
||||||
|
if (!$template) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$templateDir = app_path('../templates/' . $template->settings->staticName . '/Resources');
|
||||||
|
$assetsDir = $templateDir . '/' . Template::ASSETS_DIRECTORY;
|
||||||
|
$viewsDir = $templateDir . '/views';
|
||||||
|
|
||||||
|
// publish assets if exists for current theme
|
||||||
|
if (is_dir($assetsDir)) {
|
||||||
|
$this->publishes([$assetsDir => public_path('assets/visitor')], 'public-assets');
|
||||||
|
}
|
||||||
|
|
||||||
|
// publish base visitors views
|
||||||
|
$this->publishes([$viewsDir . '/visitor' => resource_path('views/visitor')], 'module-views');
|
||||||
|
|
||||||
|
// publish admin views
|
||||||
|
if (is_dir($viewsDir . '/modules')) {
|
||||||
|
$this->publishes([$viewsDir . '/modules' => resource_path('views/modules')], 'module-views');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,8 +72,7 @@ class Menu extends NonInstallableWidget
|
|||||||
|
|
||||||
public static function selectContentPages($ids)
|
public static function selectContentPages($ids)
|
||||||
{
|
{
|
||||||
$pages = Content::where('status', '!=', Content::STATUS_DELETED)
|
$pages = Content::where('language', LaravelLocalization::getCurrentLocale())
|
||||||
->where('language', LaravelLocalization::getCurrentLocale())
|
|
||||||
->whereIn('id', $ids)
|
->whereIn('id', $ids)
|
||||||
->get();
|
->get();
|
||||||
$used = [];
|
$used = [];
|
||||||
|
|||||||
+2
-7
@@ -30,16 +30,11 @@
|
|||||||
],
|
],
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "app/",
|
"App\\": "app/",
|
||||||
"Modules\\": "modules/"
|
"Modules\\": "modules/",
|
||||||
|
"Templates\\": "templates/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"post-root-package-install": [
|
|
||||||
"php -r \"copy('.env.example', '.env');\""
|
|
||||||
],
|
|
||||||
"post-create-project-cmd": [
|
|
||||||
"php artisan key:generate"
|
|
||||||
],
|
|
||||||
"post-install-cmd": [
|
"post-install-cmd": [
|
||||||
"php artisan clear-compiled",
|
"php artisan clear-compiled",
|
||||||
"php artisan optimize"
|
"php artisan optimize"
|
||||||
|
|||||||
+1
-1
@@ -159,7 +159,6 @@ return [
|
|||||||
Pingpong\Modules\ModulesServiceProvider::class,
|
Pingpong\Modules\ModulesServiceProvider::class,
|
||||||
Pingpong\Menus\MenusServiceProvider::class,
|
Pingpong\Menus\MenusServiceProvider::class,
|
||||||
App\Providers\SubmodulesManager::class,
|
App\Providers\SubmodulesManager::class,
|
||||||
|
|
||||||
Franzose\ClosureTable\ClosureTableServiceProvider::class,
|
Franzose\ClosureTable\ClosureTableServiceProvider::class,
|
||||||
\Watson\Sitemap\SitemapServiceProvider::class,
|
\Watson\Sitemap\SitemapServiceProvider::class,
|
||||||
/*
|
/*
|
||||||
@@ -170,6 +169,7 @@ return [
|
|||||||
App\Providers\EventServiceProvider::class,
|
App\Providers\EventServiceProvider::class,
|
||||||
App\Providers\RouteServiceProvider::class,
|
App\Providers\RouteServiceProvider::class,
|
||||||
App\Providers\GlobalViewDataProvider::class,
|
App\Providers\GlobalViewDataProvider::class,
|
||||||
|
\App\Providers\TemplateServiceProvider::class,
|
||||||
|
|
||||||
],
|
],
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class SaveTemplatesIntoModulesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('modules', function (Blueprint $table){
|
||||||
|
$table->boolean('is_template')->default(false)->comment('Templates can be treated as modules.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('modules', function (Blueprint $table){
|
||||||
|
$table->dropColumn('is_template');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddNumberOfViewsOfPage extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->integer('viewed')
|
||||||
|
->comment('How many times has been this content page displayed?')
|
||||||
|
->after('updated_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('viewed');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddTemplateSupportToWidgets extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('widget_types', function (Blueprint $table) {
|
||||||
|
$table->integer('template_id')
|
||||||
|
->comment('Commes this widget with template?')
|
||||||
|
->after('handler')
|
||||||
|
->nullable(true)
|
||||||
|
->default(null);
|
||||||
|
$table->integer('module_id')
|
||||||
|
->comment('Commes this widget with some module?')
|
||||||
|
->after('template_id')
|
||||||
|
->nullable(true)
|
||||||
|
->default(null);
|
||||||
|
|
||||||
|
$table->foreign('template_id')
|
||||||
|
->references('id')
|
||||||
|
->on('modules')
|
||||||
|
->onDelete('cascade')
|
||||||
|
->onUpdate('cascade');
|
||||||
|
|
||||||
|
$table->foreign('module_id')
|
||||||
|
->references('id')
|
||||||
|
->on('modules')
|
||||||
|
->onDelete('cascade')
|
||||||
|
->onUpdate('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('widget_types', function (Blueprint $table) {
|
||||||
|
$table->dropForeign('widget_types_module_id_foreign');
|
||||||
|
$table->dropForeign('widget_types_template_id_foreign');
|
||||||
|
$table->dropColumn(['template_id', 'module_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class MakeWidgetsAndWidgetAreasNotDeletable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('widgets', function (Blueprint $table) {
|
||||||
|
$table->boolean('deletable')
|
||||||
|
->default(true)
|
||||||
|
->comment('Can this widget be deleted?');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('widget_areas', function (Blueprint $table) {
|
||||||
|
$table->boolean('deletable')
|
||||||
|
->default(true)
|
||||||
|
->comment('Can this widget area be deleted?');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('widgets', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('deletable');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('widget_areas', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('deletable');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AddSoftDeletesToContent extends Migration
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$platform = Schema::getConnection()
|
||||||
|
->getDoctrineSchemaManager()
|
||||||
|
->getDatabasePlatform();
|
||||||
|
$platform->registerDoctrineTypeMapping('enum', 'string');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->softDeletes()
|
||||||
|
->after('updated_at');
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement("
|
||||||
|
ALTER TABLE `contents`
|
||||||
|
CHANGE `status` `status` enum('draft','protected','public') COLLATE 'utf8_unicode_ci' NOT NULL DEFAULT 'draft' AFTER `module_settings`
|
||||||
|
");
|
||||||
|
|
||||||
|
DB::statement('UPDATE contents SET status="protected", deleted_at=NOW() WHERE status=""');
|
||||||
|
DB::statement('DELETE FROM content_history WHERE new_value="deleted" OR old_value="deleted"');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->dropSoftDeletes();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement("ALTER TABLE `contents`
|
||||||
|
CHANGE `status` `status` enum('draft','protected','public', 'deleted') COLLATE 'utf8_unicode_ci' NULL DEFAULT 'draft' AFTER `module_settings`;");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
|
||||||
|
class AddSoftDeletesToUsers extends Migration
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$platform = Schema::getConnection()
|
||||||
|
->getDoctrineSchemaManager()
|
||||||
|
->getDatabasePlatform();
|
||||||
|
$platform->registerDoctrineTypeMapping('enum', 'string');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->timestamp('created_at')
|
||||||
|
->nullable()
|
||||||
|
->after('id');
|
||||||
|
$table->timestamp('updated_at')
|
||||||
|
->nullable()
|
||||||
|
->after('created_at');
|
||||||
|
$table->timestamp('deleted_at')
|
||||||
|
->nullable()
|
||||||
|
->after('updated_at');
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement("
|
||||||
|
ALTER TABLE `users`
|
||||||
|
CHANGE `status` `status` enum('blocked','active') COLLATE 'utf8_unicode_ci' NOT NULL DEFAULT 'active'
|
||||||
|
");
|
||||||
|
|
||||||
|
DB::statement('UPDATE users SET created_at=NOW(), updated_at=NOW()');
|
||||||
|
DB::statement('UPDATE users SET status="blocked", deleted_at=NOW() WHERE status=""');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropTimestamps();
|
||||||
|
$table->dropSoftDeletes();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement("
|
||||||
|
ALTER TABLE `users`
|
||||||
|
CHANGE `status` `status` enum('blocked','active', 'deleted') COLLATE 'utf8_unicode_ci' NOT NULL DEFAULT 'active'
|
||||||
|
");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class FixForeignKeysOnActionLog extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('action_log', function (Blueprint $table) {
|
||||||
|
$table->dropForeign('fk_action_log_action_log_type1');
|
||||||
|
$table->dropForeign('fk_action_log_user1');
|
||||||
|
|
||||||
|
|
||||||
|
$table->foreign('type_id')
|
||||||
|
->references('id')
|
||||||
|
->on('action_log_types')
|
||||||
|
->onDelete('cascade')
|
||||||
|
->onUpdate('cascade');
|
||||||
|
|
||||||
|
|
||||||
|
$table->foreign('user_id')
|
||||||
|
->references('id')
|
||||||
|
->on('users')
|
||||||
|
->onDelete('cascade')
|
||||||
|
->onUpdate('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
+692
-344
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
|||||||
|
<?php namespace Modules\Blog\Article\Entities;
|
||||||
|
|
||||||
|
use App\Models\Content;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Comment extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'user_id',
|
||||||
|
'content_id',
|
||||||
|
'content',
|
||||||
|
'email',
|
||||||
|
'name'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function author()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'user_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function article()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Content::class, 'content_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\Blog\Article\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Modules\Blog\Article\Entities\Comment;
|
||||||
|
|
||||||
|
class ApprovedComment extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
/**
|
||||||
|
* @var Comment
|
||||||
|
*/
|
||||||
|
public $comment;
|
||||||
|
|
||||||
|
public function __construct(Comment $comment)
|
||||||
|
{
|
||||||
|
$this->comment = $comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\Blog\Article\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Modules\Blog\Article\Entities\Comment;
|
||||||
|
|
||||||
|
class CreatedComment extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
/**
|
||||||
|
* @var Comment
|
||||||
|
*/
|
||||||
|
public $comment;
|
||||||
|
|
||||||
|
public function __construct(Comment $comment)
|
||||||
|
{
|
||||||
|
$this->comment = $comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\Blog\Article\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Modules\Blog\Article\Entities\Comment;
|
||||||
|
|
||||||
|
class DeletedComment extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
/**
|
||||||
|
* @var Comment
|
||||||
|
*/
|
||||||
|
public $comment;
|
||||||
|
|
||||||
|
public function __construct(Comment $comment)
|
||||||
|
{
|
||||||
|
$this->comment = $comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,14 +2,17 @@
|
|||||||
namespace Modules\Blog\Article\Handlers;
|
namespace Modules\Blog\Article\Handlers;
|
||||||
|
|
||||||
use App\Enumerations\ModulesHandlerToId;
|
use App\Enumerations\ModulesHandlerToId;
|
||||||
|
use App\Handlers\Contracts\ContentTitles;
|
||||||
use App\Handlers\Handler;
|
use App\Handlers\Handler;
|
||||||
use App\Http\Controllers\Admin\EditContent;
|
use App\Http\Controllers\Admin\Contents\EditContent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
|
use App\Models\ActionLogType;
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Modules\Blog\Article\Entities\Comment;
|
||||||
|
|
||||||
class Article extends Handler
|
class Article extends Handler implements ContentTitles
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Render given module into visitor area.
|
* Render given module into visitor area.
|
||||||
@@ -21,7 +24,15 @@ class Article extends Handler
|
|||||||
*/
|
*/
|
||||||
public function render(Content $content, $parameters)
|
public function render(Content $content, $parameters)
|
||||||
{
|
{
|
||||||
return Controller::VisitorsView($content->template, ['page' => $content]);
|
$content->comments = [];
|
||||||
|
if (isset($content->module_settings->allowComments) && $content->module_settings->allowComments) {
|
||||||
|
$content->comments = Comment::where('content_id', $content->id)
|
||||||
|
->where('approved', 1)
|
||||||
|
->orderBy('created_at')
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Controller::VisitorsView($content->template, ['page' => $content, 'extra' => $parameters]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getExtendedFormInputsCreate()
|
public static function getExtendedFormInputsCreate()
|
||||||
@@ -80,6 +91,7 @@ class Article extends Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Register admin menu
|
||||||
*
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
@@ -89,10 +101,20 @@ class Article extends Handler
|
|||||||
|
|
||||||
$menu = \Menu::instance('mainMenu');
|
$menu = \Menu::instance('mainMenu');
|
||||||
|
|
||||||
$menu->dropdown(trans('article::module.name'), function ($sub) {
|
$blogSubmenu = $menu->whereTitle(trans('article::module.blog'));
|
||||||
|
if (!$blogSubmenu) {
|
||||||
|
$blogSubmenu = $menu->dropdown(trans('article::module.blog'), function ($sub) {
|
||||||
|
}, 20, ['icon' => 'fa fa-fw fa-book']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$blogSubmenu->dropdown(trans('article::module.name'), function ($sub) {
|
||||||
$sub->route('content.new', trans('article::article.new'), ['id' => self::getModuleId()], 10, ['icon' => 'fa fa-fw fa-pencil']);
|
$sub->route('content.new', trans('article::article.new'), ['id' => self::getModuleId()], 10, ['icon' => 'fa fa-fw fa-pencil']);
|
||||||
$sub->route('content.overview', trans('article::article.overview'), ['id' => self::getModuleId()], 30, ['icon' => 'fa fa-fw fa-book']);
|
$sub->route('content.overview', trans('article::article.overview'), ['id' => self::getModuleId()], 30, ['icon' => 'fa fa-fw fa-book']);
|
||||||
}, 10, ['icon' => 'fa fa-fw fa-book']);
|
}, 10, ['icon' => 'fa fa-fw fa-book']);
|
||||||
|
|
||||||
|
$blogSubmenu->dropdown(trans('article::module.comments'), function ($sub) {
|
||||||
|
$sub->route('comments.overview', trans('article::module.commentsOverview'), [], 10, ['icon' => 'fa fa-fw fa-commenting-o']);
|
||||||
|
}, 20, ['icon' => 'fa fa-fw fa-comments-o']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getModuleId()
|
public static function getModuleId()
|
||||||
@@ -106,10 +128,63 @@ class Article extends Handler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Install module
|
* Install module
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public static function install()
|
public static function install()
|
||||||
{
|
{
|
||||||
|
$types = [
|
||||||
|
[
|
||||||
|
'string_id' => 'commentCreated',
|
||||||
|
'name' => 'article::comments.events.names.commentCreated',
|
||||||
|
'value' => 'article::comments.events.descriptions.commentCreated',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'string_id' => 'commentDeleted',
|
||||||
|
'name' => 'article::comments.events.names.commentDeleted',
|
||||||
|
'value' => 'article::comments.events.descriptions.commentDeleted',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'string_id' => 'commentApproved',
|
||||||
|
'name' => 'article::comments.events.names.commentApproved',
|
||||||
|
'value' => 'article::comments.events.descriptions.commentApproved',
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
foreach ($types as $type) {
|
||||||
|
ActionLogType::create($type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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()
|
||||||
|
{
|
||||||
|
return trans('article::module.allArticles');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title displayed above for for creating new content page
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getCreateNewTitle()
|
||||||
|
{
|
||||||
|
return trans('article::module.newArticle');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title for form displayed for editin content page
|
||||||
|
*
|
||||||
|
* @param Content $content
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function getEditTitle(Content $content)
|
||||||
|
{
|
||||||
|
return trans('article::module.editArticle');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\Blog\Article\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Modules\Blog\Article\Entities\Comment;
|
||||||
|
use Pingpong\Modules\Routing\Controller;
|
||||||
|
|
||||||
|
class CommentsOverview extends Controller
|
||||||
|
{
|
||||||
|
public function getOverview()
|
||||||
|
{
|
||||||
|
$comments = Comment::with('article')
|
||||||
|
->with('author')
|
||||||
|
->orderBy('approved')
|
||||||
|
->orderBy('created_at', 'DESC')
|
||||||
|
->paginate(25);
|
||||||
|
|
||||||
|
return view('article::admin/comments.overview', ['comments' => $comments]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\Blog\Article\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Modules\Blog\Article\Entities\Comment;
|
||||||
|
use Modules\Blog\Article\Events\ApprovedComment;
|
||||||
|
use Modules\Blog\Article\Events\DeletedComment;
|
||||||
|
use Pingpong\Modules\Routing\Controller;
|
||||||
|
|
||||||
|
class EditComment extends Controller
|
||||||
|
{
|
||||||
|
public function approve($id)
|
||||||
|
{
|
||||||
|
$comment = Comment::findOrFail($id);
|
||||||
|
$comment->approved = 1;
|
||||||
|
$comment->save();
|
||||||
|
|
||||||
|
Event::fire(new ApprovedComment($comment));
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('success', trans('article::comments.approved'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id)
|
||||||
|
{
|
||||||
|
$comment = Comment::findOrFail($id);
|
||||||
|
|
||||||
|
Event::fire(new DeletedComment($comment));
|
||||||
|
|
||||||
|
$comment->delete();
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('success', trans('article::comments.deleted'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\Blog\Article\Http\Controllers\Visitor;
|
||||||
|
|
||||||
|
use App\Models\Content;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Modules\Blog\Article\Entities\Comment;
|
||||||
|
use Modules\Blog\Article\Events\CreatedComment;
|
||||||
|
use Modules\Blog\Article\Handlers\Article;
|
||||||
|
use Pingpong\Modules\Routing\Controller;
|
||||||
|
|
||||||
|
class CreateNewComment extends Controller
|
||||||
|
{
|
||||||
|
public function postNew(\Modules\Blog\Article\Http\Requests\CreateNewComment $request, $articleId)
|
||||||
|
{
|
||||||
|
$article = Content::where('id', $articleId)
|
||||||
|
->where('module_handler', Article::class)
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$article->module_settings = json_decode($article->module_settings);
|
||||||
|
|
||||||
|
if (!isset($article->module_settings->allowComments) || !$article->module_settings->allowComments) {
|
||||||
|
return redirect()
|
||||||
|
->route('page.content', ['url' => $article->url])
|
||||||
|
->with('error', trans('article::comments.disabledComments'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$content = $request->message;
|
||||||
|
$user = Auth::user();
|
||||||
|
if ($user) {
|
||||||
|
$name = $user->name;
|
||||||
|
$email = $user->email;
|
||||||
|
} else {
|
||||||
|
$name = $request->name;
|
||||||
|
$email = $request->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
$comment = Comment::create([
|
||||||
|
'user_id' => $user ? $user->id : null,
|
||||||
|
'content_id' => $article->id,
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
'content' => $content
|
||||||
|
]);
|
||||||
|
|
||||||
|
// fire event about new comment
|
||||||
|
Event::fire(new CreatedComment($comment));
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->route('page.content', ['url' => $article->url])
|
||||||
|
->with('success', trans('article::comments.saved'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Blog\Article\Http\Requests;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class CreateNewComment extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
$required = ['message' => 'required'];
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
$required['name'] = 'required';
|
||||||
|
$required['email'] = 'required|email';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $required;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
Route::group([
|
Route::group([
|
||||||
'middleware' => 'web',
|
'prefix' => LaravelLocalization::setLocale(),
|
||||||
'prefix' => 'article',
|
'middleware' => ['localeSessionRedirect', 'localizationRedirect'],
|
||||||
'namespace' => 'Modules\Blog\Article\Http\Controllers'
|
'namespace' => 'Modules\Blog\Article\Http\Controllers\Admin'
|
||||||
|
], function () {
|
||||||
|
Route::group([
|
||||||
|
'middleware' => ['web', 'auth', 'adminMenu'],
|
||||||
|
'prefix' => 'admin/comments',
|
||||||
], function () {
|
], function () {
|
||||||
Route::get('/', 'CategoriesOverview@getOverview')
|
|
||||||
->name('article.overview');
|
|
||||||
|
|
||||||
Route::get('/new', 'CreateNewCategory@getNew')
|
Route::get('/', 'CommentsOverview@getOverview')
|
||||||
->name('article.new');
|
->name('comments.overview');
|
||||||
|
|
||||||
Route::post('/new', 'CreateNewCategory@postNew')
|
Route::get('/delete/{id}', 'EditComment@delete')
|
||||||
->name('article.postNew');
|
->name('comments.delete');
|
||||||
|
|
||||||
Route::get('/edit/{id}', 'EditCategory@getEdit')
|
Route::get('/approve/{id}', 'EditComment@approve')
|
||||||
->name('article.edit');
|
->name('comments.approve');
|
||||||
|
});
|
||||||
|
|
||||||
Route::post('/edit/{id}', 'EditCategory@postEdit')
|
// public routes
|
||||||
->name('article.postEdit');
|
Route::group(['middleware' => ['web']], function () {
|
||||||
|
|
||||||
Route::get('/delete/{id}', 'EditCategory@delete')
|
Route::post('comments/new/{id}', 'CreateNewComment@postNew')
|
||||||
->name('article.delete');
|
->name('comments.new');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Blog\Article\Listeners;
|
||||||
|
|
||||||
|
use App\Listeners\Logger;
|
||||||
|
use Modules\Blog\Article\Events\ApprovedComment;
|
||||||
|
|
||||||
|
class LogCommentApproval extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param ApprovedComment $event
|
||||||
|
*/
|
||||||
|
public function handle(ApprovedComment $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'author' => $event->comment->name,
|
||||||
|
'email' => $event->comment->email,
|
||||||
|
'content' => $event->comment->content
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'commentApproved';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Blog\Article\Listeners;
|
||||||
|
|
||||||
|
use App\Listeners\Logger;
|
||||||
|
use Modules\Blog\Article\Events\ApprovedComment;
|
||||||
|
use Modules\Blog\Article\Events\DeletedComment;
|
||||||
|
|
||||||
|
class LogDeletedComment extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param DeletedComment $event
|
||||||
|
*/
|
||||||
|
public function handle(DeletedComment $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'author' => $event->comment->name,
|
||||||
|
'email' => $event->comment->email,
|
||||||
|
'content' => $event->comment->content
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'commentDeleted';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Blog\Article\Listeners;
|
||||||
|
|
||||||
|
use App\Listeners\Logger;
|
||||||
|
use Modules\Blog\Article\Events\CreatedComment;
|
||||||
|
|
||||||
|
class LogNewComment extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param CreatedComment $event
|
||||||
|
*/
|
||||||
|
public function handle(CreatedComment $event)
|
||||||
|
{
|
||||||
|
// log only logged-in users
|
||||||
|
if (!$event->comment->user_id)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'author' => $event->comment->name,
|
||||||
|
'email' => $event->comment->email,
|
||||||
|
'content' => $event->comment->content
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'commentCreated';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Blog\Article\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
||||||
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
use Modules\Blog\Article\Events\ApprovedComment;
|
||||||
|
use Modules\Blog\Article\Events\CreatedComment;
|
||||||
|
use Modules\Blog\Article\Events\DeletedComment;
|
||||||
|
use Modules\Blog\Article\Listeners\LogCommentApproval;
|
||||||
|
use Modules\Blog\Article\Listeners\LogDeletedComment;
|
||||||
|
|
||||||
|
class ArticleEventServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The event listener mappings for the application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $listen = [
|
||||||
|
ApprovedComment::class => [LogCommentApproval::class],
|
||||||
|
DeletedComment::class => [LogDeletedComment::class],
|
||||||
|
CreatedComment::class => [LogNewComment::class],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function boot(DispatcherContract $events)
|
||||||
|
{
|
||||||
|
parent::boot($events); // TODO: Change the autogenerated stub
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,8 @@ class ArticleServiceProvider extends ServiceProvider {
|
|||||||
$this->registerTranslations();
|
$this->registerTranslations();
|
||||||
$this->registerConfig();
|
$this->registerConfig();
|
||||||
$this->registerViews();
|
$this->registerViews();
|
||||||
|
|
||||||
|
$this->app->register(ArticleEventServiceProvider::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,27 +59,11 @@ class ArticleServiceProvider extends ServiceProvider {
|
|||||||
$viewPath = base_path('resources/views/modules/article');
|
$viewPath = base_path('resources/views/modules/article');
|
||||||
$sourcePath = __DIR__.'/../Resources/views';
|
$sourcePath = __DIR__.'/../Resources/views';
|
||||||
|
|
||||||
$this->publishes([$sourcePath => $viewPath]);
|
$this->publishes([$sourcePath => $viewPath], 'module-views');
|
||||||
|
|
||||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||||
return $path . '/modules/article';
|
return $path . '/modules/article';
|
||||||
}, \Config::get('view.paths')), [$sourcePath]), 'article');
|
}, \Config::get('view.paths')), [$sourcePath]), 'article');
|
||||||
|
|
||||||
/**
|
|
||||||
* @var $registrator TemplateRegistrator
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
// setup some global variables
|
|
||||||
$registrator = $this->app->make('registerTemplateDir');
|
|
||||||
$registrator->setBaseDirectory('resources/views/modules/article/visitor');
|
|
||||||
$registrator->setNamespace('article');
|
|
||||||
$registrator->setModuleId(Article::getModuleId());
|
|
||||||
|
|
||||||
// register path with current template name
|
|
||||||
$registrator->register(config('app.theme'), 'article::admin/adminMenu.templatePath');
|
|
||||||
} catch (InvalidArgumentException $e) {
|
|
||||||
// ignore this exception
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
"allowComments" => "Povolit komentáře?",
|
||||||
|
"new" => "Napsat",
|
||||||
|
"overview" => "Všechny články",
|
||||||
|
];
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user