Author SHA1 Message Date
Michal Kváček f51dd9458c FEATURE: change default email template 2017-10-29 21:45:01 +01:00
Michal Kváček 962225080d FEATURE: make intro text white 2017-10-29 21:38:43 +01:00
789 changed files with 123928 additions and 44283 deletions
+1 -1
View File
@@ -16,4 +16,4 @@ MAIL_PASSWORD=
SITE_URL=/
UPLOAD_URL=/public/uploads
THUMBNAIL_URL=/public/uploads/thumbnails
THUMBNAILS_URL=/uploads/thumbnails
-8
View File
@@ -1,5 +1,4 @@
# published files from modules
/modules
/public/modules
/public/assets
/resources/views/modules
@@ -28,10 +27,3 @@
# meta information created by installer
.install
/node_modules/
/public/css/
/public/js
/public/fonts
/bower_components
.sass-cache
!/resources/views/vendor/
@@ -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,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);
}
-21
View File
@@ -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 = []);
}
-42
View File
@@ -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,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);
}
-20
View File
@@ -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;
}
}
-142
View File
@@ -1,142 +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\CMS\Repositories\Module;
use App\Models\ActionLog\ActionLog;
use App\Models\Content\Content;
use App\Models\FileManager\File;
use App\Models\Settings;
use App\Models\Templates\Template;
use App\Models\User;
use App\Models\Widgets\Widget;
use App\Models\Widgets\WidgetArea;
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) use ($user) {
// $menu->route('admin.dashboard', trans('admin/mainMenu.dashboard'), [], 10, ['icon' => 'fa fa-fw fa-dashboard']);
/**
* Content pages
* Submenus can be registered later
*/
$contentModules = app(Module::class)->getContentModules();
if ($user->can('manage', Content::class) && !$contentModules->isEmpty()) {
$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
*/
if ($user->can('manage', File::class)) {
$menu->route('upload.overview', trans('admin/mainMenu.fileManager'), [], 40, ['icon' => 'fa fa-fw fa-folder']);
}
/**
* Widgets and widget areas
*/
if ($user->can('manage', Widget::class) || $user->can('manage', WidgetArea::class)) {
$menu->dropdown(trans('admin/mainMenu.widgets'), function ($sub) use ($user) {
// create list of all widget types
$widgets = WidgetTypes::getWithTranslations();
if (!empty($widgets) && $user->can('create', Widget::class)) {
$sub->dropdown(trans('admin/mainMenu.newWidget'), function ($sub) use ($widgets) {
$i = 1;
foreach ($widgets as $type => $name) {
$sub->route('widgets.new', $name, ['type' => $type], $i++);
}
}, 10, ['icon' => 'fa fa-fw fa-plus']);
}
if ($user->can('manage', Widget::class)) {
$sub->route('widgets.overview', trans('admin/mainMenu.widgetsOverview'), [], 20, ['icon' => 'fa fa-fw fa-list']);
}
// menu for widget areas
if ($user->can('manage', WidgetArea::class)) {
$sub->dropdown(trans('admin/mainMenu.widgetAreas'), function ($sub) use ($user) {
if ($user->can('create', WidgetArea::class)) {
$sub->route('widgetareas.new', trans('admin/mainMenu.newWidgetArea'), [], 1, ['icon' => 'fa fa-fw fa-plus']);
}
$sub->route('widgetareas.overview', trans('admin/mainMenu.widgetAreaOverview'), [], 2, ['icon' => 'fa fa-fw fa-list']);
}, 50, ['icon' => 'fa fa-fw fa-object-group']);
}
}, 50, ['icon' => 'fa fa-fw fa-puzzle-piece']);
}
/**
* Divide system entries and other links in menu
*/
$menu->addDivider(9999);
$menu->dropdown(trans('admin/mainMenu.system'), function ($sub) use ($user) {
/**
* User management
*/
if ($user->can('manage', User::class)) {
$sub->dropdown(trans('admin/mainMenu.userManagement'), function ($sub) use ($user) {
if ($user->can('create', User::class)) {
$sub->route('users.new', trans('admin/mainMenu.newUser'), [], 10, ['icon' => 'fa fa-fw fa-user-plus']);
}
$sub->route('users.overview', trans('admin/mainMenu.usersOverview'), [], 30, ['icon' => 'fa fa-fw fa-users']);
}, 20, ['icon' => 'fa fa-fw fa-users']);
}
/**
* Templates
*/
if ($user->can('manage', Template::class)) {
$templatePaths = TemplatePathsHumanReadableRootOnly::getWithTranslations();
if (!empty($templatePaths)) {
$sub->dropdown(trans('admin/mainMenu.templates'), function ($sub) use ($templatePaths) {
$i = 1;
foreach ($templatePaths as $id => $name) {
$sub->route('templates.overview', $name, ['id' => $id], $i++);
}
}, 60, ['icon' => 'fa fa-fw fa-file-code-o']);
}
}
if ($user->can('manage', ActionLog::class)) {
$sub->route('log.overview', trans('admin/mainMenu.actionLog'), [], 70, ['icon' => 'fa fa-fw fa-history']);
}
if ($user->can('manage', Settings::class)) {
$sub->route('settings.overview', trans('admin/mainMenu.settings'), [], 80, ['icon' => 'fa fa-fw fa-gear']);
$sub->route('permissions.index', trans('admin/mainMenu.permissions'), [], 90, ['icon' => 'fa fa-fw fa-key']);
}
}, 10000, ['icon' => 'fa fa-fw fa-gears']);
});
// create menu with user profile
\Menu::create('profileMenu', function ($menu) use ($user) {
$menu->route('users.detail', trans('admin/userManagement.profile'), ['user' => $user], 10, ['icon' => 'fa fa-fw fa-user icon']);
$menu->addDivider(999);
$menu->route('logout', trans('admin/common.logout'), [], 1000, ['icon' => 'fa fa-fw fa-power-off icon']);
});
}
}
-39
View File
@@ -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);
}
}
-44
View File
@@ -1,44 +0,0 @@
<?php
namespace App\CMS\Handlers\Search;
use App\Models\Content\Content as ContentModel;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
class Content extends Search
{
/**
* Search for given patttern/term
*
* @param string $term searched word
*
* @return array|\Illuminate\Database\Eloquent\Collection|Collection|static[]
*/
public function search($term)
{
if (Auth::user()
->cannot('manage', ContentModel::class)) {
return new Collection();
}
$token = $this->tokenize($term);
return ContentModel::where('pageContent', 'LIKE', $token)
->orWhere('metaDescription', 'LIKE', $token)
->orWhere('metaKeywords', 'LIKE', $token)
->orWhere('title', 'LIKE', $token)
->orWhere('url', 'LIKE', $token)
->get();
}
public function getId()
{
return 'content';
}
public function getName()
{
return trans('search.content');
}
}
@@ -1,22 +0,0 @@
<?php
namespace App\CMS\Handlers\Search\Presenters;
use App\CMS\Enumerations\ContentStatuses;
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
use App\Models\Content\Content;
class AdminContent implements SearchPresenterHandler
{
public function render($foundItems)
{
if (\Auth::user()
->cannot('manage', Content::class)) {
return null;
}
return view('admin.search.results.content', [
'pages' => $foundItems,
'statuses' => ContentStatuses::getWithTranslations(),
]);
}
}
-92
View File
@@ -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']);
}
}
-49
View File
@@ -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;
}
}
-49
View File
@@ -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;
}
}
-33
View File
@@ -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;
}
}
-18
View File
@@ -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,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'
];
}
}
-64
View File
@@ -1,64 +0,0 @@
<?php
namespace App\CMS\ModuleManager;
use App\CMS\Contracts\Modules\AppHandler;
use App\CMS\Contracts\Modules\TemplateHandler;
use App\Models\Module;
use Illuminate\Support\Facades\App;
class Installer
{
/**
* Create new module in database
*
* @param $name
* @param $alias
* @param string $description
* @param null $handler
* @param $parentModuleId
* @param array $settings
*
* @return Module
* @throws \ErrorException
*/
public static function install($name, $alias, $staticName, $description, $handler, $parentModuleId, $settings)
{
// check if user does not want to install module in runtime
if (!App::runningInConsole()) {
throw new \ErrorException('Modules can be installed only via Artisan!');
}
$managesContent = $handler ? in_array(AppHandler::class, class_implements($handler)) : false;
$isTemplate = $handler ? in_array(TemplateHandler::class, class_implements($handler)) : false;
$supportCategories = $managesContent ? call_user_func([$handler, 'supportCategories']) : false;
if ($parentModuleId) {
$parentModule = Module::findOrFail($parentModuleId);
$parentModule->has_submodules = true;
$parentModule->save();
}
// insert module into database
$module = Module::create([
'name' => $name,
'description' => $description,
'handler' => $handler,
'static_name' => $staticName,
'manages_content' => $managesContent,
'support_categories' => $supportCategories,
'alias' => $alias,
'module_settings' => $settings,
'parent_id' => $parentModuleId ? $parentModuleId : null,
'enabled' => 1,
'is_template' => $isTemplate
]);
// install something module-specific
if ($handler && is_callable([$handler, 'install'])) {
call_user_func([$handler, 'install']);
}
return $module;
}
}
@@ -1,44 +0,0 @@
<?php
namespace App\CMS\ModuleManager\Providers;
use App\CMS\Repositories\Module as ModuleRepository;
use Illuminate\Support\ServiceProvider;
class ModuleManager extends ServiceProvider
{
/**
* Bootstrap the application services.
* @return void
*/
public function boot()
{
// this service provider needs published config - config is merged right after this service provider
$modules = app(ModuleRepository::class)->getOnlyModules();
// iterate over all modules and enable or disable them
foreach ($modules as $module) {
if (isset($module->module_settings['providers']) && !empty($module->module_settings['providers'])) {
foreach ($module->module_settings['providers'] as $provider) {
$this->app->register($provider);
}
}
// include files (if any)
if (isset($module->module_settings['files']) && !empty($module->module_settings['files'])) {
foreach ($module->module_settings['files'] as $file) {
include config('modules.paths.modules') . '/' . $module->static_name . '/' . $file;
}
}
}
}
/**
* Register the application services.
* @return void
*/
public function register()
{
}
}
-60
View File
@@ -1,60 +0,0 @@
<?php
namespace App\CMS\ModuleManager;
use App\Models\Module;
use App\Models\Templates\TemplatePath;
use Illuminate\Support\Facades\App;
class Uninstaller {
/**
* Delete module from database and uninstall its dependencies
*
* @param Module $module
*
* @throws \ErrorException
*/
public static function uninstall(Module $module)
{
// check if user does not want to install module in runtime
if (!App::runningInConsole()) {
throw new \ErrorException('Modules can be uninstalled only via Artisan!');
}
// delete everything in /resources/views/visitor
if ($module->is_template) {
self::deleteDirectory(resource_path('views/visitor'));
self::deleteDirectory(resource_path('views/modules'));
self::deleteDirectory(public_path('assets'));
// delete all template paths
TemplatePath::getQuery()
->delete();
}
if ($module->handler && is_callable([$module->handler, 'uninstall'])) {
call_user_func([$module->handler, 'uninstall'], $module);
}
$module->delete();
}
/**
* Delete directory when uninstalling module.
*
* @param $directory
*
* @throws \ErrorException
*/
private static function deleteDirectory($directory)
{
if (!is_dir($directory)) {
return;
}
$success = \File::deleteDirectory($directory, true);
if (!$success) {
throw new \ErrorException('Cannot delete ' . $directory);
}
}
}
-12
View File
@@ -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\BaseHandler;
use App\Models\User;
class $Module$Handler extends BaseHandler
{
/**
* 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();
}
}
-25
View File
@@ -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
-168
View File
@@ -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++;
}
}
}
-71
View File
@@ -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);
}
}
}
-132
View File
@@ -1,132 +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)
->with('module')
->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;
}
}
-16
View File
@@ -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);
}
}
-104
View File
@@ -1,104 +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;
use Illuminate\Support\Facades\Cache;
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 getContentModules()
{
return Cache::remember('enabled-content-modules', 3600, function () {
return ModuleModel::where('enabled', true)
->where('manages_content', true)
->get();
});
}
public function getCreateContentTitle(ModuleModel $module)
{
$pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]);
$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 Cache::rememberForever('enabled-modules-and-template', function () {
return ModuleModel::where('enabled', true)
->get();
});
}
public function getOnlyModules()
{
return Cache::rememberForever('enabled-modules', function () {
return ModuleModel::where('enabled', true)
->where('is_template', false)
->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,15 +0,0 @@
<?php
namespace App\CMS\Repositories\Permissions;
use App\Models\Permissions\Permission as PermissionModel;
class Permission
{
public function getRootPermissions()
{
return PermissionModel::whereNull('parent_id')
->with('subpermissions')
->get();
}
}
-12
View File
@@ -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);
}
}
-111
View File
@@ -1,111 +0,0 @@
<?php
namespace App\CMS\Repositories\Settings;
use App\Models\Settings as SettingsModel;
use Illuminate\Support\Facades\Cache;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class Settings
{
/**
* Prepares common query for selecting settings
* @return mixed
*/
protected function getSettingsQuery()
{
return SettingsModel::select(['key', 'value', 'language'])
->where('language', LaravelLocalization::getCurrentLocale())
->orWhere('language', null)
->orderBy('language', 'ASC');
}
/**
* Load all settings
* @return \stdClass
*/
public function getAll()
{
$settings = $this->getSettingsQuery()
->get();
return $this->returnPairs($settings);
}
/**
* Get all settings with language info
* @return \stdClass
*/
public function getAllWithLanguage()
{
$settings = $this->getSettingsQuery()
->get();
$data = new \stdClass();
foreach ($settings as $conf) {
$data->{$conf->key} = [
'val' => $conf->value,
'lang' => $conf->language
];
}
return $data;
}
/**
* Load only config for views
* @return \stdClass
*/
public function getForView()
{
$settings = $this->getSettingsQuery()
->where('load_into_views', 1)
->get();
return $this->returnPairs($settings);
}
/**
* From pair <key, value> create object key => value
*
* @param $settings
*
* @return \stdClass
*/
private function returnPairs($settings)
{
$data = new \stdClass();
foreach ($settings as $conf) {
$data->{$conf->key} = $conf->value;
}
return $data;
}
/**
* Save settings
*
* @param array $data
*/
public function save(array $data)
{
$commonSettings = isset($data['commonSettings']) ? $data['commonSettings'] : [];
unset($data['commonSettings']);
foreach ($data as $key => $value) {
// select language for this setting key
$language = isset($commonSettings[$key]) ? null : LaravelLocalization::getCurrentLocale();
$setting = SettingsModel::firstOrNew(['language' => $language, 'key' => $key]);
if ($setting->value == $value) {
continue;
}
// set value and save or delete
$setting->value = $value;
empty($value) ? $setting->delete() : $setting->save();
}
Cache::forget('settings');
}
}
@@ -1,79 +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;
use Illuminate\Support\Facades\Cache;
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 Cache::rememberForever('templates-for-module', function () use ($module) {
return TemplateModel::where('module_id', $module->id)
->select(['template_name', 'name', 'description'])
->get();
});
}
}
-65
View File
@@ -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;
}
}
-52
View File
@@ -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,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 [];
}
}
+2
View File
@@ -32,6 +32,8 @@ class AddLanguage extends Command
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
+11 -17
View File
@@ -14,39 +14,33 @@ class ChangePassword extends Command
*
* @var string
*/
protected $signature = 'user:change-password {email}';
protected $signature = 'user:change-password {userID} {newPassword}';
/**
* The console command description.
*
* @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.
*
* @return mixed
*/
public function handle()
{
$email = $this->argument('email');
$id = $this->argument('userID');
$newPassword = $this->argument('newPassword');
try {
$user = User::where(['email' => $email])
->first();
$user = User::findOrFail($id);
} catch (ModelNotFoundException $e) {
$this->error('Invalid user ' . $email . '.');
return;
$this->error('Invalid user ID ' . $id . '. Please see table `users` for correct IDs.');
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
$user->password = Hash::make($password);
$user->password = Hash::make($newPassword);
$user->save();
$this->info('Password successfully changed.');
@@ -1,6 +1,6 @@
<?php
namespace App\Console\Commands\Modules;
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
@@ -12,7 +12,7 @@ class InstallAllModules extends Command
*
* @var string
*/
protected $signature = 'module:install-all';
protected $signature = 'install-all-modules';
/**
* The console command description.
*
@@ -20,6 +20,16 @@ class InstallAllModules extends Command
*/
protected $description = 'Crawl /modules directory and install all modules';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
@@ -35,7 +45,7 @@ class InstallAllModules extends Command
// try to install each module
try {
$this->call('module:install', ['name' => $moduleName]);
$this->call('install-module', ['name' => $moduleName]);
} catch (\Exception $e) {
$this->line('Module ' . $moduleName . ' already installed.');
}
@@ -1,12 +1,10 @@
<?php
namespace App\Console\Commands\Modules;
namespace App\Console\Commands;
use App\CMS\ModuleManager\Installer;
use App\Models\Module;
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;
@@ -18,7 +16,7 @@ class InstallModule extends Command
*
* @var string
*/
protected $signature = 'module:install {name} {parentModuleId?}';
protected $signature = 'install-module {name} {parentModuleId?}';
/**
* The console command description.
*
@@ -65,10 +63,6 @@ class InstallModule extends Command
// 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');
}
@@ -99,7 +93,7 @@ class InstallModule extends Command
}
// we cannot rely on config() helper, because this module does not have to be published
$config = include($path);
$config = @include($path);
return $config;
}
@@ -152,15 +146,17 @@ class InstallModule extends Command
throw new \Exception('Module ' . $config['name'] . ' already exists in database.');
}
if (is_null($module)) {
if (!$module) {
// insert module into database
$settings = [
'staticName' => $this->moduleName,
'providers' => $providers,
'aliases' => isset($config['aliases']) ? $config['aliases'] : [],
'order' => isset($config['order']) ? $config['order'] : 0,
'files' => isset($config['files']) ? $config['files'] : []
];
$module = Installer::install($name, $alias, $this->moduleName, $description, $handler, $this->parentModuleId, $settings);
$module = Module::install($name, $alias, $description, $handler, $this->parentModuleId, $settings);
}
// try to install submodules
@@ -183,7 +179,7 @@ class InstallModule extends Command
$submodule = str_replace($this->modulesPath . DIRECTORY_SEPARATOR, '', $submodulePath);
try {
$this->call('module:install', ['name' => $submodule, 'parentModuleId' => $parentModule->id]);
$this->call('install-module', ['name' => $submodule, 'parentModuleId' => $parentModule->id]);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
-119
View File
@@ -1,119 +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;
}
if (!is_dir($path))
mkdir($path);
// 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,47 +0,0 @@
<?php
namespace App\Console\Commands\Modules;
use App\Models\Module;
use Illuminate\Console\Command;
class DisableModule extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'module:disable {module}';
/**
* The console command description.
* @var string
*/
protected $description = 'Disable module';
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
$moduleName = $this->argument('module');
$module = Module::where('static_name', $moduleName)
->firstOrFail();
if ($module->has_submodules) {
$submodules = $module->submodules;
foreach ($submodules as $submodule) {
$this->call('module:disable', ['module' => $submodule->static_name]);
}
}
$module->enabled = false;
$module->save();
\Cache::forget('enabled-modules');
\Cache::forget('enabled-modules-and-template');
$this->line('Module ' . $module->static_name . ' disabled.');
}
}
@@ -1,51 +0,0 @@
<?php
namespace App\Console\Commands\Modules;
use App\Models\Module;
use Illuminate\Console\Command;
class EnableModule extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'module:enable {module}';
/**
* The console command description.
* @var string
*/
protected $description = 'Enable module';
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
$moduleName = $this->argument('module');
$module = Module::where('static_name', $moduleName)
->firstOrFail();
if ($module->has_submodules) {
$submodules = $module->submodules;
foreach ($submodules as $submodule) {
$this->call('module:enable', ['module' => $submodule->static_name]);
}
}
if ($module->parent_id) {
$module->parent->update(['enabled' => true]);
}
$module->enabled = true;
$module->save();
\Cache::forget('enabled-modules');
\Cache::forget('enabled-modules-and-template');
$this->line('Module ' . $module->static_name . ' enabled.');
}
}
@@ -1,42 +0,0 @@
<?php
namespace App\Console\Commands\Modules;
use App\Models\Module;
use Illuminate\Console\Command;
class ModuleMigrate extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'module:migrate {module}';
/**
* The console command description.
* @var string
*/
protected $description = 'Run migrations in specified module';
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
$moduleName = $this->argument('module');
$module = Module::where('static_name', $moduleName)
->firstOrFail();
if ($module->has_submodules) {
$submodules = $module->submodules;
foreach ($submodules as $submodule) {
$this->call('module:migrate', ['module' => $submodule->static_name]);
}
}
$this->line('Migrating ' . $module->static_name);
$this->call('migrate', ['--path' => config('modules.paths.modules').'/'.$moduleName.'/Database']);
}
}
@@ -1,42 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class UninstallModule extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
}
}
+11 -27
View File
@@ -2,10 +2,11 @@
namespace App\Console\Commands;
use App\CMS\Enumerations\UserRoles;
use App\Enumerations\UserRoles;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use Symfony\Component\Console\Exception\InvalidArgumentException;
class NewUser extends Command
{
@@ -14,7 +15,7 @@ class NewUser extends Command
*
* @var string
*/
protected $signature = 'user:new {email}';
protected $signature = 'user:new {email} {password} {role}';
/**
* The console command description.
*
@@ -24,37 +25,20 @@ class NewUser extends Command
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$email = $this->argument('email');
$password = $this->argument('password');
$role = $this->argument('role');
// check if username is really email
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
// check if given role is valid
$roles = UserRoles::getSimple();
do {
$role = $this->ask('Role (default ' . User::ROLE_ADMIN . '): ', User::ROLE_ADMIN);
// 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));
if (!in_array($role, $roles)) {
throw new InvalidArgumentException('Invalid role specified. valid roles are: ' . implode(', ', $roles));
}
// create new user
$user = new User();
@@ -12,6 +12,7 @@ class PublishTemplateResources extends Command
* @var string
*/
protected $signature = 'template:publish';
/**
* The console command description.
*
@@ -26,7 +27,6 @@ class PublishTemplateResources extends Command
*/
public function handle()
{
$this->call('cache:clear');
$this->call('vendor:publish', ['--tag' => 'module-views', '--force' => true]);
$this->call('vendor:publish', ['--tag' => 'public-assets', '--force' => true]);
}
+6 -13
View File
@@ -2,11 +2,8 @@
namespace App\Console\Commands;
use App\CMS\ModuleManager\Installer;
use App\CMS\ModuleManager\Uninstaller;
use App\Models\Module;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class SetTemplate extends Command
@@ -45,13 +42,14 @@ class SetTemplate extends Command
$config['staticName'] = $template;
if ($current) {
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $current->static_name . '.');
$info = json_decode($current->module_settings);
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $info->staticName . '.');
$confirm = $this->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);
$current->uninstall();
} else {
$this->line('Aborting installation.');
return;
@@ -59,22 +57,17 @@ class SetTemplate extends Command
}
try {
Installer::install($config['name'], $config['alias'], $current->static_name, $config['description'], $config['handler'], false, $config);
Module::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
} catch (\Exception $e) {
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
return;
}
// 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');
}
exec('php artisan vendor:publish');
}
}
-41
View File
@@ -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);
}
}
+6 -13
View File
@@ -2,12 +2,7 @@
namespace App\Console;
use App\Console\Commands\Modules\CreateNew;
use App\Console\Commands\Modules\DisableModule;
use App\Console\Commands\Modules\EnableModule;
use App\Console\Commands\Modules\ModuleMigrate;
use App\Console\Commands\PublishTemplateResources;
use App\Console\Commands\TemplateInfo;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -15,24 +10,20 @@ class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\NewUser::class,
Commands\ChangePassword::class,
CreateNew::class,
ModuleMigrate::class,
EnableModule::class,
DisableModule::class,
Commands\Modules\InstallModule::class,
Commands\Modules\InstallAllModules::class,
Commands\InstallModule::class,
Commands\InstallAllModules::class,
Commands\TranslateDirectory::class,
Commands\TranslateAll::class,
Commands\InitDatabaseSchema::class,
Commands\SetTemplate::class,
Commands\AddLanguage::class,
PublishTemplateResources::class,
TemplateInfo::class
PublishTemplateResources::class
];
/**
@@ -44,5 +35,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}
}
+6
View File
@@ -0,0 +1,6 @@
<?php
namespace App\CustomFields;
class BaseField {
}
+6
View File
@@ -0,0 +1,6 @@
<?php
namespace App\CustomFields;
class Date extends BaseField {
}
+6
View File
@@ -0,0 +1,6 @@
<?php
namespace App\CustomFields;
class Number extends BaseField {
}
+6
View File
@@ -0,0 +1,6 @@
<?php
namespace App\CustomFields;
class SelectboxList extends BaseField {
}
+6
View File
@@ -0,0 +1,6 @@
<?php
namespace App\CustomFields;
class String extends BaseField {
}
@@ -1,5 +1,5 @@
<?php
namespace App\CMS\Enumerations;
namespace App\Enumerations;
use App\Models\ActionLogType;
@@ -1,7 +1,7 @@
<?php
namespace App\CMS\Enumerations;
namespace App\Enumerations;
use App\Models\ActionLog\ActionLogType;
use App\Models\ActionLogType;
class ActionLogTypesForLogger extends BaseEnumeration
{
@@ -1,7 +1,7 @@
<?php
namespace App\CMS\Enumerations;
namespace App\Enumerations;
use App\CMS\Exceptions\Enumerations\EnumerationExistsException;
use App\Enumerations\Exceptions\EnumerationExistsException;
abstract class BaseEnumeration
{
@@ -1,8 +1,7 @@
<?php
namespace App\CMS\Enumerations;
namespace App\Enumerations;
use App\CMS\Contracts\Repositories\Content;
use App\Models\Content;
class ContentStatuses extends BaseEnumeration
{
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Enumerations;
use App\Models\CustomFieldResource;
class CustomFieldResources extends BaseEnumeration
{
public static $items = [];
public static function init()
{
// load items from database
$types = CustomFieldResource::all(['id', 'name']);
// push items into collection
foreach ($types as $type) {
self::push($type->id, $type->name);
}
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Enumerations;
use App\Models\CustomFieldType;
class CustomFieldTypes extends BaseEnumeration
{
public static $items = [];
public static function init()
{
// load items from database
$types = CustomFieldType::all(['id', 'name']);
// push items into collection
foreach ($types as $type) {
self::push($type->id, $type->name);
}
}
}
@@ -1,5 +1,5 @@
<?php
namespace App\CMS\Exceptions\Enumerations;
namespace App\Enumerations\Exceptions;
class EnumerationExistsException extends \Exception {

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