Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b3f9f1717 | ||
|
|
6037f88260 | ||
|
|
3df68ad5cd | ||
|
|
b06f884b4a | ||
|
|
53894d4657 | ||
|
|
91683a48e2 | ||
|
|
66f0873bc8 | ||
|
|
c17ddd48f8 |
+6
-5
@@ -1,8 +1,8 @@
|
|||||||
APP_KEY=
|
APP_ENV=testing
|
||||||
APP_ENV=
|
APP_DEBUG=true
|
||||||
APP_DEBUG=
|
APP_KEY=ZKZAzM23wQ6BPji6zffBjaTzZ3yW7zKQ
|
||||||
|
|
||||||
DB_HOST=
|
DB_HOST=localhost
|
||||||
DB_DATABASE=
|
DB_DATABASE=
|
||||||
DB_USERNAME=
|
DB_USERNAME=
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
@@ -16,4 +16,5 @@ MAIL_PASSWORD=
|
|||||||
|
|
||||||
SITE_URL=/
|
SITE_URL=/
|
||||||
UPLOAD_URL=/public/uploads
|
UPLOAD_URL=/public/uploads
|
||||||
THUMBNAIL_URL=/public/uploads/thumbnails
|
THUMBNAILS_URL=/uploads/thumbnails
|
||||||
|
THEME=
|
||||||
+2
-9
@@ -1,9 +1,8 @@
|
|||||||
# published files from modules
|
# published files from modules
|
||||||
/public/modules
|
|
||||||
/public/assets
|
|
||||||
/resources/views/modules
|
/resources/views/modules
|
||||||
/resources/views/visitor
|
/public/modules
|
||||||
/resources/views/vendor
|
/resources/views/vendor
|
||||||
|
/public/assets
|
||||||
|
|
||||||
# directories with custom templates
|
# directories with custom templates
|
||||||
**/views/**/custom/*
|
**/views/**/custom/*
|
||||||
@@ -27,9 +26,3 @@
|
|||||||
|
|
||||||
# meta information created by installer
|
# meta information created by installer
|
||||||
.install
|
.install
|
||||||
/node_modules/
|
|
||||||
/public/css/
|
|
||||||
/public/js
|
|
||||||
/public/fonts
|
|
||||||
/bower_components
|
|
||||||
.sass-cache
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Content;
|
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
interface AdvancedContentModifier {
|
|
||||||
/**
|
|
||||||
* Method called right after content page is marked as deleted
|
|
||||||
*
|
|
||||||
* This method is supposed to clean after "deleted" page.
|
|
||||||
*
|
|
||||||
* @param Content $content
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function delete(Content $content);
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Content;
|
|
||||||
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface ContentTitles
|
|
||||||
*
|
|
||||||
* Classes which implement this interface get the ability to rewrite default text on edit/create/overview of content
|
|
||||||
* page.
|
|
||||||
*
|
|
||||||
* @package App\CMS\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);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Content\DisplayPipeline;
|
|
||||||
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
interface Pipeline {
|
|
||||||
/**
|
|
||||||
* Add new process into pipeline
|
|
||||||
*
|
|
||||||
* @param string $process
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function add($process);
|
|
||||||
function run(Content $page);
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Content\DisplayPipeline;
|
|
||||||
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
interface Process {
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function handle(Content & $page);
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Content\SavePipeline;
|
|
||||||
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
interface Pipeline {
|
|
||||||
/**
|
|
||||||
* Add new process into pipeline
|
|
||||||
*
|
|
||||||
* @param string $process
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function add($process);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save content page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param array $input
|
|
||||||
*
|
|
||||||
* @return Content
|
|
||||||
*/
|
|
||||||
function run(Content & $page, array $input);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Content\SavePipeline;
|
|
||||||
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
interface Process {
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param array $input
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function handle(Content & $page, array & $input);
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts;
|
|
||||||
|
|
||||||
interface Interaction {
|
|
||||||
/**
|
|
||||||
* Perform given action
|
|
||||||
*
|
|
||||||
* @param $data array input data
|
|
||||||
* @param $parameters array parameters
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle($data, $parameters);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $data array input data
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getValidationRules($data = []);
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Modules;
|
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
interface AppHandler extends BaseModuleHandler
|
|
||||||
{
|
|
||||||
public static function getHistoryHandler();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for section names in creating/editing content resource
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getExtendedFormSections();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for views used in extended part of form for creating new content
|
|
||||||
*
|
|
||||||
* This method should return pairs <section, view-name>. View is returned only as name in plain text
|
|
||||||
*
|
|
||||||
* @return array of views/templates/html codes divided into section
|
|
||||||
*/
|
|
||||||
public static function getExtendedFormInputsCreate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for extended part of form for editing existing content
|
|
||||||
*
|
|
||||||
* Basically, this method may be
|
|
||||||
*
|
|
||||||
* @return array of views/templates/html codes divided into section
|
|
||||||
*/
|
|
||||||
public static function getExtendedFormInputsEdit();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does this module support categories?
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public static function supportCategories();
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Modules;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
|
|
||||||
interface BaseModuleHandler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Register admin menu (or multiple ones)
|
|
||||||
*
|
|
||||||
* This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before
|
|
||||||
* starting any middleware..
|
|
||||||
*
|
|
||||||
* @param User $user model of logged user
|
|
||||||
*/
|
|
||||||
public static function registerAdminMenu(User $user);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Modules;
|
|
||||||
|
|
||||||
use App\Models\Module;
|
|
||||||
|
|
||||||
interface InstallableModule {
|
|
||||||
/**
|
|
||||||
* Install module.
|
|
||||||
*
|
|
||||||
* This method is called after inserting info about module into database. It can be called only using Artisan in
|
|
||||||
* CLI.
|
|
||||||
*/
|
|
||||||
public static function install();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uninstalls module
|
|
||||||
*
|
|
||||||
* @param Module $module
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function uninstall(Module $module);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Modules;
|
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface TemplateHandler
|
|
||||||
*
|
|
||||||
* Inerface used for registering template into CMS core.
|
|
||||||
*
|
|
||||||
* @package App\CMS\Handlers\Contracts
|
|
||||||
*/
|
|
||||||
interface TemplateHandler extends BaseModuleHandler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Repositories;
|
|
||||||
|
|
||||||
interface BaseRepository {
|
|
||||||
public function getOne($id = null);
|
|
||||||
public function all();
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Repositories;
|
|
||||||
|
|
||||||
interface Content extends BaseRepository
|
|
||||||
{
|
|
||||||
const STATUS_DRAFT = 'draft';
|
|
||||||
const STATUS_PROTECTED = 'protected';
|
|
||||||
const STATUS_PUBLIC = 'public';
|
|
||||||
|
|
||||||
public function getOverview($handler = null, $statuses = null);
|
|
||||||
|
|
||||||
public function getHomepage();
|
|
||||||
|
|
||||||
public function getByURL($url);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Repositories;
|
|
||||||
|
|
||||||
use App\Models\Content\Content as ContentModel;
|
|
||||||
use App\Models\Module as ModuleModel;
|
|
||||||
|
|
||||||
interface Module extends BaseRepository
|
|
||||||
{
|
|
||||||
public function getCreateContentTitle(ModuleModel $module);
|
|
||||||
|
|
||||||
public function getUpdateContentTitle(ModuleModel $module, ContentModel $content = null);
|
|
||||||
|
|
||||||
public function getOverviewTitle(ModuleModel $module);
|
|
||||||
|
|
||||||
public function getByHandler($handler);
|
|
||||||
|
|
||||||
public function call(ModuleModel $module, $method, $parameters = []);
|
|
||||||
|
|
||||||
public function callOnString($moduleHandler, $method, $parameters = []);
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Repositories;
|
|
||||||
|
|
||||||
use App\Models\Module as ModuleModel;
|
|
||||||
use App\Models\Templates\Template as TemplateModel;
|
|
||||||
|
|
||||||
interface Template
|
|
||||||
{
|
|
||||||
const EDITED_TEMPLATES_DIRECTORY = 'custom';
|
|
||||||
const ASSETS_DIRECTORY = 'assets';
|
|
||||||
const MODULES_DIRECTORY = 'modules';
|
|
||||||
const TEMPLATE_SUFFIX = '.blade.php';
|
|
||||||
const CUSTOM_EDIT_DIRECTORY = 1;
|
|
||||||
const ORIGINAL_DIRECTORY = 2;
|
|
||||||
|
|
||||||
public function setModel(TemplateModel $model);
|
|
||||||
|
|
||||||
public function getPathToTemplate($mode = null);
|
|
||||||
|
|
||||||
public function getForModule(ModuleModel $module);
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Contracts\Widgets;
|
|
||||||
|
|
||||||
interface InstallableWidget extends PublicWidget {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function for installing given widget
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function install();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function for uninstalling widget
|
|
||||||
*/
|
|
||||||
public static function uninstall();
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Exceptions\FileManager;
|
|
||||||
|
|
||||||
class SubdirectoryExistsInDirectory extends \Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Exceptions\Validation;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class ValidationFailedException extends \Exception {
|
|
||||||
protected $validator;
|
|
||||||
|
|
||||||
public function __construct($validator, $message = null, $code = null, Exception $previous = null)
|
|
||||||
{
|
|
||||||
parent::__construct($message, $code, $previous);
|
|
||||||
|
|
||||||
$this->validator = $validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getValidator(){
|
|
||||||
return $this->validator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Handlers;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Modules\BaseModuleHandler;
|
|
||||||
use App\CMS\Enumerations\TemplatePathsHumanReadableRootOnly;
|
|
||||||
use App\CMS\Enumerations\WidgetTypes;
|
|
||||||
use App\Models\User;
|
|
||||||
|
|
||||||
abstract class BaseHandler implements BaseModuleHandler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Register admin menu (or multiple ones)
|
|
||||||
*
|
|
||||||
* This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before
|
|
||||||
* starting any middleware..
|
|
||||||
*
|
|
||||||
* @param User $user model of logged user
|
|
||||||
*/
|
|
||||||
public static function registerAdminMenu(User $user)
|
|
||||||
{
|
|
||||||
$menu = \Menu::instance('mainMenu');
|
|
||||||
if (!is_null($menu)) {
|
|
||||||
// menus were already defined
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create instance of main menu
|
|
||||||
\Menu::create('mainMenu', function ($menu) {
|
|
||||||
// $menu->route('admin.dashboard', trans('admin/mainMenu.dashboard'), [], 10, ['icon' => 'fa fa-fw fa-dashboard']);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Content pages
|
|
||||||
*
|
|
||||||
* Submenus can be registered later
|
|
||||||
*/
|
|
||||||
$menu->dropdown(trans('admin/mainMenu.contentPages'), function ($sub) {
|
|
||||||
$sub->route('content.overview', trans('admin/mainMenu.contentPageOverview'), [], 10000, ['icon' => 'fa fa-fw fa-list']);
|
|
||||||
}, 20, ['icon' => 'fa fa-fw fa-database']);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File manager
|
|
||||||
*/
|
|
||||||
$menu->route('upload.overview', trans('admin/mainMenu.fileManager'), [], 40, ['icon' => 'fa fa-fw fa-folder']);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Widgets and widget areas
|
|
||||||
*/
|
|
||||||
$menu->dropdown(trans('admin/mainMenu.widgets'), function ($sub) {
|
|
||||||
// create list of all widget types
|
|
||||||
$widgets = WidgetTypes::getWithTranslations();
|
|
||||||
|
|
||||||
if (!empty($widgets)) {
|
|
||||||
$sub->dropdown(trans('admin/mainMenu.newWidget'), function ($sub) use ($widgets) {
|
|
||||||
$i = 1;
|
|
||||||
foreach ($widgets as $type => $name) {
|
|
||||||
$sub->route('widgets.new', $name, ['type' => $type], $i++);
|
|
||||||
}
|
|
||||||
}, 10, ['icon' => 'fa fa-fw fa-plus']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sub->route('widgets.overview', trans('admin/mainMenu.widgetsOverview'), [], 20, ['icon' => 'fa fa-fw fa-list']);
|
|
||||||
|
|
||||||
// menu for widget areas
|
|
||||||
$sub->dropdown(trans('admin/mainMenu.widgetAreas'), function ($sub) {
|
|
||||||
$sub->route('widgetareas.new', trans('admin/mainMenu.newWidgetArea'), [], 1, ['icon' => 'fa fa-fw fa-plus']);
|
|
||||||
$sub->route('widgetareas.overview', trans('admin/mainMenu.widgetAreaOverview'), [], 2, ['icon' => 'fa fa-fw fa-list']);
|
|
||||||
}, 50, ['icon' => 'fa fa-fw fa-object-group']);
|
|
||||||
}, 50, ['icon' => 'fa fa-fw fa-puzzle-piece']);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Divide system entries and other links in menu
|
|
||||||
*/
|
|
||||||
$menu->addDivider(9999);
|
|
||||||
|
|
||||||
$menu->dropdown(trans('admin/mainMenu.system'), function ($sub) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User management
|
|
||||||
*/
|
|
||||||
$sub->dropdown(trans('admin/mainMenu.userManagement'), function ($sub) {
|
|
||||||
$sub->route('users.new', trans('admin/mainMenu.newUser'), [], 10, ['icon' => 'fa fa-fw fa-user-plus']);
|
|
||||||
$sub->route('users.overview', trans('admin/mainMenu.usersOverview'), [], 30, ['icon' => 'fa fa-fw fa-users']);
|
|
||||||
}, 20, ['icon' => 'fa fa-fw fa-users']);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Templates
|
|
||||||
*/
|
|
||||||
$templatePaths = TemplatePathsHumanReadableRootOnly::getWithTranslations();
|
|
||||||
if (!empty($templatePaths)) {
|
|
||||||
$sub->dropdown(trans('admin/mainMenu.templates'), function ($sub) use ($templatePaths) {
|
|
||||||
$i = 1;
|
|
||||||
foreach ($templatePaths as $id => $name) {
|
|
||||||
$sub->route('templates.overview', $name, ['id' => $id], $i++);
|
|
||||||
}
|
|
||||||
}, 60, ['icon' => 'fa fa-fw fa-file-code-o']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sub->route('log.overview', trans('admin/mainMenu.actionLog'), [], 70, ['icon' => 'fa fa-fw fa-history']);
|
|
||||||
$sub->route('settings.overview', trans('admin/mainMenu.settings'), [], 80, ['icon' => 'fa fa-fw fa-gear']);
|
|
||||||
}, 10000, ['icon' => 'fa fa-fw fa-gears']);
|
|
||||||
});
|
|
||||||
|
|
||||||
// create menu with user profile
|
|
||||||
\Menu::create('profileMenu', function ($menu) {
|
|
||||||
$menu->route('users.detail', trans('admin/userManagement.profile'), [], 10, ['icon' => 'fa fa-fw fa-user icon']);
|
|
||||||
$menu->addDivider(999);
|
|
||||||
$menu->route('logout', trans('admin/common.logout'), [], 1000, ['icon' => 'fa fa-fw fa-power-off icon']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Handlers;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Modules\AppHandler;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Handler
|
|
||||||
*
|
|
||||||
* Handler is a class which handles module-specific behaviour which cannot be done by module itself, resp. cannot be
|
|
||||||
* done by some abstract magic.
|
|
||||||
*
|
|
||||||
* @package App\CMS\Handlers\
|
|
||||||
*/
|
|
||||||
abstract class Handler extends BaseHandler implements AppHandler
|
|
||||||
{
|
|
||||||
public static function getHistoryHandler()
|
|
||||||
{
|
|
||||||
return History::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getExtendedFormSections()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'basicInfo' => trans('admin/contents.basicInfo'),
|
|
||||||
'meta' => trans('admin/contents.metaOptions'),
|
|
||||||
'publication' => trans('admin/contents.publicationOptions'),
|
|
||||||
'appearance' => trans('admin/contents.appearance'),
|
|
||||||
'files' => trans('admin/contents.files')
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getExtendedFormInputsCreate()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'basicInfo' => 'admin.content.formParts.basicInformation',
|
|
||||||
'meta' => 'admin.content.formParts.metaInformation',
|
|
||||||
'publication' => 'admin.content.formParts.publicationSetup',
|
|
||||||
'appearance' => 'admin.content.formParts.appearance',
|
|
||||||
'files' => 'admin.content.formParts.files'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getExtendedFormInputsEdit()
|
|
||||||
{
|
|
||||||
return self::getExtendedFormInputsCreate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Cms\Handlers\Interactions;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Interaction as InteractionContract;
|
|
||||||
use App\CMS\Exceptions\Validation\ValidationFailedException;
|
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
|
|
||||||
class Interaction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle interaction with application
|
|
||||||
*
|
|
||||||
* @param string $interactionClass
|
|
||||||
* @param array $data
|
|
||||||
* @param array $extraParameters
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
* @throws ValidationFailedException
|
|
||||||
*/
|
|
||||||
public static function handle($interactionClass, $data, ...$extraParameters)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var $interaction InteractionContract
|
|
||||||
*/
|
|
||||||
|
|
||||||
$interaction = app($interactionClass);
|
|
||||||
// validate interaction
|
|
||||||
$validator = Validator::make($data, $interaction->getValidationRules($extraParameters));
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
|
||||||
throw new ValidationFailedException($validator);
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle it
|
|
||||||
|
|
||||||
return $interaction->handle($data, $extraParameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Handlers\Registrators;
|
|
||||||
|
|
||||||
use App\CMS\Enumerations\WidgetTypesWithHandlers;
|
|
||||||
use App\Models\Widgets\WidgetType;
|
|
||||||
|
|
||||||
class WidgetRegistrator
|
|
||||||
{
|
|
||||||
protected $registeredWidgets = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method used for registering new widgets
|
|
||||||
*
|
|
||||||
* @param $classname
|
|
||||||
* @param null $templateId
|
|
||||||
* @param null $moduleId
|
|
||||||
*/
|
|
||||||
public function register($classname, $templateId = null, $moduleId = null)
|
|
||||||
{
|
|
||||||
$this->registeredWidgets[] = [
|
|
||||||
'class' => $classname,
|
|
||||||
'templateId' => $templateId,
|
|
||||||
'moduleId' => $moduleId
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Install all non-installed widgets
|
|
||||||
*/
|
|
||||||
public function installWidgets()
|
|
||||||
{
|
|
||||||
$installed = WidgetTypesWithHandlers::getSimple();
|
|
||||||
foreach ($this->registeredWidgets as $registeredWidget) {
|
|
||||||
$classname = $registeredWidget['class'];
|
|
||||||
$templateId = $registeredWidget['templateId'];
|
|
||||||
$moduleId = $registeredWidget['moduleId'];
|
|
||||||
|
|
||||||
// register widget as new widget type
|
|
||||||
if (!in_array($classname, $installed)) {
|
|
||||||
$widgetName = call_user_func($classname . '::getName');
|
|
||||||
$widgetDescription = call_user_func($classname . '::getDescription');
|
|
||||||
|
|
||||||
// create row in widget types
|
|
||||||
WidgetType::create([
|
|
||||||
'handler' => $classname,
|
|
||||||
'name' => $widgetName,
|
|
||||||
'module_id' => $moduleId,
|
|
||||||
'template_id' => $templateId,
|
|
||||||
'description' => $widgetDescription
|
|
||||||
]);
|
|
||||||
|
|
||||||
// install widget (if neccessary)
|
|
||||||
if (is_callable([$classname, 'install'])) {
|
|
||||||
call_user_func($classname . '::install');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Handlers\Search\Presenters;
|
|
||||||
|
|
||||||
use App\CMS\Enumerations\ContentStatuses;
|
|
||||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
|
||||||
|
|
||||||
class AdminContent implements SearchPresenterHandler
|
|
||||||
{
|
|
||||||
public function render($foundItems)
|
|
||||||
{
|
|
||||||
return view('admin.search.results.content', [
|
|
||||||
'pages' => $foundItems,
|
|
||||||
'statuses' => ContentStatuses::getWithTranslations(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Modules\TemplateHandler;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\Module;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\QueryException;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
|
|
||||||
class CurrentTemplate implements TemplateHandler
|
|
||||||
{
|
|
||||||
protected static $template;
|
|
||||||
protected static $initialized = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for currently set template
|
|
||||||
* @return Module
|
|
||||||
* @throws \ErrorException
|
|
||||||
*/
|
|
||||||
public static function get()
|
|
||||||
{
|
|
||||||
if (!self::$initialized) {
|
|
||||||
self::$template = Cache::rememberForever('current-template', function () {
|
|
||||||
return Module::where('is_template', true)
|
|
||||||
->where('enabled', true)
|
|
||||||
->first();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
self::$initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset currently set template and load another one on next call of get() method.
|
|
||||||
*/
|
|
||||||
public static function reset()
|
|
||||||
{
|
|
||||||
self::$initialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register admin menu (or multiple ones)
|
|
||||||
*
|
|
||||||
* This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before
|
|
||||||
* starting any middleware..
|
|
||||||
*
|
|
||||||
* @param User $user model of logged user
|
|
||||||
*/
|
|
||||||
public static function registerAdminMenu(User $user)
|
|
||||||
{
|
|
||||||
call_user_func_array([self::handler(), 'registerAdminMenu'], [$user]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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()
|
|
||||||
{
|
|
||||||
return call_user_func([self::handler(), 'getPublicTemplatePaths']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
class Date
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Print date in configured format
|
|
||||||
*
|
|
||||||
* @param $datestamp
|
|
||||||
* @param bool $withTime
|
|
||||||
*
|
|
||||||
* @return false|string
|
|
||||||
*/
|
|
||||||
public static function date($datestamp, $withTime = true)
|
|
||||||
{
|
|
||||||
$timestamp = strtotime($datestamp);
|
|
||||||
|
|
||||||
if ($timestamp <= 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$format = $withTime ? config('app.datetime_format') : config('app.date_format');
|
|
||||||
|
|
||||||
return date($format, $timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function dateFormatted($format, $datestamp)
|
|
||||||
{
|
|
||||||
$timestamp = strtotime($datestamp);
|
|
||||||
|
|
||||||
if ($timestamp <= 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return date($format, $timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function monthName($datestamp) {
|
|
||||||
$timestamp = strtotime($datestamp);
|
|
||||||
|
|
||||||
if ($timestamp <= 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$months = [
|
|
||||||
trans('common.months.january'),
|
|
||||||
trans('common.months.february'),
|
|
||||||
trans('common.months.march'),
|
|
||||||
trans('common.months.april'),
|
|
||||||
trans('common.months.may'),
|
|
||||||
trans('common.months.june'),
|
|
||||||
trans('common.months.july'),
|
|
||||||
trans('common.months.august'),
|
|
||||||
trans('common.months.semptember'),
|
|
||||||
trans('common.months.october'),
|
|
||||||
trans('common.months.november'),
|
|
||||||
trans('common.months.december'),
|
|
||||||
];
|
|
||||||
|
|
||||||
$monthNumber = date('n', $timestamp);
|
|
||||||
|
|
||||||
return $months[$monthNumber - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
class Gravatar
|
|
||||||
{
|
|
||||||
public static function img($email, $size = 50)
|
|
||||||
{
|
|
||||||
return "//www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "?s=" . $size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
use App\CMS\Handlers\Contracts\AppHandler;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use Webwizo\Shortcodes\Facades\Shortcode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class PageRenderer
|
|
||||||
*
|
|
||||||
* Simple class for rendering page for visitor
|
|
||||||
*
|
|
||||||
* @package App\CMS\Helpers
|
|
||||||
*/
|
|
||||||
class PageRenderer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Render page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function render(Content $page)
|
|
||||||
{
|
|
||||||
// do something template-specific
|
|
||||||
$parameters = call_user_func_array([CurrentTemplate::handler(), 'beforeRender'], [&$page]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var $handler AppHandler
|
|
||||||
*/
|
|
||||||
$handler = new $page->moduleHandler;
|
|
||||||
|
|
||||||
// render page
|
|
||||||
return $handler->render($page, $parameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
use App\Models\FileManager\Directory;
|
|
||||||
use App\Models\FileManager\File;
|
|
||||||
|
|
||||||
class RootDirectory
|
|
||||||
{
|
|
||||||
protected static $directory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create root directory
|
|
||||||
*
|
|
||||||
* @return Directory
|
|
||||||
*/
|
|
||||||
protected static function create()
|
|
||||||
{
|
|
||||||
$directory = new Directory();
|
|
||||||
$directory->name = 'Root';
|
|
||||||
$directory->is_root = true;
|
|
||||||
$directory->save();
|
|
||||||
|
|
||||||
Directory::whereNull('parent_id')
|
|
||||||
->where('is_root', false)
|
|
||||||
->update(['parent_id' => $directory->id]);
|
|
||||||
|
|
||||||
File::where('directory_id', null)
|
|
||||||
->update(['directory_id' => $directory->id]);
|
|
||||||
|
|
||||||
return $directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get root directory
|
|
||||||
*
|
|
||||||
* @return Directory
|
|
||||||
*/
|
|
||||||
public static function get()
|
|
||||||
{
|
|
||||||
self::$directory = Directory::where('is_root', true)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if (is_null(self::$directory)) {
|
|
||||||
self::$directory = self::create();
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$directory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
use App\Models\Settings as SettingsModel;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Settings
|
|
||||||
*
|
|
||||||
* Helper class for easier obtaining system settings
|
|
||||||
*
|
|
||||||
* @package App\CMS\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;
|
|
||||||
self::$initialized = true;
|
|
||||||
return self::$settings->$key;
|
|
||||||
}
|
|
||||||
|
|
||||||
$exists = false;
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for obtaining settings saved as JSON
|
|
||||||
*
|
|
||||||
* @param $key
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getJson($key)
|
|
||||||
{
|
|
||||||
return json_decode(self::get($key, '{}'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all settings
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function all()
|
|
||||||
{
|
|
||||||
self::init();
|
|
||||||
|
|
||||||
return self::$settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize settings array
|
|
||||||
*/
|
|
||||||
private static function init()
|
|
||||||
{
|
|
||||||
if (!self::$initialized) {
|
|
||||||
self::$settings = Cache::remember('settings', config('cache.settingCacheLifetime'), function () {
|
|
||||||
$model = new SettingsModel();
|
|
||||||
return $model->getAll();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
||||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
|
||||||
|
|
||||||
class Template
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Getter for real template name
|
|
||||||
*
|
|
||||||
* @param $template
|
|
||||||
*
|
|
||||||
* @param bool $throwExceptions
|
|
||||||
*
|
|
||||||
* @return null|string
|
|
||||||
*/
|
|
||||||
public static function name($template, $throwExceptions = true)
|
|
||||||
{
|
|
||||||
$namespace = null;
|
|
||||||
if (strpos($template, '::')) {
|
|
||||||
list($namespace, $template) = explode('::', $template);
|
|
||||||
$namespace .= '::';
|
|
||||||
}
|
|
||||||
|
|
||||||
// list of prefixes
|
|
||||||
$prefixes = ['custom.', ''];
|
|
||||||
|
|
||||||
$view = null;
|
|
||||||
foreach ($prefixes as $prefix) {
|
|
||||||
if (view()->exists($namespace . 'visitor.' . $prefix . $template)) {
|
|
||||||
$view = $namespace . 'visitor.' . $prefix . $template;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($view)) {
|
|
||||||
if ($throwExceptions) {
|
|
||||||
throw new InvalidArgumentException('Cannot find template for ' . $namespace . $template);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $view;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Helpers\Traits;
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Nullable
|
|
||||||
*
|
|
||||||
* @package App\CMS\Helpers\Traits
|
|
||||||
*/
|
|
||||||
trait Nullable {
|
|
||||||
/**
|
|
||||||
* Get null or parsed date
|
|
||||||
*
|
|
||||||
* @param $date
|
|
||||||
*
|
|
||||||
* @return null|string
|
|
||||||
*/
|
|
||||||
public function nullableDate($date) {
|
|
||||||
return empty($date) ? null : Carbon::parse($date)->toDateTimeString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get null or input value
|
|
||||||
*
|
|
||||||
* @param $string
|
|
||||||
*
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function nullable($string) {
|
|
||||||
return empty($string) ? null : $string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
class Widget
|
|
||||||
{
|
|
||||||
public static function render(\App\Models\Widgets\Widget $widget)
|
|
||||||
{
|
|
||||||
$handler = $widget->widget_type_handler;
|
|
||||||
|
|
||||||
if (is_string($widget->settings)) {
|
|
||||||
$widget->settings = json_decode($widget->settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
$presenter = call_user_func([$handler, 'getPresenter']);
|
|
||||||
|
|
||||||
return call_user_func([$presenter, 'render'], $widget);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\Helpers;
|
|
||||||
|
|
||||||
use App\CMS\Repositories\Widgets\WidgetArea as WidgetAreaRepository;
|
|
||||||
use App\Models\Widgets\WidgetArea;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
|
|
||||||
class WidgetAreas
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array list of inicialized widget areas
|
|
||||||
*/
|
|
||||||
protected static $widgetAreas = [];
|
|
||||||
protected static $initialized = false;
|
|
||||||
|
|
||||||
protected static function saveRenderedWidgetArea($widgets)
|
|
||||||
{
|
|
||||||
foreach ($widgets as $widget) {
|
|
||||||
if (!isset(self::$widgetAreas[$widget->widget_area_code])) {
|
|
||||||
self::$widgetAreas[$widget->widget_area_code] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
self::$widgetAreas[$widget->widget_area_code] .= Widget::render($widget);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function loadWidgetArea($uniqueCode)
|
|
||||||
{
|
|
||||||
WidgetArea::where('code', $uniqueCode)
|
|
||||||
->increment('viewed');
|
|
||||||
|
|
||||||
$widgets = Cache::remember('widget-area-' . $uniqueCode, setting('widgetCacheLifetime', 5), function () use ($uniqueCode) {
|
|
||||||
$widgetArea = app(\App\CMS\Repositories\Widgets\WidgetArea::class);
|
|
||||||
|
|
||||||
return $widgetArea->getWidgets($uniqueCode)
|
|
||||||
->get();
|
|
||||||
});
|
|
||||||
|
|
||||||
self::saveRenderedWidgetArea($widgets);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function initWidgetAreas()
|
|
||||||
{
|
|
||||||
if (self::$initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$widgets = Cache::remember('widgets', setting('widgetCacheLifetime', 5), function () {
|
|
||||||
$widgetArea = app(WidgetAreaRepository::class);
|
|
||||||
return $widgetArea->getWidgets()
|
|
||||||
->get();
|
|
||||||
});
|
|
||||||
|
|
||||||
self::saveRenderedWidgetArea($widgets);
|
|
||||||
self::$initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renderer for whole widget area.
|
|
||||||
*
|
|
||||||
* @param $uniqueCode
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function render($uniqueCode)
|
|
||||||
{
|
|
||||||
if (!self::$initialized) {
|
|
||||||
self::initWidgetAreas();
|
|
||||||
}
|
|
||||||
|
|
||||||
// dd($uniqueCode);
|
|
||||||
|
|
||||||
if (!isset(self::$widgetAreas[$uniqueCode])) {
|
|
||||||
self::loadWidgetArea($uniqueCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo isset(self::$widgetAreas[$uniqueCode]) ? self::$widgetAreas[$uniqueCode] : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Define function for escaping characters.
|
|
||||||
*
|
|
||||||
* This funcion prevents of creating build-in function, which escapes also accents...
|
|
||||||
*
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function e($value)
|
|
||||||
{
|
|
||||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for \App\CMS\Helpers\Settings::get()
|
|
||||||
*
|
|
||||||
* @param $key
|
|
||||||
* @param null $default
|
|
||||||
*
|
|
||||||
* @return null|string
|
|
||||||
*/
|
|
||||||
function setting($key, $default = null) {
|
|
||||||
return \App\CMS\Helpers\Settings::get($key, $default);
|
|
||||||
}
|
|
||||||
|
|
||||||
function asset_path($path) {
|
|
||||||
return env('SITE_URL').'/assets/'.$path;
|
|
||||||
}
|
|
||||||
|
|
||||||
function template_name($name, $throwExceptions = true) {
|
|
||||||
return \App\CMS\Helpers\Template::name($name, $throwExceptions);
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Interactions\Admin\Content;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Interaction;
|
|
||||||
use App\CMS\Enumerations\ContentStatuses;
|
|
||||||
|
|
||||||
class ChangeStatus implements Interaction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Change status of content page
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param array $parameters
|
|
||||||
*
|
|
||||||
* @return mixed|void
|
|
||||||
*/
|
|
||||||
public function handle($data, $parameters)
|
|
||||||
{
|
|
||||||
list ($page) = $parameters;
|
|
||||||
|
|
||||||
$page->status = $data['status'];
|
|
||||||
$page->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if status is valid
|
|
||||||
*
|
|
||||||
* @param array $parameters
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getValidationRules($parameters = [])
|
|
||||||
{
|
|
||||||
$statuses = ContentStatuses::getWithTranslations();
|
|
||||||
|
|
||||||
return ['status' => 'in:' . implode(',', array_keys($statuses))];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Interactions\Admin\Content;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Interaction;
|
|
||||||
use App\CMS\Contracts\Repositories\Module;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
|
|
||||||
class DeletePage implements Interaction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Perform given action
|
|
||||||
*
|
|
||||||
* @param $data array input data
|
|
||||||
* @param $parameters array parameters
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle($data, $parameters)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var $page Content
|
|
||||||
* @var $module Module
|
|
||||||
*/
|
|
||||||
|
|
||||||
$module = App::make(Module::class);
|
|
||||||
list ($page) = $parameters;
|
|
||||||
|
|
||||||
// delete page
|
|
||||||
$page->delete();
|
|
||||||
|
|
||||||
// let module to delete some extra content created during page's life
|
|
||||||
$module->callOnString($page->moduleHandler, 'delete', [$page]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $data array input data
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getValidationRules($data = [])
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Cms\Interactions\Admin\Content;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Interaction;
|
|
||||||
use App\CMS\Contracts\Repositories\Module;
|
|
||||||
use App\CMS\Enumerations\ContentStatuses;
|
|
||||||
use App\CMS\Helpers\CurrentTemplate;
|
|
||||||
use App\Events\EditContent as EditContentEvent;
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\FileManager\File;
|
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
||||||
|
|
||||||
class EditContent implements Interaction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Module
|
|
||||||
*/
|
|
||||||
protected $module;
|
|
||||||
/**
|
|
||||||
* @var File
|
|
||||||
*/
|
|
||||||
protected $file;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->module = App::make(Module::class);
|
|
||||||
$this->file = App::make(File::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit page
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param array $parameters
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle($data, $parameters)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var $page Content
|
|
||||||
*/
|
|
||||||
list($page) = $parameters;
|
|
||||||
|
|
||||||
app('saveContentPipeline')->run($page, $data);
|
|
||||||
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate this interaction
|
|
||||||
*
|
|
||||||
* @param array $parameters
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getValidationRules($parameters = [])
|
|
||||||
{
|
|
||||||
$id = $parameters[0]->id;
|
|
||||||
|
|
||||||
// get all available statuses
|
|
||||||
$statuses = ContentStatuses::getSimple();
|
|
||||||
$statuses = implode(',', $statuses);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'title' => 'required',
|
|
||||||
'url' => 'required|unique:contents,url,' . $id.',id,deleted_at,NULL,language,' . LaravelLocalization::getCurrentLocale(),
|
|
||||||
'publishedFrom' => 'date',
|
|
||||||
'publishedTo' => 'date',
|
|
||||||
'status' => 'required|in:' . $statuses,
|
|
||||||
'parentPage' => 'exists:contents,id'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Cms\Interactions\Admin\Content;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Interaction;
|
|
||||||
use App\CMS\Contracts\Repositories\Content as ContentRepository;
|
|
||||||
use App\CMS\Contracts\Repositories\Module;
|
|
||||||
use App\CMS\Enumerations\ContentStatuses;
|
|
||||||
use App\CMS\Helpers\CurrentTemplate;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\FileManager\File;
|
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
||||||
|
|
||||||
class NewContent implements Interaction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var ContentRepository
|
|
||||||
*/
|
|
||||||
protected $content;
|
|
||||||
/**
|
|
||||||
* @var File
|
|
||||||
*/
|
|
||||||
protected $file;
|
|
||||||
/**
|
|
||||||
* @var Module
|
|
||||||
*/
|
|
||||||
protected $module;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->content = App::make(ContentRepository::class);
|
|
||||||
$this->module = App::make(Module::class);
|
|
||||||
$this->file = App::make(File::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new content page
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param $parameters
|
|
||||||
*
|
|
||||||
* @return Content
|
|
||||||
*/
|
|
||||||
public function handle($data, $parameters)
|
|
||||||
{
|
|
||||||
list($moduleHandler) = $parameters;
|
|
||||||
|
|
||||||
$data['userId'] = \Auth::user()->id;
|
|
||||||
$data['language'] = LaravelLocalization::getCurrentLocale();
|
|
||||||
$data['moduleHandler'] = $moduleHandler;
|
|
||||||
|
|
||||||
$page = new Content();
|
|
||||||
app('saveContentPipeline')->run($page, $data);
|
|
||||||
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getValidationRules($parameters = [])
|
|
||||||
{
|
|
||||||
// get all available statuses
|
|
||||||
$statuses = ContentStatuses::getSimple();
|
|
||||||
$statuses = implode(',', $statuses);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'titlePhoto' => 'image',
|
|
||||||
'title' => 'required',
|
|
||||||
'url' => 'required|unique:contents,url,NULL,id,deleted_at,NULL,language,' . LaravelLocalization::getCurrentLocale(),
|
|
||||||
'status' => 'required|in:'.$statuses,
|
|
||||||
'parentPage' => 'exists:contents,id',
|
|
||||||
'publishedFrom' => 'date',
|
|
||||||
'publishedTo' => 'date',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Interactions\Admin\Content;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Interaction;
|
|
||||||
use App\CMS\Enumerations\ContentStatuses;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
||||||
|
|
||||||
class SetHomepage implements Interaction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Set homepage of given page
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param array $parameters
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle($data, $parameters)
|
|
||||||
{
|
|
||||||
list ($page) = $parameters;
|
|
||||||
// disable any other existing homepage
|
|
||||||
Content::where('isHomepage', true)
|
|
||||||
->where('language', LaravelLocalization::getCurrentLocale())
|
|
||||||
->update(['isHomepage' => false]);
|
|
||||||
|
|
||||||
// set new homepage
|
|
||||||
$page->isHomepage = true;
|
|
||||||
$page->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if status is valid
|
|
||||||
*
|
|
||||||
* @param array $parameters
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getValidationRules($parameters = [])
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Interactions\Admin\FileManager;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Interaction;
|
|
||||||
use App\CMS\Exceptions\FileManager\SubdirectoryExistsInDirectory;
|
|
||||||
use App\CMS\Repositories\FileManager\Directory as DirectoryRepository;
|
|
||||||
use App\Models\FileManager\Directory;
|
|
||||||
|
|
||||||
class CreateDirectory implements Interaction
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var DirectoryRepository
|
|
||||||
*/
|
|
||||||
private $repository;
|
|
||||||
|
|
||||||
public function __construct(DirectoryRepository $repository)
|
|
||||||
{
|
|
||||||
$this->repository = $repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform given action
|
|
||||||
*
|
|
||||||
* @param $data array input data
|
|
||||||
* @param $parameters array parameters
|
|
||||||
*
|
|
||||||
* @return Directory
|
|
||||||
* @throws SubdirectoryExistsInDirectory
|
|
||||||
*/
|
|
||||||
public function handle($data, $parameters)
|
|
||||||
{
|
|
||||||
$data['parentDirectory'] = isset($data['parentDirectory']) ? $data['parentDirectory'] : null;
|
|
||||||
|
|
||||||
// check if created folder does not exist in current directory
|
|
||||||
if ($this->repository->checkIfNameExists($data['name'], $data['parentDirectory'])) {
|
|
||||||
throw new SubdirectoryExistsInDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
// create new database entry
|
|
||||||
return $this->repository->create($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $data array input data
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @throws SubdirectoryExistsInDirectory
|
|
||||||
*/
|
|
||||||
public function getValidationRules($data = [])
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'name' => 'required|max:255',
|
|
||||||
'parentDirectory' => 'exists:directories,id'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\MenuPresenters;
|
|
||||||
|
|
||||||
use Nwidart\Menus\MenuItem;
|
|
||||||
use Nwidart\Menus\Presenters\Presenter;
|
|
||||||
|
|
||||||
class MetismenuPresenter extends Presenter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getOpenTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '<ul class="nav metismenu" id="sidebar-menu">' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getCloseTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '</ul>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getMenuWithoutDropdownWrapper($item)
|
|
||||||
{
|
|
||||||
return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '">' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getActiveState(MenuItem $item)
|
|
||||||
{
|
|
||||||
if ($item->isDivider()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$active = ' class="active"';
|
|
||||||
|
|
||||||
if (empty($item->getChilds())) {
|
|
||||||
// for direct menu input return if page is active
|
|
||||||
return \Request::is($item->getRequest()) ? $active : null;
|
|
||||||
} else {
|
|
||||||
// on nested menu inputs loop over children and in case any of them is active, mark active also root level
|
|
||||||
foreach ($item->getChilds() as $child) {
|
|
||||||
if ($this->getActiveState($child)) {
|
|
||||||
return $active;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getDividerWrapper()
|
|
||||||
{
|
|
||||||
return '<li class="divider"></li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMultiLevelDropdownWrapper($item)
|
|
||||||
{
|
|
||||||
return $this->getMenuWithDropDownWrapper($item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getMenuWithDropDownWrapper($item)
|
|
||||||
{
|
|
||||||
$active = $this->getActiveState($item);
|
|
||||||
return '<li' . $active . '>
|
|
||||||
<a href="#">' . $item->getIcon() . ' ' . $item->title . ' <i class="fa arrow"></i></a>
|
|
||||||
<ul>
|
|
||||||
' . $this->getChildMenuItems($item) . '
|
|
||||||
</ul>
|
|
||||||
</li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\MenuPresenters;
|
|
||||||
|
|
||||||
use Nwidart\Menus\MenuItem;
|
|
||||||
use Nwidart\Menus\Presenters\Presenter;
|
|
||||||
|
|
||||||
|
|
||||||
class ProfileMenuPresenter extends Presenter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getOpenTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '<div class="dropdown-menu profile-dropdown-menu">' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getCloseTagWrapper()
|
|
||||||
{
|
|
||||||
return PHP_EOL . '</div>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getMenuWithoutDropdownWrapper($item)
|
|
||||||
{
|
|
||||||
return '<a href="' . $item->getUrl() . '" class="dropdown-item">' . $item->getIcon() . ' ' . $item->title . '</a>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getActiveState(MenuItem $item)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getDividerWrapper()
|
|
||||||
{
|
|
||||||
return '<div class="dropdown-divider"></div>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMultiLevelDropdownWrapper($item)
|
|
||||||
{
|
|
||||||
return null;//$this->getMenuWithDropDownWrapper($item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc }
|
|
||||||
*/
|
|
||||||
public function getMenuWithDropDownWrapper($item)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\Modules\ServiceProviders;
|
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
|
||||||
|
|
||||||
abstract class ServiceProvider extends LaravelServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Indicates if loading of the provider is deferred.
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $defer = false;
|
|
||||||
protected $alias = false;
|
|
||||||
protected $path = false;
|
|
||||||
|
|
||||||
abstract protected function setModuleAlias();
|
|
||||||
|
|
||||||
abstract protected function setModulePath();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Boot the application events.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
$this->setModuleAlias();
|
|
||||||
$this->setModulePath();
|
|
||||||
|
|
||||||
$this->registerTranslations();
|
|
||||||
$this->registerConfig();
|
|
||||||
$this->registerViews();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register config.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function registerConfig()
|
|
||||||
{
|
|
||||||
$this->publishes([$this->path . '/../Config/config.php' => config_path($this->alias . '.php')]);
|
|
||||||
$this->mergeConfigFrom($this->path . '/../Config/config.php', $this->alias);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register views.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function registerViews()
|
|
||||||
{
|
|
||||||
$viewPath = base_path('resources/views/modules/' . $this->alias);
|
|
||||||
$sourcePath = $this->path . '/../Resources/views';
|
|
||||||
|
|
||||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
|
||||||
return $path . '/modules/' . $this->alias;
|
|
||||||
}, \Config::get('view.paths')), [$sourcePath]), $this->alias);
|
|
||||||
|
|
||||||
if (is_dir($sourcePath)) {
|
|
||||||
$this->publishes([$sourcePath => $viewPath], 'module-views');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register translations.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function registerTranslations()
|
|
||||||
{
|
|
||||||
$this->loadTranslationsFrom($this->path . '/../Resources/lang', $this->alias);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'name' => '$Module$',
|
|
||||||
'translatedName' => '$module$::$module$.name',
|
|
||||||
'translatedDescription' => '$module$::$module$.description',
|
|
||||||
'alias' => 'categories',
|
|
||||||
'handler' => \Modules\$Module$\Handlers\$Module$Handler::class,
|
|
||||||
'providers' => [\Modules\$Module$\Providers\$Module$ServiceProvider::class],
|
|
||||||
'files' => ['Http/routes.php'],
|
|
||||||
'order' => 0,
|
|
||||||
];
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\$ModuleNamespace$\Entities;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class $Entity$ extends Model {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\$ModuleNamespace$\Handlers;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\ContentTitles;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
class $Module$ContentHandler extends $Module$Handler implements ContentTitles
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get translated title for pages overview of given type.
|
|
||||||
* This value is used for rendering list of all content pages of given type in administration.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getOverviewTitle()
|
|
||||||
{
|
|
||||||
// TODO: Implement getOverviewTitle() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title displayed above for for creating new content page
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getCreateNewTitle()
|
|
||||||
{
|
|
||||||
// TODO: Implement getCreateNewTitle() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title for form displayed for editin content page
|
|
||||||
*
|
|
||||||
* @param Content $content
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getEditTitle(Content $content)
|
|
||||||
{
|
|
||||||
// TODO: Implement getEditTitle() method.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\$ModuleNamespace$\Handlers;
|
|
||||||
|
|
||||||
use App\CMS\Handlers\Handler;
|
|
||||||
use App\Models\User;
|
|
||||||
|
|
||||||
class $Module$Handler extends Handler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Register admin menu
|
|
||||||
*
|
|
||||||
* @param User $user
|
|
||||||
*/
|
|
||||||
public static function registerAdminMenu(User $user)
|
|
||||||
{
|
|
||||||
// register links in admin menu
|
|
||||||
$menu = \Menu::instance('mainMenu');
|
|
||||||
|
|
||||||
$menu->dropdown(trans('$module$::$module$.name'), function ($submenu) use ($user) {
|
|
||||||
$submenu->route('$module$.overview', trans('$module$::$module$.overview'), [], 20, ['icon' => 'fa fa-fw fa-list']);
|
|
||||||
$submenu->route('$module$.new', trans('$module$::$module$.new'), [], 21, ['icon' => 'fa fa-fw fa-plus']);
|
|
||||||
}, 15, ['icon' => 'fa fa-fw']);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: add admin menu entries
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does this module support categories?
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public static function supportCategories()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\$ModuleNamespace$\Http\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Admin\Controller;
|
|
||||||
use Modules\$ModuleNamespace$\Http\Requests\Update$Entity$;
|
|
||||||
use Modules\$ModuleNamespace$\Http\Requests\Create$Entity$;
|
|
||||||
use Modules\$ModuleNamespace$\Repositories\$Module$Repository;
|
|
||||||
use $EntityNamespace$\$Entity$ as $Entity$Entity;
|
|
||||||
|
|
||||||
class $Module$ extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var $Module$Repository
|
|
||||||
*/
|
|
||||||
private $$module$Repository;
|
|
||||||
|
|
||||||
public function __construct($Module$Repository $$module$Repository)
|
|
||||||
{
|
|
||||||
$this->$module$Repository = $$module$Repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
||||||
*/
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
$items = $Entity$Entity::all();
|
|
||||||
|
|
||||||
return view('$module$::admin/index', compact('items'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display form for updating entity
|
|
||||||
*
|
|
||||||
* @param $Entity$Entity $entity
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
||||||
*/
|
|
||||||
public function edit($Entity$Entity $entity)
|
|
||||||
{
|
|
||||||
return view('$module$::admin/update', compact('entity'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update existing entity
|
|
||||||
*
|
|
||||||
* @param Update$Entity$ $request
|
|
||||||
* @param $Entity$Entity $item
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
|
||||||
public function update(Update$Entity$ $request, $Entity$Entity $entity)
|
|
||||||
{
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
$this->$module$Repository->update($entity, $request->all());
|
|
||||||
|
|
||||||
return redirect()
|
|
||||||
->back()
|
|
||||||
->with('success', trans('$module$.$module.successfullyUpdated'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display form for creating new entity
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
||||||
*/
|
|
||||||
public function create() {
|
|
||||||
$entity = new $Entity$Entity();
|
|
||||||
|
|
||||||
return view('$module$::admin/create', compact('entity'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new instance of entity
|
|
||||||
*/
|
|
||||||
public function store(Create$Entity$ $request) {
|
|
||||||
// ...
|
|
||||||
|
|
||||||
$this->$module$Repository->create($request->all());
|
|
||||||
|
|
||||||
return redirect()
|
|
||||||
->back()
|
|
||||||
->with('success', trans('$module$.$module.successfullyUpdated'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete entity
|
|
||||||
*
|
|
||||||
* @param $Entity$ $entity
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
|
||||||
public function destroy($Entity$ $entity) {
|
|
||||||
$entity->delete();
|
|
||||||
|
|
||||||
return redirect()
|
|
||||||
->back()
|
|
||||||
->with('success', trans('$module$.$module.successfullyDeleted'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\$ModuleNamespace$\Http\Requests;
|
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
|
|
||||||
class Create$Entity$ extends Request {
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return parent::rules();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\$ModuleNamespace$\Http\Requests;
|
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
|
|
||||||
class Update$Entity$ extends Request {
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return parent::rules();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
\Route::group([
|
|
||||||
'prefix' => \LaravelLocalization::setLocale() . '/admin/$module$',
|
|
||||||
'middleware' => ['admin'],
|
|
||||||
'namespace' => 'Modules\$Module$\Http\Controllers\Admin'
|
|
||||||
], function () {
|
|
||||||
Route::get('/', '$Module$@index')
|
|
||||||
->name('$module$.overview');
|
|
||||||
|
|
||||||
Route::get('/new', '$Module$@create')
|
|
||||||
->name('$module$.new');
|
|
||||||
|
|
||||||
Route::post('/new', '$Module$@store')
|
|
||||||
->name('$module$.postNew');
|
|
||||||
|
|
||||||
Route::get('/edit/{id}', '$Module$@edit')
|
|
||||||
->name('$module$.edit');
|
|
||||||
|
|
||||||
Route::post('/edit/{id}', '$Module$@update')
|
|
||||||
->name('$module$.postEdit');
|
|
||||||
|
|
||||||
Route::get('/delete/{id}', '$Module$@delete')
|
|
||||||
->name('$module$.delete');
|
|
||||||
});
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\$Module$\Providers;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Modules\ServiceProvider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class $Module$ServiceProvider
|
|
||||||
*
|
|
||||||
* Service provider for module $Module$
|
|
||||||
*
|
|
||||||
* @package Modules\$Module$\Providers
|
|
||||||
*/
|
|
||||||
class $Module$ServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Set module Alias
|
|
||||||
*/
|
|
||||||
protected function setModuleAlias()
|
|
||||||
{
|
|
||||||
$this->alias = strtolower('$module$');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set path to module
|
|
||||||
*/
|
|
||||||
protected function setModulePath()
|
|
||||||
{
|
|
||||||
$this->path = __DIR__;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\$ModuleNamespace$\Repositories;
|
|
||||||
|
|
||||||
use $EntityNamespace$\$Entity$ as $Entity$Entity;
|
|
||||||
|
|
||||||
class $Module$Repository {
|
|
||||||
/**
|
|
||||||
* Create new instance of entity
|
|
||||||
*
|
|
||||||
* @param $data
|
|
||||||
*/
|
|
||||||
public function create($data) {
|
|
||||||
$Entity$Entity::create($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update entity
|
|
||||||
*
|
|
||||||
* @param $Entity$Entity $entity
|
|
||||||
*/
|
|
||||||
public function update($Entity$Entity $entity, $data) {
|
|
||||||
$entity->update($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'name' => '$Module$',
|
|
||||||
'new' => 'Vytvořit nový',
|
|
||||||
'description' => '',
|
|
||||||
'successfullyUpdated' => 'Úspěšně upraveno.',
|
|
||||||
'successfullyCreated' => 'Úspěšně vytvořeno.',
|
|
||||||
'successfullyDeleted' => 'Úspěšně smazáno.',
|
|
||||||
'overview' => 'Přehled',
|
|
||||||
'noItems' => 'Žádná data.',
|
|
||||||
'save' => 'Uložit'
|
|
||||||
];
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
@extends('admin.layoutWithNavigation')
|
|
||||||
|
|
||||||
@section('pageHeading', @trans('$module$::$module$.name'))
|
|
||||||
|
|
||||||
@section('content')
|
|
||||||
@include('$module$::admin/form', ['action' => route('$module$.new')])
|
|
||||||
@endsection
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
@extends('admin.layoutWithNavigation')
|
|
||||||
|
|
||||||
@section('pageHeading', @trans('$module$::$module$.name'))
|
|
||||||
|
|
||||||
@section('content')
|
|
||||||
@include('$module$::admin/form', ['action' => route('$module$.update')])
|
|
||||||
@endsection
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<form action="{{$action}}" method="post">
|
|
||||||
|
|
||||||
{{--...--}}
|
|
||||||
|
|
||||||
<input type="submit" class="btn btn-primary" value="@lang('$module$::$module$.save')">
|
|
||||||
</form>
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
@extends('admin.layoutWithNavigation')
|
|
||||||
|
|
||||||
@section('pageHeading', @trans('$module$::$module$.overview'))
|
|
||||||
|
|
||||||
@section('content')
|
|
||||||
@if (!empty($items))
|
|
||||||
<table>
|
|
||||||
@foreach($items as $item)
|
|
||||||
|
|
||||||
@endforeach
|
|
||||||
</table>
|
|
||||||
@else
|
|
||||||
<div class="alert alert-info">
|
|
||||||
<em>@trans('$module$::$module$.noItems')</em>
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
@endsection
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Observers;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Repositories\Content as ContentContract;
|
|
||||||
use App\Events\CreateNewContent;
|
|
||||||
use App\Events\DeleteContent;
|
|
||||||
use App\Events\EditContent;
|
|
||||||
use App\Events\MakeDraftFromContent;
|
|
||||||
use App\Events\PublishContent;
|
|
||||||
use App\Events\SetHomepage;
|
|
||||||
use App\Models\Content\Content as ContentModel;
|
|
||||||
use App\Models\Content\ContentHistory;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Content
|
|
||||||
*
|
|
||||||
* Model observer for logging changes on content page.
|
|
||||||
*
|
|
||||||
* @package App\CMS\Observers
|
|
||||||
*/
|
|
||||||
class Content
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $changeset;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->changeset = uniqid();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Log changes on edit
|
|
||||||
*
|
|
||||||
* @param ContentModel $content
|
|
||||||
*/
|
|
||||||
public function updated(ContentModel $content)
|
|
||||||
{
|
|
||||||
$fields = $this->getDirtyFields($content->getDirty(), $content->getOriginal());
|
|
||||||
|
|
||||||
$normalFieldsEdited = 0;
|
|
||||||
foreach ($fields as $field => $change) {
|
|
||||||
if ($field == 'viewed')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$history = [
|
|
||||||
'user_id' => \Auth::user()->id,
|
|
||||||
'content_id' => $content->id,
|
|
||||||
'edit_batch' => $this->changeset,
|
|
||||||
'column' => $field,
|
|
||||||
'old_value' => $change['old'],
|
|
||||||
'new_value' => $change['new']
|
|
||||||
];
|
|
||||||
|
|
||||||
// save history
|
|
||||||
ContentHistory::create($history);
|
|
||||||
|
|
||||||
// fire event
|
|
||||||
$this->fireEvent($field, $change, $content, $normalFieldsEdited);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($normalFieldsEdited > 0) {
|
|
||||||
Event::fire(new EditContent($content, $this->changeset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fire event when new instance of model is stored into database
|
|
||||||
*
|
|
||||||
* @param ContentModel $content
|
|
||||||
*/
|
|
||||||
public function created(ContentModel $content)
|
|
||||||
{
|
|
||||||
Event::fire(new CreateNewContent($content));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ContentModel $content
|
|
||||||
*/
|
|
||||||
public function deleted(ContentModel $content)
|
|
||||||
{
|
|
||||||
Event::fire(new DeleteContent($content));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all dirty changed from model.
|
|
||||||
*
|
|
||||||
* If user did not change moduleSettings column, return result from ContentModel::getDirty(). Otherwise append all
|
|
||||||
* changed columns from module settings.
|
|
||||||
*
|
|
||||||
* @param $changed
|
|
||||||
* @param $original
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getDirtyFields($changed, $original)
|
|
||||||
{
|
|
||||||
unset($changed['updated_at']);
|
|
||||||
|
|
||||||
$changes = $this->getNewAndOldValues(array_keys($changed), $changed, $original);
|
|
||||||
|
|
||||||
if (!isset($changed['moduleSettings'])) {
|
|
||||||
return $changes;
|
|
||||||
}
|
|
||||||
|
|
||||||
$moduleSettings = (array)json_decode($changed['moduleSettings']);
|
|
||||||
$originalSettings = isset($original['moduleSettings']) ? (array)json_decode($original['moduleSettings']) : [];
|
|
||||||
unset($changed['moduleSettings']);
|
|
||||||
|
|
||||||
$settingChanged = array_keys(array_diff_assoc($moduleSettings, $originalSettings));
|
|
||||||
$changesInSettings = $this->getNewAndOldValues($settingChanged, $moduleSettings, $originalSettings);
|
|
||||||
|
|
||||||
return array_merge($changes, $changesInSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get original and changed values in one array
|
|
||||||
*
|
|
||||||
* @param $fields
|
|
||||||
* @param $new
|
|
||||||
* @param $original
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getNewAndOldValues($fields, $new, $original)
|
|
||||||
{
|
|
||||||
$changes = [];
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$changes[$field] = [
|
|
||||||
'new' => isset($new[$field]) ? $new[$field] : null,
|
|
||||||
'old' => isset($original[$field]) ? $original[$field] : null
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $changes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fire events for publishing/making draft and setting homepage
|
|
||||||
*
|
|
||||||
* @param $field
|
|
||||||
* @param $change
|
|
||||||
* @param ContentModel $content
|
|
||||||
* @param $normalFieldsEdited
|
|
||||||
*/
|
|
||||||
protected function fireEvent($field, $change, ContentModel $content, &$normalFieldsEdited)
|
|
||||||
{
|
|
||||||
switch ($field) {
|
|
||||||
case 'status':
|
|
||||||
if ($change['new'] !== ContentContract::STATUS_DRAFT) {
|
|
||||||
Event::fire(new PublishContent($content, $this->changeset));
|
|
||||||
} else {
|
|
||||||
Event::fire(new MakeDraftFromContent($content, $this->changeset));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'isHomepage':
|
|
||||||
Event::fire(new SetHomepage($content, $this->changeset));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$normalFieldsEdited++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Pipeline;
|
|
||||||
|
|
||||||
use App\CMS\Pipeline\Exceptions\InvalidProcessType;
|
|
||||||
|
|
||||||
abstract class AbstractPipeline {
|
|
||||||
protected $processes = [];
|
|
||||||
protected $beforeStart = null;
|
|
||||||
protected $beforeRender = null;
|
|
||||||
protected $acceptedProcessInterface = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check if given classname implements valid Process interface
|
|
||||||
*
|
|
||||||
* @param $classname
|
|
||||||
*
|
|
||||||
* @throws InvalidProcessType
|
|
||||||
*/
|
|
||||||
protected function checkValidProcess($classname)
|
|
||||||
{
|
|
||||||
if (is_null($this->acceptedProcessInterface))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!in_array($this->acceptedProcessInterface, class_implements($classname))) {
|
|
||||||
throw new InvalidProcessType($classname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add new process into pipeline
|
|
||||||
*
|
|
||||||
* @param $process
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws InvalidProcessType
|
|
||||||
*/
|
|
||||||
function add($process)
|
|
||||||
{
|
|
||||||
$this->checkValidProcess($process);
|
|
||||||
|
|
||||||
$this->processes[] = $process;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param null $beforeStart
|
|
||||||
*/
|
|
||||||
public function setBeforeStart($beforeStart)
|
|
||||||
{
|
|
||||||
$this->checkValidProcess($beforeStart);
|
|
||||||
|
|
||||||
if (!is_null($this->beforeStart)) {
|
|
||||||
array_unshift($this->processes, $this->beforeStart);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->beforeStart = $beforeStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param null $beforeRender
|
|
||||||
*/
|
|
||||||
public function setBeforeRender($beforeRender)
|
|
||||||
{
|
|
||||||
$this->checkValidProcess($beforeRender);
|
|
||||||
|
|
||||||
if (!is_null($this->beforeRender)) {
|
|
||||||
array_push($this->processes, $this->beforeRender);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->beforeRender = $beforeRender;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Pipeline\DisplayPipeline;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\DisplayPipeline\Pipeline;
|
|
||||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
|
||||||
use App\CMS\Pipeline\AbstractPipeline;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
class DisplayPipeline extends AbstractPipeline implements Pipeline
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* DisplayPipeline constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->acceptedProcessInterface = Process::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run pipeline
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
*
|
|
||||||
* @return Content
|
|
||||||
*/
|
|
||||||
function run(Content $page)
|
|
||||||
{
|
|
||||||
$this->runBeforeStart($page);
|
|
||||||
|
|
||||||
foreach ($this->processes as $process) {
|
|
||||||
/**
|
|
||||||
* @var $run Process
|
|
||||||
*/
|
|
||||||
$run = new $process;
|
|
||||||
$run->handle($page);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->runBeforeRender($page);
|
|
||||||
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function runBeforeStart($page)
|
|
||||||
{
|
|
||||||
if (!is_null($this->beforeStart)) {
|
|
||||||
$process = new $this->beforeStart;
|
|
||||||
$process->handle($page);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function runBeforeRender($page)
|
|
||||||
{
|
|
||||||
if (!is_null($this->beforeRender)) {
|
|
||||||
$process = new $this->beforeRender;
|
|
||||||
$process->handle($page);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Pipeline\DisplayPipeline\Process;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
class AddViewedToPage implements Process {
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function handle(Content & $page)
|
|
||||||
{
|
|
||||||
$page->view();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Pipeline\DisplayPipeline\Process;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use Webwizo\Shortcodes\Facades\Shortcode;
|
|
||||||
|
|
||||||
class CompileShortcodes implements Process {
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function handle(Content & $page)
|
|
||||||
{
|
|
||||||
$page->pageContent = Shortcode::compile($page->pageContent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Pipeline\Exceptions;
|
|
||||||
|
|
||||||
class InvalidProcessType extends \Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Pipeline\SavePipeline\Process;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
class SaveCommonFields implements Process {
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param array $input
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function handle(Content & $page, array &$input)
|
|
||||||
{
|
|
||||||
($page->exists == false) ? $page = Content::create($input): $page->update($input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\Pipeline\SavePipeline\Process;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\Content\ContentHasFile;
|
|
||||||
use App\Models\FileManager\Directory;
|
|
||||||
use App\Models\FileManager\File;
|
|
||||||
|
|
||||||
class UploadRelatedFiles implements Process
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param array $input
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function handle(Content & $page, array & $input)
|
|
||||||
{
|
|
||||||
if (!isset($input['files'])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$files = $input['files'];
|
|
||||||
$assignedFiles = isset($input['keepAssigned']) ? $input['keepAssigned'] : [];
|
|
||||||
|
|
||||||
// check if any file was removed
|
|
||||||
$this->removeRelatedFiles($page, $assignedFiles);
|
|
||||||
|
|
||||||
// allow uploading only on created pages
|
|
||||||
if (!$page->id || !$files[0]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find or create new directory for files assigned to content
|
|
||||||
$directory = Directory::firstOrCreate([
|
|
||||||
'name' => '.content_files',
|
|
||||||
'hidden' => true
|
|
||||||
]);
|
|
||||||
$data = new \stdClass();
|
|
||||||
$data->directoryId = $directory->id;
|
|
||||||
|
|
||||||
$fileModel = app(File::class);
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if (!$file) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$uploaded = $fileModel->upload($file, $data);
|
|
||||||
|
|
||||||
// add assignement
|
|
||||||
ContentHasFile::create([
|
|
||||||
'file_id' => $uploaded['id'],
|
|
||||||
'content_id' => $page->id
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete files from association
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param $assignedFiles
|
|
||||||
*/
|
|
||||||
private function removeRelatedFiles(Content $page, $assignedFiles)
|
|
||||||
{
|
|
||||||
$allFiles = $page->files()
|
|
||||||
->whereNotIn('id', array_keys($assignedFiles))
|
|
||||||
->get();
|
|
||||||
|
|
||||||
foreach ($allFiles as $file) {
|
|
||||||
ContentHasFile::where('content_id', $page->id)
|
|
||||||
->where('file_id', $file->id)
|
|
||||||
->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Pipeline\SavePipeline\Process;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
|
||||||
use App\CMS\Helpers\RootDirectory;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\FileManager\File;
|
|
||||||
|
|
||||||
class UploadTitlePhoto implements Process
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param array $input
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function handle(Content & $page, array & $input)
|
|
||||||
{
|
|
||||||
$fileModel = app(File::class);
|
|
||||||
$titlePhoto = isset($input['titlePhotoFile']) ? $input['titlePhotoFile'] : null;
|
|
||||||
|
|
||||||
// upload file - if provided
|
|
||||||
$page->titlePhoto = isset($input['existingTitlePhoto']) ? $input['existingTitlePhoto'] : null;
|
|
||||||
|
|
||||||
if (!is_null($titlePhoto)) {
|
|
||||||
$root = RootDirectory::get();
|
|
||||||
$data = ['directoryId' => $root->id];
|
|
||||||
|
|
||||||
$file = $fileModel->upload($titlePhoto, (object)$data);
|
|
||||||
|
|
||||||
$page->titlePhoto = $file ? $file['filename'] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$page->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Pipeline\SavePipeline;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\SavePipeline\Pipeline;
|
|
||||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
|
||||||
use App\CMS\Pipeline\AbstractPipeline;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
class SavePipeline extends AbstractPipeline implements Pipeline
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* SavePipeline constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->acceptedProcessInterface = Process::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save content page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param array $input
|
|
||||||
*
|
|
||||||
* @return Content
|
|
||||||
*/
|
|
||||||
function run(Content & $page, array $input)
|
|
||||||
{
|
|
||||||
$this->runBeforeStart($page, $input);
|
|
||||||
|
|
||||||
foreach ($this->processes as $process) {
|
|
||||||
/**
|
|
||||||
* @var $run Process
|
|
||||||
*/
|
|
||||||
$run = new $process;
|
|
||||||
$run->handle($page, $input);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->runAfter($page, $input);
|
|
||||||
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run process as first - if specified
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param array $input
|
|
||||||
*/
|
|
||||||
protected function runBeforeStart(Content $page, array $input)
|
|
||||||
{
|
|
||||||
if (!is_null($this->beforeStart)) {
|
|
||||||
app($this->beforeStart)->handle($page, $input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run some process in the end - if exists
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
* @param array $input
|
|
||||||
*/
|
|
||||||
protected function runAfter(Content $page, array $input)
|
|
||||||
{
|
|
||||||
if (!is_null($this->beforeRender)) {
|
|
||||||
app($this->beforeRender)->handle($page, $input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Repositories\Content;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
|
||||||
use App\CMS\Enumerations\ContentStatuses;
|
|
||||||
use App\CMS\Repositories\Repository;
|
|
||||||
use App\Models\Content\Content as ContentModel;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
||||||
|
|
||||||
class Content extends Repository implements IContent
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var ContentModel
|
|
||||||
*/
|
|
||||||
protected $model;
|
|
||||||
|
|
||||||
public function __construct(ContentModel $model)
|
|
||||||
{
|
|
||||||
$this->model = $model;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for query with setup filter for non-deleted and non-draft pages
|
|
||||||
*/
|
|
||||||
protected function getPageQuery()
|
|
||||||
{
|
|
||||||
return ContentModel::where('status', '!=', IContent::STATUS_DRAFT)
|
|
||||||
->select('contents.*')
|
|
||||||
->with('author')
|
|
||||||
->join('modules', 'modules.handler', '=', 'contents.moduleHandler')
|
|
||||||
->where(function ($query) {
|
|
||||||
$query->where('publishedFrom', '<=', Carbon::now())
|
|
||||||
->orWhereNull('publishedFrom');
|
|
||||||
})
|
|
||||||
->where(function ($query) {
|
|
||||||
$query->where('publishedTo', '>=', Carbon::now())
|
|
||||||
->orWhereNull('publishedTo');
|
|
||||||
})
|
|
||||||
->where('language', LaravelLocalization::getCurrentLocale())
|
|
||||||
->whereNull('contents.deleted_at')
|
|
||||||
->where('modules.enabled', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function all()
|
|
||||||
{
|
|
||||||
return $this->getPageQuery()
|
|
||||||
->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getOne($id = null)
|
|
||||||
{
|
|
||||||
if (is_null($id)) {
|
|
||||||
$page = new ContentModel();
|
|
||||||
$page->user_id = \Auth::user()->id;
|
|
||||||
$page->language = LaravelLocalization::getCurrentLocale();
|
|
||||||
$page->status = IContent::STATUS_DRAFT;
|
|
||||||
$page->moduleSettings = [];
|
|
||||||
} else {
|
|
||||||
$page = $this->model->findOrFail($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for homepage content page
|
|
||||||
* @return Content
|
|
||||||
*/
|
|
||||||
public function getHomepage()
|
|
||||||
{
|
|
||||||
return $this->getPageQuery()
|
|
||||||
->where('isHomepage', 1)
|
|
||||||
->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for any page specified by its url.
|
|
||||||
*
|
|
||||||
* @param $url
|
|
||||||
*
|
|
||||||
* @return Content
|
|
||||||
*/
|
|
||||||
public function getByURL($url)
|
|
||||||
{
|
|
||||||
return $this->getPageQuery()
|
|
||||||
->where('url', $url)
|
|
||||||
->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for overview of all content pages.
|
|
||||||
* These content pages may be filtered by using some handler
|
|
||||||
*
|
|
||||||
* @param bool $handler
|
|
||||||
* @param null $statuses
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public function getOverview($handler = null, $statuses = null)
|
|
||||||
{
|
|
||||||
$query = ContentModel::select('contents.*', 'modules.name AS module_name', 'modules.id AS module_id')
|
|
||||||
->join('modules', 'modules.handler', '=', 'contents.moduleHandler')
|
|
||||||
->join('users', 'users.id', '=', 'contents.userId')
|
|
||||||
->addSelect(DB::raw('COALESCE(users.name, users.email) AS author_name'))
|
|
||||||
->addSelect('users.email AS author_email')
|
|
||||||
->whereNull('contents.deleted_at')
|
|
||||||
->where('contents.language', LaravelLocalization::getCurrentLocale())
|
|
||||||
->where('modules.enabled', 1)
|
|
||||||
->orderBy('contents.created_at', 'DESC');
|
|
||||||
|
|
||||||
// filter results using handler
|
|
||||||
if (!is_null($handler)) {
|
|
||||||
$query = $query->where('contents.moduleHandler', $handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add filtering by status
|
|
||||||
if (is_array($statuses) && in_array($statuses, ContentStatuses::getSimple())) {
|
|
||||||
$query = $query->whereIn('contents.status', $statuses);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\Repositories\FileManager;
|
|
||||||
|
|
||||||
use App\CMS\Helpers\RootDirectory;
|
|
||||||
use App\Models\FileManager\Directory as DirectoryModel;
|
|
||||||
|
|
||||||
class Directory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Checks if directory with given name does not exist in current directory
|
|
||||||
*
|
|
||||||
* @param $name
|
|
||||||
* @param $parentDirectoryId
|
|
||||||
* @param bool $ignoredId
|
|
||||||
*/
|
|
||||||
public function checkIfNameExists($name, $parentDirectoryId, $ignoredId = false)
|
|
||||||
{
|
|
||||||
$exists = DirectoryModel::where('name', $name)
|
|
||||||
->where('parent_id', $parentDirectoryId);
|
|
||||||
|
|
||||||
if ($ignoredId !== false) {
|
|
||||||
$exists = $exists->where('id', '!=', $ignoredId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $exists->exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new directory
|
|
||||||
*
|
|
||||||
* @param $data
|
|
||||||
*
|
|
||||||
* @return DirectoryModel
|
|
||||||
*/
|
|
||||||
public function create($data)
|
|
||||||
{
|
|
||||||
$directory = new DirectoryModel();
|
|
||||||
$directory->name = $data['name'];
|
|
||||||
$directory->parent_id = $data['parentDirectory'];
|
|
||||||
$directory->user_id = \Auth::user()->id;
|
|
||||||
$directory->description = $data['description'];
|
|
||||||
$directory->save();
|
|
||||||
|
|
||||||
return $directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update given directory
|
|
||||||
*
|
|
||||||
* @param DirectoryModel $directory
|
|
||||||
* @param $data
|
|
||||||
*/
|
|
||||||
public function update(DirectoryModel $directory, $data)
|
|
||||||
{
|
|
||||||
$directory->name = $data['name'];
|
|
||||||
$directory->description = $data['description'];
|
|
||||||
$directory->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param DirectoryModel $directory
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
||||||
*/
|
|
||||||
public function getAllSubdirectories(DirectoryModel &$directory)
|
|
||||||
{
|
|
||||||
if (!$directory->exists) {
|
|
||||||
$directory = DirectoryModel::where('is_root', true)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if (is_null($directory)) {
|
|
||||||
$directory = RootDirectory::get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$subdirectories = $directory->allSubdirectories();
|
|
||||||
|
|
||||||
return $subdirectories;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Repositories\FileManager;
|
|
||||||
|
|
||||||
use App\Models\FileManager\File as FileModel;
|
|
||||||
|
|
||||||
class File {
|
|
||||||
/**
|
|
||||||
* Update given instance of File
|
|
||||||
*
|
|
||||||
* @param FileModel $file
|
|
||||||
* @param $data
|
|
||||||
*/
|
|
||||||
public function update(FileModel $file, $data) {
|
|
||||||
$file->update($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Repositories;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Repositories\Module as IModule;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\Module as ModuleModel;
|
|
||||||
|
|
||||||
class Module extends Repository implements IModule
|
|
||||||
{
|
|
||||||
public function __construct(ModuleModel $module)
|
|
||||||
{
|
|
||||||
$this->model = $module;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOne($id = null)
|
|
||||||
{
|
|
||||||
if (is_null($id)) {
|
|
||||||
return new ModuleModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_numeric($id)) {
|
|
||||||
return ModuleModel::findOrFail($id);
|
|
||||||
} else {
|
|
||||||
return ModuleModel::where('alias', $id)
|
|
||||||
->firstOrFail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCreateContentTitle(ModuleModel $module)
|
|
||||||
{
|
|
||||||
$pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]);
|
|
||||||
$moduleHeading = $this->call($module, 'getCreateNewTitle');
|
|
||||||
|
|
||||||
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUpdateContentTitle(ModuleModel $module, Content $content = null)
|
|
||||||
{
|
|
||||||
$pageHeading = trans('admin/contents.edit', ['name' => trans($module->name)]);
|
|
||||||
$moduleHeading = $this->call($module, 'getEditTitle', [$content]);
|
|
||||||
|
|
||||||
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOverviewTitle(ModuleModel $module)
|
|
||||||
{
|
|
||||||
$pageHeading = 'admin/contents.overview';
|
|
||||||
$moduleHeading = $this->call($module, 'getOverviewTitle');
|
|
||||||
|
|
||||||
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function all()
|
|
||||||
{
|
|
||||||
return ModuleModel::where('enabled', true)
|
|
||||||
->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getByHandler($handler)
|
|
||||||
{
|
|
||||||
return ModuleModel::where('handler', $handler)
|
|
||||||
->firstOrFail();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function call(ModuleModel $module, $method, $parameters = [])
|
|
||||||
{
|
|
||||||
if (!is_null($module) && is_callable([$module->handler, $method])) {
|
|
||||||
return call_user_func_array([$module->handler, $method], $parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function callOnString($moduleHandler, $method, $parameters = [])
|
|
||||||
{
|
|
||||||
if (is_callable([$moduleHandler, $method])) {
|
|
||||||
return call_user_func_array([$moduleHandler, $method], $parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Repositories;
|
|
||||||
|
|
||||||
abstract class Repository
|
|
||||||
{
|
|
||||||
protected $model;
|
|
||||||
|
|
||||||
public function __call($method, $args)
|
|
||||||
{
|
|
||||||
return call_user_func_array([$this->model, $method], $args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Cms\Repositories\Templates;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Repositories\Template as ITemplate;
|
|
||||||
use App\CMS\Repositories\Repository;
|
|
||||||
use App\Models\Module;
|
|
||||||
use App\Models\Templates\Template as TemplateModel;
|
|
||||||
|
|
||||||
class Template extends Repository implements ITemplate
|
|
||||||
{
|
|
||||||
public function setModel(TemplateModel $model)
|
|
||||||
{
|
|
||||||
$this->model = $model;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for absolute path to template
|
|
||||||
*
|
|
||||||
* @param null $mode
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPathToTemplate($mode = null)
|
|
||||||
{
|
|
||||||
$templateName = $this->model->template_name;
|
|
||||||
$path = $this->model->templatePath;
|
|
||||||
|
|
||||||
// delete namespace if given
|
|
||||||
if (strpos($this->model->template_name, '::')) {
|
|
||||||
list(, $templateName) = explode('::', $templateName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get template name, do not care about directories (they are already contained in path)
|
|
||||||
$parts = explode('.', $templateName);
|
|
||||||
$templateName = last($parts);
|
|
||||||
|
|
||||||
// just a shortcut for this unbelievable long constant name...
|
|
||||||
$_ = DIRECTORY_SEPARATOR;
|
|
||||||
|
|
||||||
// path parts
|
|
||||||
$absolutePath = base_path($path->path);
|
|
||||||
$templatePath = str_replace('.', $_, $templateName);
|
|
||||||
$file = $templatePath . ITemplate::TEMPLATE_SUFFIX;
|
|
||||||
|
|
||||||
// compose two versions of path - original and with "custom" directory
|
|
||||||
$original = $absolutePath . $_ . $file;
|
|
||||||
$edited = $absolutePath . $_ . ITemplate::EDITED_TEMPLATES_DIRECTORY . $_ . $file;
|
|
||||||
|
|
||||||
// decide which path will be returned
|
|
||||||
switch ($mode) {
|
|
||||||
case ITemplate::CUSTOM_EDIT_DIRECTORY:
|
|
||||||
return $edited;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ITemplate::ORIGINAL_DIRECTORY:
|
|
||||||
return $original;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (file_exists($absolutePath . $_ . ITemplate::EDITED_TEMPLATES_DIRECTORY . $_ . $file)) {
|
|
||||||
return $edited;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $original;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getForModule(Module $module)
|
|
||||||
{
|
|
||||||
return TemplateModel::where('module_id', $module->id)
|
|
||||||
->select(['template_name', 'name', 'description'])
|
|
||||||
->get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Repositories\Users;
|
|
||||||
|
|
||||||
use App\CMS\Repositories\Repository;
|
|
||||||
use App\Models\User as UserModel;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
|
|
||||||
class User extends Repository {
|
|
||||||
/**
|
|
||||||
* Update given user
|
|
||||||
*
|
|
||||||
* @param UserModel $user
|
|
||||||
* @param $data
|
|
||||||
*/
|
|
||||||
public function update(UserModel $user, $data) {
|
|
||||||
// update username if set
|
|
||||||
if (isset($data['username'])) {
|
|
||||||
$user->username = $data['username'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// change name (if set)
|
|
||||||
if (isset($data['name'])) {
|
|
||||||
$user->name = $data['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['role'])) {
|
|
||||||
$user->role = $data['role'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['status'])) {
|
|
||||||
$user->status = $data['status'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['password'])) {
|
|
||||||
$user->password = Hash::make($data['password']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->email = $data['email'];
|
|
||||||
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new user
|
|
||||||
*
|
|
||||||
* @param $data
|
|
||||||
*
|
|
||||||
* @return UserModel
|
|
||||||
*/
|
|
||||||
public function create($data)
|
|
||||||
{
|
|
||||||
// create new user
|
|
||||||
$user = new UserModel();
|
|
||||||
$user->name = $data['name'];
|
|
||||||
$user->email = $data['email'];
|
|
||||||
$user->username = $data['username'];
|
|
||||||
$user->role = $data['role'];
|
|
||||||
$user->password = Hash::make($data['password']);
|
|
||||||
|
|
||||||
// store user into database
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\Repositories\Widgets;
|
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Widgets\Widget as WidgetModel;
|
|
||||||
use App\Models\Widgets\WidgetType;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
|
|
||||||
class Widget
|
|
||||||
{
|
|
||||||
public function createNew(WidgetType $widgetType, Request $request)
|
|
||||||
{
|
|
||||||
$data = $request->except('_token');
|
|
||||||
|
|
||||||
// create new widget
|
|
||||||
$widget = new WidgetModel();
|
|
||||||
$widget->widget_type_handler = $widgetType->handler;
|
|
||||||
$widget->user_id = \Auth::user()->id;
|
|
||||||
$widget->name = $data['name'];
|
|
||||||
$widget->description = $data['description'];
|
|
||||||
$widget->container_class = $data['containerClass'];
|
|
||||||
$widget->container_id = empty($data['containerId']) ? null : $data['containerId'];
|
|
||||||
$widget->settings = call_user_func([$widgetType->handler, 'save'], $request);
|
|
||||||
|
|
||||||
// save into database
|
|
||||||
$widget->save();
|
|
||||||
|
|
||||||
// fire event with newly created widget
|
|
||||||
Event::fire(new \App\Events\CreateNewWidget($widget));
|
|
||||||
|
|
||||||
return $widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function edit(WidgetModel $widget, Request $request)
|
|
||||||
{
|
|
||||||
// update name
|
|
||||||
$widget->name = $request->name;
|
|
||||||
$widget->container_class = $request->containerClass;
|
|
||||||
$widget->container_id = empty($request->containerId) ? null : $request->containerId;
|
|
||||||
$widget->description = $request->description;
|
|
||||||
|
|
||||||
// try to save this widget
|
|
||||||
$widget->settings = call_user_func([$widget->widget_type_handler, 'save'], $request);
|
|
||||||
|
|
||||||
// save into database
|
|
||||||
$widget->save();
|
|
||||||
|
|
||||||
// fire event with editing widget
|
|
||||||
Event::fire(new \App\Events\EditWidget($widget));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\Repositories\Widgets;
|
|
||||||
|
|
||||||
use App\Events\CreateNewWidgetArea;
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Widgets\Widget;
|
|
||||||
use App\Models\Widgets\WidgetArea as WidgetAreaModel;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
||||||
|
|
||||||
class WidgetArea
|
|
||||||
{
|
|
||||||
public function getWidgets($uniqueCode = false)
|
|
||||||
{
|
|
||||||
$widgets = Widget::select('widgets.*', 'widgets.widget_type_handler', 'widget_areas.code as widget_area_code', 'widgets.name as widget_name', 'widgets.settings')
|
|
||||||
->join('widget_in_widget_area', 'widget_in_widget_area.widget_id', '=', 'widgets.id')
|
|
||||||
->join('widget_areas', 'widget_in_widget_area.widget_area_id', '=', 'widget_areas.id')
|
|
||||||
->where('language', LaravelLocalization::getCurrentLocale())
|
|
||||||
->orderBy('widget_in_widget_area.position');
|
|
||||||
if (!$uniqueCode) {
|
|
||||||
$widgets = $widgets->where('widget_areas.viewed', '>=', setting('preloadFrequentedWidgetAreasTreshold', 10));
|
|
||||||
} else {
|
|
||||||
$widgets = $widgets->where('code', $uniqueCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $widgets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(\App\Models\Widgets\WidgetArea $area, Request $request) {
|
|
||||||
$area->name = $request->name;
|
|
||||||
$area->description = $request->description;
|
|
||||||
$area->save();
|
|
||||||
|
|
||||||
// fire event with new widget area
|
|
||||||
Event::fire(new \App\Events\EditWidgetArea($area));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new instance of widget area
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
*/
|
|
||||||
public function create(Request $request)
|
|
||||||
{
|
|
||||||
$area = WidgetAreaModel::create([
|
|
||||||
'code' => $request->code,
|
|
||||||
'name' => $request->name,
|
|
||||||
'description' => $request->description
|
|
||||||
]);
|
|
||||||
|
|
||||||
// fire event with new widget area
|
|
||||||
Event::fire(new CreateNewWidgetArea($area));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Shortcodes;
|
|
||||||
|
|
||||||
use App\Models\Widgets\Widget as WidgetModel;
|
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
||||||
|
|
||||||
class Widget
|
|
||||||
{
|
|
||||||
protected static $widgets = [];
|
|
||||||
protected static $initialized = false;
|
|
||||||
|
|
||||||
protected function getRenderedWidget(WidgetModel $widget)
|
|
||||||
{
|
|
||||||
$widget->settings = json_decode($widget->settings);
|
|
||||||
|
|
||||||
$handler = $widget->widget_type_handler;
|
|
||||||
$presenter = call_user_func([$handler, 'getPresenter']);
|
|
||||||
|
|
||||||
return call_user_func([$presenter, 'render'], $widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load one widget from database
|
|
||||||
*
|
|
||||||
* @param $containerId
|
|
||||||
*/
|
|
||||||
protected function loadWidget($containerId)
|
|
||||||
{
|
|
||||||
$widget = WidgetModel::where('container_id', $containerId)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if (!$widget) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$widget->timestamps = false;
|
|
||||||
$widget->viewed++;
|
|
||||||
$widget->save();
|
|
||||||
$widget->timestamps = true;
|
|
||||||
|
|
||||||
self::$widgets[$containerId] = $this->getRenderedWidget($widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load all frequently used widgets
|
|
||||||
*
|
|
||||||
* Frequency of loaded widgets is counted only using direct loading, widgets displayed in widget areas are omitted
|
|
||||||
*/
|
|
||||||
protected function initWidgets()
|
|
||||||
{
|
|
||||||
if (self::$initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$widgets = WidgetModel::where('viewed', '>=', setting('preloadFrequentedWidgetsTreshold', 10))
|
|
||||||
->where('language', LaravelLocalization::getCurrentLocale())
|
|
||||||
->get();
|
|
||||||
|
|
||||||
foreach ($widgets as $widget) {
|
|
||||||
self::$widgets[$widget->container_id] = $this->getRenderedWidget($widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
self::$initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register new shortcode
|
|
||||||
*
|
|
||||||
* Initfrequently used widgets and if not presented yet - load desired widget specified as content of shortcode
|
|
||||||
*
|
|
||||||
* @param $shortcode
|
|
||||||
* @param $containerId
|
|
||||||
* @param $compiler
|
|
||||||
* @param $name
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function register($shortcode, $containerId, $compiler, $name)
|
|
||||||
{
|
|
||||||
$this->initWidgets();
|
|
||||||
|
|
||||||
if (!isset(self::$widgets[$containerId])) {
|
|
||||||
$this->loadWidget($containerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$widgets[$containerId];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\CMS\Widgets\Menu;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
|
||||||
use App\CMS\Contracts\Widgets\PublicWidget;
|
|
||||||
use App\CMS\Contracts\Widgets\WidgetRenderer;
|
|
||||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
||||||
use Modules\Blog\Article\Handlers\Article;
|
|
||||||
|
|
||||||
class Menu implements PublicWidget
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Name getter
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getName()
|
|
||||||
{
|
|
||||||
return 'widgets/menu.widgetName';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for description
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getDescription()
|
|
||||||
{
|
|
||||||
return 'widgets/menu.widgetDescription';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for presenter/renderer of this widget
|
|
||||||
*
|
|
||||||
* @return WidgetRenderer
|
|
||||||
*/
|
|
||||||
public static function getPresenter()
|
|
||||||
{
|
|
||||||
return Presenters\Menu::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \App\Models\Widget $widget
|
|
||||||
* @param \stdClass $data
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function save(Request $data)
|
|
||||||
{
|
|
||||||
if (!isset($data->settings) || empty($data->settings) || !json_decode($data->settings)) {
|
|
||||||
throw new MissingParameterException('settings');
|
|
||||||
}
|
|
||||||
|
|
||||||
$links = json_decode($data->settings);
|
|
||||||
$pages = self::selectContentPages(array_keys((array)$links));
|
|
||||||
|
|
||||||
foreach ($links as $link) {
|
|
||||||
if (!isset($pages[$link->id])) {
|
|
||||||
unset($links->{$link->id});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ['links' => $links];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function selectContentPages($ids)
|
|
||||||
{
|
|
||||||
$allowedStatuses = [IContent::STATUS_PUBLIC];
|
|
||||||
|
|
||||||
if (\Auth::user()) {
|
|
||||||
$allowedStatuses[] = IContent::STATUS_PROTECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pages = Content::where('language', LaravelLocalization::getCurrentLocale())
|
|
||||||
->whereIn('id', $ids)
|
|
||||||
->whereIn('status', $allowedStatuses)
|
|
||||||
->where('moduleHandler', '!=', Article::class)
|
|
||||||
->get();
|
|
||||||
$used = [];
|
|
||||||
foreach ($pages as $page) {
|
|
||||||
$used[$page->id] = $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $used;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Widgets\SocialButtons\Presenters;
|
|
||||||
|
|
||||||
use App\Models\Widgets\Widget;
|
|
||||||
use App\Models\Widgets\WidgetType;
|
|
||||||
use App\Models\Settings as SettingsModel;
|
|
||||||
use App\CMS\Contracts\Widgets\WidgetRenderer;
|
|
||||||
use App\CMS\Widgets\SocialButtons\Presenters\Route;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Modules\Blog\Article\Entities\Article as ArticleModel;
|
|
||||||
use Modules\Blog\Article\Handlers\Article;
|
|
||||||
|
|
||||||
class SocialButtons implements WidgetRenderer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Method used for displaying widget.
|
|
||||||
*
|
|
||||||
* This method renders some HTML code for displaying.
|
|
||||||
*
|
|
||||||
* @param Widget $widget
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function render(Widget $widget)
|
|
||||||
{
|
|
||||||
return view('visitor.widgets.shareButtons.all', compact('widget'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display form for creating new instance of widget
|
|
||||||
*
|
|
||||||
* @param WidgetType $type
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function renderAddForm(WidgetType $type)
|
|
||||||
{
|
|
||||||
return view('admin.widgets.socialButtons.new', [
|
|
||||||
'type' => $type,
|
|
||||||
'widget' => new Widget(),
|
|
||||||
'settings' => new \stdClass()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display form for editing already existing widget
|
|
||||||
*
|
|
||||||
* @param Widget $widget
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function renderEditForm(Widget $widget)
|
|
||||||
{
|
|
||||||
$settings = $widget->settings;
|
|
||||||
return view('admin.widgets.socialButtons.edit', ['widget' => $widget, 'settings' => $settings]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\CMS\Widgets\SocialButtons;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Widgets\PublicWidget;
|
|
||||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Widgets\Widget;
|
|
||||||
|
|
||||||
class SocialButtons implements PublicWidget
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Name getter
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getName()
|
|
||||||
{
|
|
||||||
return 'widgets/socialButtons.widgetName';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for description
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getDescription()
|
|
||||||
{
|
|
||||||
return 'widgets/socialButtons.widgetDescription';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for presenter/renderer of this widget
|
|
||||||
*
|
|
||||||
* @return WidgetRenderer
|
|
||||||
*/
|
|
||||||
public static function getPresenter()
|
|
||||||
{
|
|
||||||
return Presenters\SocialButtons::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Request $data
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @throws MissingParameterException
|
|
||||||
*/
|
|
||||||
public static function save(Request $data)
|
|
||||||
{
|
|
||||||
//if (!isset($data->code) || empty($data->code)) {
|
|
||||||
// throw new MissingParameterException('code');
|
|
||||||
//}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Models\Language;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
class AddLanguage extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'language:add {code} {translation} {native} {script?}';
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Insert new language into database';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$code = $this->argument('code');
|
|
||||||
$translation = $this->argument('translation');
|
|
||||||
$native = $this->argument('native');
|
|
||||||
$script = $this->argument('script');
|
|
||||||
|
|
||||||
// check if language does not exist
|
|
||||||
$exist = Language::find($code);
|
|
||||||
|
|
||||||
if ($exist) {
|
|
||||||
$this->error('Language ' . $code . ' already exists!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Language::create([
|
|
||||||
'code' => $code,
|
|
||||||
'name' => $translation,
|
|
||||||
'native' => $native,
|
|
||||||
'script' => $script ? $script : 'Latn'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->line('Successfully installed.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,39 +14,33 @@ class ChangePassword extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'user:change-password {email}';
|
protected $signature = 'user:change-password {userID} {newPassword}';
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Change password for user with given e-mail';
|
protected $description = 'Change password for user with given ID';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$email = $this->argument('email');
|
$id = $this->argument('userID');
|
||||||
|
$newPassword = $this->argument('newPassword');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user = User::where(['email' => $email])
|
$user = User::findOrFail($id);
|
||||||
->first();
|
|
||||||
} catch (ModelNotFoundException $e) {
|
} catch (ModelNotFoundException $e) {
|
||||||
$this->error('Invalid user ' . $email . '.');
|
$this->error('Invalid user ID ' . $id . '. Please see table `users` for correct IDs.');
|
||||||
return;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
|
||||||
$password = $this->secret('Password');
|
|
||||||
$passwordAgain = $this->secret('Password again');
|
|
||||||
|
|
||||||
if ($password !== $passwordAgain) {
|
|
||||||
$this->error('Passwords does not match');
|
|
||||||
}
|
|
||||||
} while ($passwordAgain !== $password || strlen($password) === 0);
|
|
||||||
|
|
||||||
// set new password
|
// set new password
|
||||||
$user->password = Hash::make($password);
|
$user->password = Hash::make($newPassword);
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
$this->info('Password successfully changed.');
|
$this->info('Password successfully changed.');
|
||||||
|
|||||||
+13
-3
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands\Modules;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
@@ -12,7 +12,7 @@ class InstallAllModules extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'module:install-all';
|
protected $signature = 'install-all-modules';
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
@@ -20,6 +20,16 @@ class InstallAllModules extends Command
|
|||||||
*/
|
*/
|
||||||
protected $description = 'Crawl /modules directory and install all modules';
|
protected $description = 'Crawl /modules directory and install all modules';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
@@ -35,7 +45,7 @@ class InstallAllModules extends Command
|
|||||||
|
|
||||||
// try to install each module
|
// try to install each module
|
||||||
try {
|
try {
|
||||||
$this->call('module:install', ['name' => $moduleName]);
|
$this->call('install-module', ['name' => $moduleName]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->line('Module ' . $moduleName . ' already installed.');
|
$this->line('Module ' . $moduleName . ' already installed.');
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Module;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
|
||||||
|
|
||||||
|
class InstallModule extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'install-module {name}';
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Custom installation of CMS module. Name given as directory name in /modules.';
|
||||||
|
protected $moduleName;
|
||||||
|
protected $modulesPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->modulesPath = config('modules.paths.modules');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->moduleName = $name = $this->argument('name');
|
||||||
|
|
||||||
|
// invalid module name provided
|
||||||
|
if (!is_dir($this->modulesPath . DIRECTORY_SEPARATOR . $name)) {
|
||||||
|
throw new InvalidArgumentException('Invalid module ' . $name . '. No directory under ' . $this->modulesPath . DIRECTORY_SEPARATOR . $name . ' found!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get config
|
||||||
|
$config = $this->loadConfig();
|
||||||
|
|
||||||
|
// check if it is valid
|
||||||
|
$this->checkMandatoryFields($config);
|
||||||
|
|
||||||
|
// all mandatory fields are present, we can write it into database and create modules.json
|
||||||
|
$this->installModule($config);
|
||||||
|
|
||||||
|
// inform user
|
||||||
|
$this->line('Module ' . $name . ' successfuly installed');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load config from Config/config.php in module files. We cannot use config() because the file have not published
|
||||||
|
* yet.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function loadConfig()
|
||||||
|
{
|
||||||
|
// we cannot rely on config() helper, because this module does not have to be published
|
||||||
|
$config = @include($this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'config.php');
|
||||||
|
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if config contains all mandatory entries.
|
||||||
|
*
|
||||||
|
* @param $config
|
||||||
|
*/
|
||||||
|
private function checkMandatoryFields($config)
|
||||||
|
{
|
||||||
|
$fields = ['providers', 'handler', 'name', 'files', 'alias'];
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
if (!isset($config[$field])) {
|
||||||
|
throw new MissingMandatoryParametersException('Missing *' . $field . '* in config file! Cannot install ' . $this->moduleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs module into database.
|
||||||
|
*
|
||||||
|
* This method calls Module::install, which handles specific installation of module. In this way we should be able
|
||||||
|
* to install any module even with some other database structures.
|
||||||
|
*
|
||||||
|
* @param $config
|
||||||
|
*
|
||||||
|
* @return Module
|
||||||
|
* @throws \ErrorException
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
private function installModule($config)
|
||||||
|
{
|
||||||
|
$name = isset($config['translatedName']) ? $config['translatedName'] : $config['name'];
|
||||||
|
$description = isset($config['translatedDescription']) ? $config['translatedDescription'] : null;
|
||||||
|
|
||||||
|
// check if module is not installed yet
|
||||||
|
$exists = Module::where('handler', $config['handler'])
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($exists) {
|
||||||
|
throw new \Exception('Module ' . $config['name'] . ' already exists in database.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = [
|
||||||
|
'staticName' => $this->moduleName,
|
||||||
|
'providers' => $config['providers'],
|
||||||
|
'aliases' => isset($config['aliases']) ? $config['aliases'] : [],
|
||||||
|
'order' => isset($config['order']) ? $config['order'] : 0,
|
||||||
|
'files' => $config['files']
|
||||||
|
|
||||||
|
];
|
||||||
|
$module = Module::install($name, $config['alias'], $description, $config['handler'], $settings);
|
||||||
|
|
||||||
|
return $module;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Modules;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class CreateNew extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'module:new
|
|
||||||
{name : module name}
|
|
||||||
{parentModule? : name of parent module}
|
|
||||||
{--entity= : entity}';
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Create new CMS module.';
|
|
||||||
protected $moduleName;
|
|
||||||
protected $moduleNamespace;
|
|
||||||
protected $entity;
|
|
||||||
protected $entityNamespace;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$defaultEntityNamespace = $this->loadArguments();
|
|
||||||
$path = preg_replace('|/{2,}|i', '/', config('modules.paths.modules') . '/' . $this->moduleNamespace);
|
|
||||||
|
|
||||||
if (is_dir($path)) {
|
|
||||||
$this->error('Module already exists in ' . $path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy stub files
|
|
||||||
\File::copyDirectory(config('modules.paths.stubs'), $path);
|
|
||||||
|
|
||||||
$files = \File::allFiles($path);
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$newName = str_replace('stub', 'php', $this->replacePlaceholders($file->getPathname()));
|
|
||||||
|
|
||||||
// ignore new entity when using existing entity
|
|
||||||
if ($this->entityNamespace != $defaultEntityNamespace && Str::contains('Entities', $file)) {
|
|
||||||
\File::delete($file);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// rename file
|
|
||||||
\File::move($file, $newName);
|
|
||||||
|
|
||||||
// change its content
|
|
||||||
$content = file_get_contents($newName);
|
|
||||||
$content = $this->replacePlaceholders($content);
|
|
||||||
file_put_contents($newName, $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->info('Module successfully created.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find and replace all placeholders in given content
|
|
||||||
*
|
|
||||||
* @param $content
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
private function replacePlaceholders($content)
|
|
||||||
{
|
|
||||||
$replace = [
|
|
||||||
'$Module$' => $this->moduleName,
|
|
||||||
'$ModuleNamespace$' => str_replace('/', '\\', $this->moduleNamespace),
|
|
||||||
'$module$' => strtolower($this->moduleName),
|
|
||||||
'$EntityNamespace$' => $this->entityNamespace,
|
|
||||||
'$Entity$' => $this->entity
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($replace as $what => $for) {
|
|
||||||
$content = str_replace($what, $for, $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load command arguments
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function loadArguments()
|
|
||||||
{
|
|
||||||
$parent = $this->argument('parentModule');
|
|
||||||
$this->moduleName = $moduleName = $this->argument('name');
|
|
||||||
$this->moduleNamespace = trim($parent . '/' . $moduleName, '/');
|
|
||||||
|
|
||||||
$entity = $this->option('entity');
|
|
||||||
|
|
||||||
$defaultEntityNamespace = '\\Modules\\' . str_replace('/', '\\', $this->moduleNamespace) . '\Entities\\';
|
|
||||||
|
|
||||||
if (!empty($entity)) {
|
|
||||||
$parts = explode('\\', $entity);
|
|
||||||
$this->entity = $parts[count($parts) - 1];
|
|
||||||
unset($parts[count($parts) - 1]);
|
|
||||||
$this->entityNamespace = implode('\\', $parts);
|
|
||||||
} else {
|
|
||||||
$this->entityNamespace = $defaultEntityNamespace;
|
|
||||||
$this->entity = $this->moduleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $defaultEntityNamespace;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,193 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Modules;
|
|
||||||
|
|
||||||
use App\Models\Module;
|
|
||||||
use App\ModuleManager\Installer;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Illuminate\Support\Facades\File;
|
|
||||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
|
||||||
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
|
|
||||||
|
|
||||||
class InstallModule extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'module:install {name} {parentModuleId?}';
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Custom installation of CMS module. Name given as directory name in /modules.';
|
|
||||||
protected $moduleName;
|
|
||||||
protected $parentModuleId;
|
|
||||||
protected $modulesPath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
$this->modulesPath = config('modules.paths.modules');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$this->moduleName = $name = $this->argument('name');
|
|
||||||
$this->parentModuleId = $this->argument('parentModuleId');
|
|
||||||
|
|
||||||
// invalid module name provided
|
|
||||||
if (!is_dir($this->modulesPath . DIRECTORY_SEPARATOR . $name)) {
|
|
||||||
throw new InvalidArgumentException('Invalid module ' . $name . '. No directory under ' . $this->modulesPath . DIRECTORY_SEPARATOR . $name . ' found!');
|
|
||||||
}
|
|
||||||
|
|
||||||
// get config
|
|
||||||
$config = $this->loadConfig();
|
|
||||||
|
|
||||||
if (empty($config))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// check if it is valid
|
|
||||||
$this->checkMandatoryFields($config);
|
|
||||||
|
|
||||||
// all mandatory fields are present, we can write it into database and create modules.json
|
|
||||||
$this->installModule($config);
|
|
||||||
|
|
||||||
// delete cache
|
|
||||||
Cache::forget('enabled-modules');
|
|
||||||
Cache::forget('module-handler-to-id-enumeration');
|
|
||||||
|
|
||||||
// inform user
|
|
||||||
$this->line('Module ' . $name . ' successfuly installed');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load config from Config/config.php in module files. We cannot use config() because the file have not published
|
|
||||||
* yet.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
*/
|
|
||||||
private function loadConfig()
|
|
||||||
{
|
|
||||||
$basePath = $this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR;
|
|
||||||
$path = $basePath . 'Config' . DIRECTORY_SEPARATOR . 'config.php';
|
|
||||||
|
|
||||||
if (basename($basePath) == 'Database')
|
|
||||||
return [];
|
|
||||||
|
|
||||||
// check if module has Config/config.php file
|
|
||||||
if (!file_exists($path)) {
|
|
||||||
$path = $basePath . 'info.php';
|
|
||||||
|
|
||||||
// does module has info.php? If not, throw error, because we have no info about this module
|
|
||||||
if (!file_exists($path)) {
|
|
||||||
throw new FileNotFoundException('Missing config file. Create /Config/config.php or /info.php (for module with submodules) in ' . $basePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we cannot rely on config() helper, because this module does not have to be published
|
|
||||||
$config = include($path);
|
|
||||||
|
|
||||||
return $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if config contains all mandatory entries.
|
|
||||||
*
|
|
||||||
* @param $config
|
|
||||||
*/
|
|
||||||
private function checkMandatoryFields($config)
|
|
||||||
{
|
|
||||||
$fields = ['name'];
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
if (!isset($config[$field])) {
|
|
||||||
throw new MissingMandatoryParametersException('Missing *' . $field . '* in config file! Cannot install ' . $this->moduleName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Installs module into database.
|
|
||||||
*
|
|
||||||
* This method calls Module::install, which handles specific installation of module. In this way we should be able
|
|
||||||
* to install any module even with some other database structures.
|
|
||||||
*
|
|
||||||
* @param $config
|
|
||||||
*
|
|
||||||
* @return Module
|
|
||||||
* @throws \ErrorException
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
private function installModule($config)
|
|
||||||
{
|
|
||||||
$name = isset($config['translatedName']) ? $config['translatedName'] : $config['name'];
|
|
||||||
$description = isset($config['translatedDescription']) ? $config['translatedDescription'] : null;
|
|
||||||
$alias = isset($config['alias']) ? $config['alias'] : null;
|
|
||||||
$handler = isset($config['handler']) ? $config['handler'] : null;
|
|
||||||
$providers = isset($config['providers']) ? $config['providers'] : [];
|
|
||||||
|
|
||||||
// check if module is not installed yet
|
|
||||||
$module = Module::where('name', $name);
|
|
||||||
|
|
||||||
if ($handler) {
|
|
||||||
$module = $module->where('handler', $handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
$module = $module->first();
|
|
||||||
|
|
||||||
if ($module && (!isset($config['hasSubmodules']) || !$config['hasSubmodules'])) {
|
|
||||||
throw new \Exception('Module ' . $config['name'] . ' already exists in database.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($module)) {
|
|
||||||
// insert module into database
|
|
||||||
$settings = [
|
|
||||||
'staticName' => $this->moduleName,
|
|
||||||
'providers' => $providers,
|
|
||||||
'order' => isset($config['order']) ? $config['order'] : 0,
|
|
||||||
'files' => isset($config['files']) ? $config['files'] : []
|
|
||||||
];
|
|
||||||
|
|
||||||
$module = Installer::install($name, $alias, $description, $handler, $this->parentModuleId, $settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to install submodules
|
|
||||||
if (isset($config['hasSubmodules']) && $config['hasSubmodules']) {
|
|
||||||
$this->installSubmodules($this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName, $module);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crawl all subdirectories in module and try to install submodules
|
|
||||||
*
|
|
||||||
* @param $path string path to module base directory
|
|
||||||
* @param $parentModule
|
|
||||||
*/
|
|
||||||
private function installSubmodules($path, Module $parentModule)
|
|
||||||
{
|
|
||||||
$submodules = File::directories($path);
|
|
||||||
|
|
||||||
foreach ($submodules as $submodulePath) {
|
|
||||||
$submodule = str_replace($this->modulesPath . DIRECTORY_SEPARATOR, '', $submodulePath);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->call('module:install', ['name' => $submodule, 'parentModuleId' => $parentModule->id]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\CMS\Enumerations\UserRoles;
|
use App\Enumerations\UserRoles;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
class NewUser extends Command
|
class NewUser extends Command
|
||||||
{
|
{
|
||||||
@@ -14,7 +15,7 @@ class NewUser extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'user:new {email}';
|
protected $signature = 'user:new {email} {password} {role}';
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
@@ -24,37 +25,20 @@ class NewUser extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$email = $this->argument('email');
|
$email = $this->argument('email');
|
||||||
|
$password = $this->argument('password');
|
||||||
|
$role = $this->argument('role');
|
||||||
|
|
||||||
// check if username is really email
|
// check if given role is valid
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
||||||
$this->error($email . ' is not a valid e-mail!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ask for password
|
|
||||||
do {
|
|
||||||
$password = $this->secret('Password');
|
|
||||||
$passwordAgain = $this->secret('Password again');
|
|
||||||
|
|
||||||
if ($password !== $passwordAgain) {
|
|
||||||
$this->error('Passwords does not match');
|
|
||||||
}
|
|
||||||
} while ($passwordAgain !== $password || strlen($password) === 0);
|
|
||||||
|
|
||||||
// ask for role
|
|
||||||
$roles = UserRoles::getSimple();
|
$roles = UserRoles::getSimple();
|
||||||
do {
|
if (!in_array($role, $roles)) {
|
||||||
$role = $this->ask('Role (default ' . User::ROLE_ADMIN . '): ', User::ROLE_ADMIN);
|
throw new InvalidArgumentException('Invalid role specified. valid roles are: ' . implode(', ', $roles));
|
||||||
|
}
|
||||||
// check if given role is valid
|
|
||||||
if (!in_array($role, $roles)) {
|
|
||||||
$this->error('Invalid role specified. valid roles are: ' . implode(', ', $roles));
|
|
||||||
}
|
|
||||||
} while (!in_array($role, $roles));
|
|
||||||
|
|
||||||
// create new user
|
// create new user
|
||||||
$user = new User();
|
$user = new User();
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
class PublishTemplateResources extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'template:publish';
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Publish assets and views for currently set template';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$this->call('cache:clear');
|
|
||||||
$this->call('vendor:publish', ['--tag' => 'module-views', '--force' => true]);
|
|
||||||
$this->call('vendor:publish', ['--tag' => 'public-assets', '--force' => true]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Models\Module;
|
|
||||||
use App\ModuleManager\Installer;
|
|
||||||
use App\ModuleManager\Uninstaller;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
||||||
|
|
||||||
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) {
|
|
||||||
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $current->module_settings['staticName'] . '.');
|
|
||||||
$confirm = $this->confirm('Uninstall it and install *' . trans($config['name']) . '*? All data associated with installed template will be lost!');
|
|
||||||
|
|
||||||
if ($confirm) {
|
|
||||||
$this->line('Uninstalling ' . $current->name . '.');
|
|
||||||
|
|
||||||
Uninstaller::uninstall($current);
|
|
||||||
} else {
|
|
||||||
$this->line('Aborting installation.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Installer::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete cached current template
|
|
||||||
Cache::forget('current-template');
|
|
||||||
|
|
||||||
// theme written
|
|
||||||
$this->line('Template successfully set up.');
|
|
||||||
|
|
||||||
// run again artisan for publishing resources
|
|
||||||
// it cannot be done using $this->call, because we need to load different template into service providers
|
|
||||||
if ($publish) {
|
|
||||||
exec('php artisan vendor:publish');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<?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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\CMS\Helpers\CurrentTemplate;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
class TemplateInfo extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'template:info';
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Show details about currently set template';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$template = CurrentTemplate::get();
|
|
||||||
|
|
||||||
if (is_null($template)) {
|
|
||||||
$this->error('No template set.');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->line($template->name);
|
|
||||||
$this->line($template->handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\File;
|
|
||||||
|
|
||||||
class TranslateAll extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'translate:all';
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Checks for missing translations in all modules.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$this->call('translate:dir', ['dir' => 'resources/lang']);
|
|
||||||
|
|
||||||
$this->crawlDirectory('modules');
|
|
||||||
$this->crawlDirectory('templates', ['templates/Base']);
|
|
||||||
$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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\File;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class TranslateDirectory extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'translate:dir {dir}';
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Checks for missing translations in given directory.';
|
|
||||||
/**
|
|
||||||
* @var array All translations
|
|
||||||
*/
|
|
||||||
protected $translations = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$dir = rtrim($this->argument('dir'), '/');
|
|
||||||
$defaultLocales = config('app.fallback_locale');
|
|
||||||
$currentLocales = config('app.locale');
|
|
||||||
|
|
||||||
$defaultLocalesDir = base_path($dir . '/' . $defaultLocales);
|
|
||||||
$currentLocalesDir = base_path($dir . '/' . $currentLocales);
|
|
||||||
|
|
||||||
if (!is_dir($defaultLocalesDir)) {
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_dir($currentLocalesDir)) {
|
|
||||||
File::makeDirectory($currentLocalesDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->compareTranslationsInDirectory($defaultLocalesDir, $currentLocalesDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crawl given defaul directory and compare all files in default and current directory.
|
|
||||||
*
|
|
||||||
* @param $defaultDir string path to directory with default (fallback) locales
|
|
||||||
* @param $currentDir string path to directory with currently selected localse
|
|
||||||
*/
|
|
||||||
private function compareTranslationsInDirectory($defaultDir, $currentDir)
|
|
||||||
{
|
|
||||||
$files = File::files($defaultDir);
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if (!Str::endsWith($file, '.php')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fileName = basename($file);
|
|
||||||
$default = include($file);
|
|
||||||
$checked = file_exists($currentDir . '/' . $fileName) ? include $currentDir . '/' . $fileName : [];
|
|
||||||
$this->translations = &$checked;
|
|
||||||
|
|
||||||
$this->checkForMissingTranslations($default, $checked, $currentDir, $fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// iterate over directories
|
|
||||||
$this->crawlSubdirectories($defaultDir, $currentDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check translations and ask for missing ones.
|
|
||||||
*
|
|
||||||
* @param $default
|
|
||||||
* @param $checked
|
|
||||||
* @param $currentLocalesDir
|
|
||||||
* @param $fileName
|
|
||||||
*/
|
|
||||||
private function checkForMissingTranslations($default, &$checked, $currentLocalesDir, $fileName)
|
|
||||||
{
|
|
||||||
foreach ($default as $key => $translation) {
|
|
||||||
if (!isset($checked[$key])) {
|
|
||||||
// translate only plain text fields
|
|
||||||
if (is_array($default[$key])) {
|
|
||||||
|
|
||||||
if (!isset($checked[$key])) {
|
|
||||||
$checked[$key] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->checkForMissingTranslations($default[$key], $checked[$key], $currentLocalesDir, $fileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->info($fileName . ':' . $key);
|
|
||||||
$this->line($translation);
|
|
||||||
$newTranslation = $this->ask('Translate');
|
|
||||||
|
|
||||||
$checked[$key] = $newTranslation;
|
|
||||||
$this->saveTranslation($currentLocalesDir, $fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new/reset file and fill it with translations
|
|
||||||
*
|
|
||||||
* @param $checked
|
|
||||||
* @param $dir
|
|
||||||
* @param $fileName
|
|
||||||
*/
|
|
||||||
private function saveTranslation($dir, $fileName)
|
|
||||||
{
|
|
||||||
$file = $dir . '/' . $fileName;
|
|
||||||
|
|
||||||
$this->resetFile($file);
|
|
||||||
$this->writeRow('<?php', null, $file, false);
|
|
||||||
$this->writeRow('return [', null, $file, false);
|
|
||||||
|
|
||||||
// write real translation data
|
|
||||||
$this->writeTranslations($this->translations, $dir, $fileName);
|
|
||||||
|
|
||||||
$this->writeRow('];', '', $file, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write translation as PHP array
|
|
||||||
*
|
|
||||||
* @param $checked
|
|
||||||
* @param $dir
|
|
||||||
* @param $fileName
|
|
||||||
*/
|
|
||||||
private function writeTranslations($checked, $dir, $fileName)
|
|
||||||
{
|
|
||||||
$file = $dir . '/' . $fileName;
|
|
||||||
|
|
||||||
ksort($checked);
|
|
||||||
|
|
||||||
foreach ($checked as $key => $value) {
|
|
||||||
if (is_array($value)) {
|
|
||||||
$this->writeRow($key, '[', $file, false);
|
|
||||||
$this->writeTranslations($value, $dir, $fileName);
|
|
||||||
$this->writeRow('],', null, $file, false);
|
|
||||||
} else {
|
|
||||||
$this->writeRow($key, $value, $file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets content of given file
|
|
||||||
*
|
|
||||||
* @param $file
|
|
||||||
*/
|
|
||||||
private function resetFile($file)
|
|
||||||
{
|
|
||||||
file_put_contents($file, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write row with translations
|
|
||||||
*
|
|
||||||
* @param $key
|
|
||||||
* @param $value
|
|
||||||
* @param $file
|
|
||||||
* @param bool $arrayItem
|
|
||||||
*/
|
|
||||||
private function writeRow($key, $value, $file, $arrayItem = true)
|
|
||||||
{
|
|
||||||
if ($value != null) {
|
|
||||||
if ($arrayItem) {
|
|
||||||
$value = strpos($value, '"') !== false ? '\'' . $value . '\'' : '"' . $value . '"';
|
|
||||||
$value .= ",\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
file_put_contents($file, '"' . $key . '" => ' . $value, FILE_APPEND);
|
|
||||||
} else {
|
|
||||||
file_put_contents($file, $key . "\n", FILE_APPEND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crawl subdirectories and compare translations there
|
|
||||||
*
|
|
||||||
* @param $defaultDir
|
|
||||||
* @param $currentDir
|
|
||||||
*/
|
|
||||||
private function crawlSubdirectories($defaultDir, $currentDir)
|
|
||||||
{
|
|
||||||
$directories = File::directories($defaultDir);
|
|
||||||
|
|
||||||
foreach ($directories as $directory) {
|
|
||||||
$dirname = basename($directory);
|
|
||||||
|
|
||||||
if (!is_dir($currentDir . '/' . $dirname)) {
|
|
||||||
File::makeDirectory($currentDir . '/' . $dirname);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->compareTranslationsInDirectory($directory, $currentDir . '/' . $dirname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+6
-12
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
use App\Console\Commands\Modules\CreateNew;
|
|
||||||
use App\Console\Commands\PublishTemplateResources;
|
|
||||||
use App\Console\Commands\TemplateInfo;
|
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
@@ -18,16 +15,11 @@ class Kernel extends ConsoleKernel
|
|||||||
protected $commands = [
|
protected $commands = [
|
||||||
Commands\NewUser::class,
|
Commands\NewUser::class,
|
||||||
Commands\ChangePassword::class,
|
Commands\ChangePassword::class,
|
||||||
CreateNew::class,
|
Commands\InstallModule::class,
|
||||||
Commands\Modules\InstallModule::class,
|
Commands\InstallAllModules::class,
|
||||||
Commands\Modules\InstallAllModules::class,
|
// Commands\SetupDatabase::class,
|
||||||
Commands\TranslateDirectory::class,
|
|
||||||
Commands\TranslateAll::class,
|
|
||||||
Commands\InitDatabaseSchema::class,
|
Commands\InitDatabaseSchema::class,
|
||||||
Commands\SetTemplate::class,
|
Commands\SetTheme::class,
|
||||||
Commands\AddLanguage::class,
|
|
||||||
PublishTemplateResources::class,
|
|
||||||
TemplateInfo::class
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,5 +31,7 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
|
// $schedule->command('inspire')
|
||||||
|
// ->hourly();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\CustomFields;
|
||||||
|
|
||||||
|
class BaseField {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\CustomFields;
|
||||||
|
|
||||||
|
class Date extends BaseField {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\CustomFields;
|
||||||
|
|
||||||
|
class Number extends BaseField {
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user