FEATURE: move widget and template dir installation into middleware, optimize middleware groups
This commit is contained in:
@@ -28,6 +28,10 @@ class TemplateRegistrator
|
|||||||
* @var int ID of module
|
* @var int ID of module
|
||||||
*/
|
*/
|
||||||
protected $moduleId;
|
protected $moduleId;
|
||||||
|
/**
|
||||||
|
* @var array list of all registered template paths
|
||||||
|
*/
|
||||||
|
protected $paths = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set base path
|
* Set base path
|
||||||
@@ -80,24 +84,39 @@ class TemplateRegistrator
|
|||||||
* Registers new template path.
|
* Registers new template path.
|
||||||
* This method registeres given path itself with all subdirectories
|
* This method registeres given path itself with all subdirectories
|
||||||
*
|
*
|
||||||
|
* @param $baseDirectory
|
||||||
* @param string $path path relatively to root of the project
|
* @param string $path path relatively to root of the project
|
||||||
* @param string $name human readable identification of given template path
|
* @param string $name human readable identification of given template path
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function register($path, $name)
|
public function register($baseDirectory, $path, $name)
|
||||||
{
|
{
|
||||||
// check if base directory was set
|
$this->paths[] = [
|
||||||
if (!$this->baseDirectory || !is_dir($this->baseDirectory)) {
|
'namespace' => $this->namespace,
|
||||||
throw new \Exception('Set $baseDirectory before registering template path.');
|
'moduleId' => $this->moduleId,
|
||||||
|
'baseDirectory' => $baseDirectory,
|
||||||
|
'path' => $this->baseDirectory . DIRECTORY_SEPARATOR . $path,
|
||||||
|
'name' => $name
|
||||||
|
];
|
||||||
|
$this->unsetNamespace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveTemplates()
|
||||||
|
{
|
||||||
|
if (!is_array($this->paths) || empty($this->paths)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->registeredPath = $this->baseDirectory . DIRECTORY_SEPARATOR . $path;
|
foreach ($this->paths as $path) {
|
||||||
|
$this->setNamespace($path['namespace']);
|
||||||
|
$this->setModuleId($path['moduleId']);
|
||||||
|
$this->setBaseDirectory($path['baseDirectory']);
|
||||||
|
|
||||||
// register path
|
$this->registeredPath = $this->baseDirectory . DIRECTORY_SEPARATOR . $path['path'];
|
||||||
$this->registerPath($this->registeredPath, $name);
|
// register path
|
||||||
|
$this->registerPath($this->registeredPath, $path['name']);
|
||||||
$this->unsetNamespace();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,7 +165,7 @@ class TemplateRegistrator
|
|||||||
Template::ASSETS_DIRECTORY,
|
Template::ASSETS_DIRECTORY,
|
||||||
Template::MODULES_DIRECTORY
|
Template::MODULES_DIRECTORY
|
||||||
];
|
];
|
||||||
|
|
||||||
if (in_array($dirName, $ignoredDirectories)) {
|
if (in_array($dirName, $ignoredDirectories)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,11 @@ namespace App\Handlers\Registrators;
|
|||||||
|
|
||||||
use App\Enumerations\WidgetTypesWithHandlers;
|
use App\Enumerations\WidgetTypesWithHandlers;
|
||||||
use App\Models\WidgetType;
|
use App\Models\WidgetType;
|
||||||
use App\Widgets\Contracts\PublicWidget;
|
|
||||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
|
||||||
|
|
||||||
class WidgetRegistrator
|
class WidgetRegistrator
|
||||||
{
|
{
|
||||||
protected $widgets;
|
protected $registeredWidgets = [];
|
||||||
|
|
||||||
function __construct()
|
|
||||||
{
|
|
||||||
$this->widgets = WidgetTypesWithHandlers::getSimple();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method used for registering new widgets
|
* Method used for registering new widgets
|
||||||
@@ -24,27 +18,41 @@ class WidgetRegistrator
|
|||||||
*/
|
*/
|
||||||
public function register($classname, $templateId = null, $moduleId = null)
|
public function register($classname, $templateId = null, $moduleId = null)
|
||||||
{
|
{
|
||||||
$class = new $classname;
|
$this->registeredWidgets[] = [
|
||||||
if (!$class instanceof PublicWidget) {
|
'class' => $classname,
|
||||||
throw new InvalidArgumentException($class . ' must implement PublicWidget interface.');
|
'templateId' => $templateId,
|
||||||
}
|
'moduleId' => $moduleId
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
// register widget as new widget type
|
/**
|
||||||
if (!in_array($classname, $this->widgets)) {
|
* Install all non-installed widgets
|
||||||
$widgetName = call_user_func($classname . '::getName');
|
*/
|
||||||
$widgetDescription = call_user_func($classname . '::getDescription');
|
public function installWidgets()
|
||||||
|
{
|
||||||
|
$installed = WidgetTypesWithHandlers::getSimple();
|
||||||
|
foreach ($this->registeredWidgets as $registeredWidget) {
|
||||||
|
$classname = $registeredWidget['class'];
|
||||||
|
$templateId = $registeredWidget['templateId'];
|
||||||
|
$moduleId = $registeredWidget['moduleId'];
|
||||||
|
|
||||||
// create row in widget types
|
// register widget as new widget type
|
||||||
WidgetType::create([
|
if (!in_array($classname, $installed)) {
|
||||||
'handler' => $classname,
|
$widgetName = call_user_func($classname . '::getName');
|
||||||
'name' => $widgetName,
|
$widgetDescription = call_user_func($classname . '::getDescription');
|
||||||
'module_id' => $moduleId,
|
|
||||||
'template_id' => $templateId,
|
|
||||||
'description' => $widgetDescription
|
|
||||||
]);
|
|
||||||
|
|
||||||
// install widget (if neccessary)
|
// create row in widget types
|
||||||
call_user_func($classname . '::install');
|
WidgetType::create([
|
||||||
|
'handler' => $classname,
|
||||||
|
'name' => $widgetName,
|
||||||
|
'module_id' => $moduleId,
|
||||||
|
'template_id' => $templateId,
|
||||||
|
'description' => $widgetDescription
|
||||||
|
]);
|
||||||
|
|
||||||
|
// install widget (if neccessary)
|
||||||
|
call_user_func($classname . '::install');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Helpers;
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
|
|
||||||
class CurrentTemplate
|
class CurrentTemplate
|
||||||
@@ -20,6 +19,12 @@ class CurrentTemplate
|
|||||||
self::$template = Module::where('is_template', true)
|
self::$template = Module::where('is_template', true)
|
||||||
->where('enabled', true)
|
->where('enabled', true)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
if (self::$template) {
|
||||||
|
self::$template->module_settings = json_decode(self::$template->module_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$template;
|
return self::$template;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class Settings
|
|||||||
|
|
||||||
if (isset(self::$settings->$key)) {
|
if (isset(self::$settings->$key)) {
|
||||||
$exists = true;
|
$exists = true;
|
||||||
|
self::$initialized = true;
|
||||||
return self::$settings->$key;
|
return self::$settings->$key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-8
@@ -2,8 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Http;
|
namespace App\Http;
|
||||||
|
|
||||||
|
use App\Http\Middleware\TemplatePathInstaller;
|
||||||
|
use App\Http\Middleware\WidgetInstaller;
|
||||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||||
|
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
use Illuminate\Session\Middleware\StartSession;
|
||||||
|
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||||
use Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter;
|
use Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter;
|
||||||
use Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes;
|
use Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes;
|
||||||
use Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect;
|
use Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect;
|
||||||
@@ -18,7 +23,10 @@ class Kernel extends HttpKernel
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $middleware = [
|
protected $middleware = [
|
||||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
Middleware\EncryptCookies::class,
|
||||||
|
StartSession::class,
|
||||||
|
ShareErrorsFromSession::class,
|
||||||
|
Middleware\VerifyCsrfToken::class
|
||||||
];
|
];
|
||||||
/**
|
/**
|
||||||
* The application's route middleware groups.
|
* The application's route middleware groups.
|
||||||
@@ -26,14 +34,16 @@ class Kernel extends HttpKernel
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $middlewareGroups = [
|
protected $middlewareGroups = [
|
||||||
'web' => [
|
'web' => [
|
||||||
Middleware\EncryptCookies::class,
|
CheckForMaintenanceMode::class,
|
||||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
|
||||||
\Illuminate\Session\Middleware\StartSession::class,
|
|
||||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
|
||||||
Middleware\VerifyCsrfToken::class,
|
|
||||||
],
|
],
|
||||||
'api' => [
|
'admin' => [
|
||||||
|
Middleware\Authenticate::class,
|
||||||
|
Middleware\AdminMenuRegistrator::class,
|
||||||
|
TemplatePathInstaller::class,
|
||||||
|
WidgetInstaller::class,
|
||||||
|
],
|
||||||
|
'api' => [
|
||||||
'throttle:60,1',
|
'throttle:60,1',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Handlers\Registrators\TemplateRegistrator;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
|
class TemplatePathInstaller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var $registator TemplateRegistrator
|
||||||
|
*/
|
||||||
|
$registator = App::make('registerTemplateDir');
|
||||||
|
|
||||||
|
// install registered widgets
|
||||||
|
$registator->saveTemplates();
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Handlers\Registrators\WidgetRegistrator;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
|
class WidgetInstaller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var $registator WidgetRegistrator
|
||||||
|
*/
|
||||||
|
$registator = App::make('registerWidget');
|
||||||
|
|
||||||
|
// install registered widgets
|
||||||
|
$registator->installWidgets();
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -19,7 +19,7 @@ Route::group([
|
|||||||
* This route group serves to handle request in admin
|
* This route group serves to handle request in admin
|
||||||
*/
|
*/
|
||||||
Route::group([
|
Route::group([
|
||||||
'middleware' => ['web', 'auth', 'adminMenu'],
|
'middleware' => ['admin'],
|
||||||
'namespace' => 'Admin',
|
'namespace' => 'Admin',
|
||||||
'prefix' => 'admin'
|
'prefix' => 'admin'
|
||||||
], function () {
|
], function () {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use App\Widgets\HtmlCode\HtmlCode;
|
|||||||
use App\Widgets\Menu\Menu;
|
use App\Widgets\Menu\Menu;
|
||||||
use App\Widgets\OrbitSlider\OrbitSlider;
|
use App\Widgets\OrbitSlider\OrbitSlider;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||||
@@ -34,7 +35,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->registerWidgets();
|
$this->registerWidgets();
|
||||||
$this->registerTemplates();
|
|
||||||
$this->registerSettings();
|
$this->registerSettings();
|
||||||
$this->registerSearch();
|
$this->registerSearch();
|
||||||
}
|
}
|
||||||
@@ -97,24 +97,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$registrator->register(HtmlCode::class);
|
$registrator->register(HtmlCode::class);
|
||||||
$registrator->register(Menu::class);
|
$registrator->register(Menu::class);
|
||||||
$registrator->register(OrbitSlider::class);
|
$registrator->register(OrbitSlider::class);
|
||||||
|
|
||||||
// register some menu extensions
|
|
||||||
// $menuExtensions = $this->app->make('registerMenuExtension');
|
|
||||||
// $menuExtensions->register(new URL());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register path with editable contents
|
|
||||||
*/
|
|
||||||
private function registerTemplates()
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var $registrator TemplateRegistrator
|
|
||||||
*/
|
|
||||||
// $registrator = $this->app->make('registerTemplateDir');
|
|
||||||
// $registrator->setBaseDirectory('resources/views/visitor');
|
|
||||||
|
|
||||||
// $registrator->register(config('app.theme'), 'admin/templates.core');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,32 +3,13 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Handlers\Registrators\TemplateRegistrator;
|
use App\Handlers\Registrators\TemplateRegistrator;
|
||||||
use App\Models\Module;
|
use App\Helpers\CurrentTemplate;
|
||||||
use App\Models\Template;
|
use App\Models\Template;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use InvalidArgumentException;
|
|
||||||
|
|
||||||
class TemplateServiceProvider extends ServiceProvider
|
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()
|
public function boot()
|
||||||
{
|
{
|
||||||
// ignore running from artisan
|
// ignore running from artisan
|
||||||
@@ -38,28 +19,24 @@ class TemplateServiceProvider extends ServiceProvider
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$template = $this->getTemplate();
|
$template = CurrentTemplate::get();
|
||||||
|
|
||||||
if (!$template) {
|
if (!$template) {
|
||||||
throw new \ErrorException('Template is not set, cannot continue');
|
throw new \ErrorException('Template is not set, cannot continue');
|
||||||
}
|
}
|
||||||
|
|
||||||
// include files
|
// include files
|
||||||
$files = isset($template->settings->files) ? $template->settings->files : [];
|
$files = isset($template->module_settings->files) ? $template->module_settings->files : [];
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
include_once $file;
|
include_once $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
// register templates
|
// register templates
|
||||||
$publicTemplates = call_user_func([$template->handler, 'getPublicTemplatePaths']);
|
$publicTemplates = call_user_func([CurrentTemplate::handler(), 'getPublicTemplatePaths']);
|
||||||
|
|
||||||
if (!is_array($publicTemplates)) {
|
if (!is_array($publicTemplates)) {
|
||||||
throw new \ErrorException($template->handler . '::getPublicTemplatePaths() must return array!');
|
throw new \ErrorException(CurrentTemplate::handler() . '::getPublicTemplatePaths() must return array!');
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($publicTemplates)) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,16 +47,12 @@ class TemplateServiceProvider extends ServiceProvider
|
|||||||
// setup some global variables
|
// setup some global variables
|
||||||
$module = strtolower($template['module']);
|
$module = strtolower($template['module']);
|
||||||
$namespace = isset($template['namespace']) ? $template['namespace'] : 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
|
// register path with current template name
|
||||||
$registrator->register('visitor', $template['templateName']);
|
|
||||||
} catch (InvalidArgumentException $e) {
|
$registrator->setNamespace($namespace);
|
||||||
// ignore this exception
|
$registrator->setModuleId(call_user_func([config($module . '.handler'), 'getModuleId']));
|
||||||
}
|
$registrator->register('resources/views/modules/' . $module, 'visitor', $template['templateName']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,12 +70,12 @@ class TemplateServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
private function publishViewResources()
|
private function publishViewResources()
|
||||||
{
|
{
|
||||||
$template = $this->getTemplate();
|
$template = CurrentTemplate::get();
|
||||||
if (!$template) {
|
if (!$template) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$templateDir = app_path('../templates/' . $template->settings->staticName . '/Resources');
|
$templateDir = base_path('templates/' . $template->module_settings->staticName . '/Resources');
|
||||||
$assetsDir = $templateDir . '/' . Template::ASSETS_DIRECTORY;
|
$assetsDir = $templateDir . '/' . Template::ASSETS_DIRECTORY;
|
||||||
$viewsDir = $templateDir . '/views';
|
$viewsDir = $templateDir . '/views';
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
<?php namespace Modules\Staticpages\Providers;
|
<?php namespace Modules\Staticpages\Providers;
|
||||||
|
|
||||||
use App\Enumerations\ModulesHandlerToId;
|
|
||||||
use App\Enumerations\ModulesWithIds;
|
|
||||||
use App\Handlers\Registrators\TemplateRegistrator;
|
|
||||||
use App\Models\ActionLogType;
|
|
||||||
use App\Models\Module;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
|
||||||
|
|
||||||
class StaticPagesServiceProvider extends ServiceProvider
|
class StaticPagesServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -45,7 +39,7 @@ class StaticPagesServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
protected function registerConfig()
|
protected function registerConfig()
|
||||||
{
|
{
|
||||||
$config = __DIR__ . DIRECTORY_SEPARATOR .'../Config/config.php';
|
$config = __DIR__ . DIRECTORY_SEPARATOR . '../Config/config.php';
|
||||||
$this->publishes([$config => config_path('staticpages.php')]);
|
$this->publishes([$config => config_path('staticpages.php')]);
|
||||||
$this->mergeConfigFrom($config, 'staticpages');
|
$this->mergeConfigFrom($config, 'staticpages');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ abstract class OnePage implements TemplateHandler
|
|||||||
* Name of settings key for list of pages used on homepage
|
* Name of settings key for list of pages used on homepage
|
||||||
*/
|
*/
|
||||||
const HOMEPAGE_PAGES_SETTINGS_KEY = 'template.onepage.homepagePages';
|
const HOMEPAGE_PAGES_SETTINGS_KEY = 'template.onepage.homepagePages';
|
||||||
|
protected static $homepagePagesInitialized = false;
|
||||||
|
protected static $homepagePages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register admin menu (or multiple ones)
|
* Register admin menu (or multiple ones)
|
||||||
@@ -40,22 +42,28 @@ abstract class OnePage implements TemplateHandler
|
|||||||
*/
|
*/
|
||||||
public static function getPagesOnHomepage()
|
public static function getPagesOnHomepage()
|
||||||
{
|
{
|
||||||
$pageIds = (array)json_decode(Settings::get(self::HOMEPAGE_PAGES_SETTINGS_KEY, '[]'));
|
if (!self::$homepagePagesInitialized) {
|
||||||
|
$pageIds = (array)json_decode(Settings::get(self::HOMEPAGE_PAGES_SETTINGS_KEY, '[]'));
|
||||||
|
|
||||||
if (empty($pageIds)) {
|
if (empty($pageIds)) {
|
||||||
return [];
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// get all available pages
|
||||||
|
$pages = Content::whereIn('id', $pageIds);
|
||||||
|
|
||||||
|
if (Auth::user()) {
|
||||||
|
$pages = $pages->where('status', '!=', Content::STATUS_DRAFT);
|
||||||
|
} else {
|
||||||
|
$pages = $pages->where('status', Content::STATUS_PUBLIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
self:: $homepagePages = $pages->get();
|
||||||
|
|
||||||
|
self::$homepagePagesInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all available pages
|
return self::$homepagePages;
|
||||||
$pages = Content::whereIn('id', $pageIds);
|
|
||||||
|
|
||||||
if (Auth::user()) {
|
|
||||||
$pages = $pages->where('status', '!=', Content::STATUS_DRAFT);
|
|
||||||
} else {
|
|
||||||
$pages = $pages->where('status', Content::STATUS_PUBLIC);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $pages->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user