Compare commits
67
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3b1951d25 | ||
|
|
cad205960d | ||
|
|
73e049e47d | ||
|
|
0ae3e4fe08 | ||
|
|
28addf5e33 | ||
|
|
d5a33b382e | ||
|
|
2fdec0a65f | ||
|
|
6fb6aef199 | ||
|
|
f69b8f39ad | ||
|
|
35bda2828c | ||
|
|
bda659b910 | ||
|
|
c8ec9c4eeb | ||
|
|
9451357e02 | ||
|
|
727e449ebc | ||
|
|
b5425423d6 | ||
|
|
66e78aff6a | ||
|
|
497ff1b96d | ||
|
|
c429024a54 | ||
|
|
0778a1d30c | ||
|
|
3748d00c2f | ||
|
|
a525d9c085 | ||
|
|
dff8dcf565 | ||
|
|
0d22a14604 | ||
|
|
724478d0c9 | ||
|
|
0ba0d1c15d | ||
|
|
9593b6502e | ||
|
|
e53283da65 | ||
|
|
f0d1cb8020 | ||
|
|
9076f81185 | ||
|
|
b7d4ab9515 | ||
|
|
2b98c60d2a | ||
|
|
99ed8806da | ||
|
|
d0fbce13fb | ||
|
|
675aec669b | ||
|
|
ca718a5efe | ||
|
|
3aabb8fa7b | ||
|
|
2fffea39fa | ||
|
|
7584491ff5 | ||
|
|
84b2902613 | ||
|
|
2d6be0cb2e | ||
|
|
e6c02617e6 | ||
|
|
0b56b41c3c | ||
|
|
f89e11b5fb | ||
|
|
785168ecc2 | ||
|
|
9f430cee11 | ||
|
|
785387b796 | ||
|
|
f940930c66 | ||
|
|
8cb06bf641 | ||
|
|
000352052d | ||
|
|
988f153d9f | ||
|
|
6dd452317b | ||
|
|
34feaac2ac | ||
|
|
e25f47a511 | ||
|
|
cc999dd24e | ||
|
|
28f67ffe3c | ||
|
|
4f6a006ad9 | ||
|
|
662700b4f2 | ||
|
|
eabbf48ee0 | ||
|
|
6ec692bd1c | ||
|
|
aa0ef7ccc6 | ||
|
|
e26e6fd460 | ||
|
|
2ded2924a1 | ||
|
|
87f1920373 | ||
|
|
b7f911c9b8 | ||
|
|
84aea5c847 | ||
|
|
98fc287f10 | ||
|
|
686edf1c6f |
@@ -27,3 +27,9 @@
|
||||
|
||||
# meta information created by installer
|
||||
.install
|
||||
/node_modules/
|
||||
/public/css/
|
||||
/public/js
|
||||
/public/fonts
|
||||
/bower_components
|
||||
.sass-cache
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Content;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
interface AdvancedContentModifier {
|
||||
/**
|
||||
* Save module-specific values into database
|
||||
*
|
||||
* @param Content $content
|
||||
* @param array $inputData
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function createNew(Content &$content, array $inputData);
|
||||
|
||||
/**
|
||||
* Method used for editing existing content page.
|
||||
*
|
||||
* Reason why it is separated from createNew() method is simple - we need to save history of changes.
|
||||
*
|
||||
* @param Content $content
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function edit(Content $content, $request);
|
||||
/**
|
||||
* Method called right after content page is marked as deleted
|
||||
*
|
||||
* This method is supposed to clean after "deleted" page.
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function delete(Content $content);
|
||||
}
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
namespace App\CMS\Contracts\Content;
|
||||
|
||||
use App\Models\Content;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
/**
|
||||
* Interface ContentTitles
|
||||
@@ -9,7 +9,7 @@ use App\Models\Content;
|
||||
* Classes which implement this interface get the ability to rewrite default text on edit/create/overview of content
|
||||
* page.
|
||||
*
|
||||
* @package App\Handlers\Contracts
|
||||
* @package App\CMS\Handlers\Contracts
|
||||
*/
|
||||
interface ContentTitles
|
||||
{
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
namespace App\CMS\Handlers\Contracts;
|
||||
|
||||
interface HistoryHandler
|
||||
{
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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,8 +1,8 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
namespace App\CMS\Contracts\Modules;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
interface AppHandler extends BaseModuleHandler
|
||||
{
|
||||
@@ -18,51 +18,6 @@ interface AppHandler extends BaseModuleHandler
|
||||
|
||||
public static function getHistoryHandler();
|
||||
|
||||
/**
|
||||
* Load some extra data for content management form?
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function loadExtraData(Content $content);
|
||||
|
||||
/**
|
||||
* Save module-specific values into database
|
||||
*
|
||||
* @param Content $content
|
||||
* @param Request $request
|
||||
*
|
||||
* @return mixed
|
||||
* @internal param Widget $widget
|
||||
*/
|
||||
public static function createNew(Content &$content, Request $request);
|
||||
|
||||
/**
|
||||
* Method used for editing existing content page.
|
||||
*
|
||||
* Reason why it is separated from createNew() method is simple - we need to save history of changes.
|
||||
*
|
||||
* @param Content $content
|
||||
* @param Request $request
|
||||
*
|
||||
* @param $revisionID string ID of revision used
|
||||
*
|
||||
* @return int number of edited fields
|
||||
*/
|
||||
public static function edit(Content &$content, Request $request, $revisionID);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Getter for section names in creating/editing content resource
|
||||
*
|
||||
+1
-8
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
namespace App\CMS\Contracts\Modules;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -15,11 +15,4 @@ interface BaseModuleHandler
|
||||
*/
|
||||
public static function registerAdminMenu(User $user);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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);
|
||||
}
|
||||
+5
-15
@@ -1,28 +1,18 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
namespace App\CMS\Contracts\Modules;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content;
|
||||
use App\Models\Module;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
/**
|
||||
* Interface TemplateHandler
|
||||
*
|
||||
* Inerface used for registering template into CMS core.
|
||||
*
|
||||
* @package App\Handlers\Contracts
|
||||
* @package App\CMS\Handlers\Contracts
|
||||
*/
|
||||
interface TemplateHandler extends BaseModuleHandler
|
||||
{
|
||||
/**
|
||||
* Uninstall template
|
||||
*
|
||||
* Delete some items in database, delete files etc.
|
||||
*
|
||||
* @param Module $template
|
||||
*/
|
||||
public static function uninstall(Module $template);
|
||||
|
||||
/**
|
||||
* Get list of registered templates and supported modules.
|
||||
*
|
||||
@@ -58,7 +48,7 @@ interface TemplateHandler extends BaseModuleHandler
|
||||
* This way we can do almost whatever we want - even in template
|
||||
*
|
||||
* @param Content $content
|
||||
* @param Request $request
|
||||
* @param $request
|
||||
*/
|
||||
public static function beforeSave(Content & $content, Request $request);
|
||||
public static function beforeSave(Content & $content, $request);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Repositories;
|
||||
|
||||
interface BaseRepository {
|
||||
public function getOne($id = null);
|
||||
public function all();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?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 = []);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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();
|
||||
|
||||
public function getForModule(ModuleModel $module);
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
namespace App\CMS\Handlers\Contracts;
|
||||
|
||||
interface SearchHandler {
|
||||
public function getId();
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
namespace App\CMS\Handlers\Contracts;
|
||||
|
||||
interface SearchPresenterHandler
|
||||
{
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Widgets\Contracts;
|
||||
namespace App\CMS\Contracts\Widgets;
|
||||
|
||||
interface AdminDashboardWidget extends PublicWidget
|
||||
{
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Widgets\Contracts;
|
||||
namespace App\CMS\Widgets\Contracts;
|
||||
|
||||
interface MenuExtensionHandler {
|
||||
|
||||
+6
-17
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace App\Widgets\Contracts;
|
||||
namespace App\CMS\Contracts\Widgets;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Widget;
|
||||
use App\Models\Widgets\Widget;
|
||||
|
||||
interface PublicWidget
|
||||
{
|
||||
@@ -28,22 +28,11 @@ interface PublicWidget
|
||||
public static function getPresenter();
|
||||
|
||||
/**
|
||||
* @param Widget $widget
|
||||
* @param \stdClass $data
|
||||
* Get widget settings for saving into database
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function save(Widget $widget, \stdClass $data);
|
||||
|
||||
/**
|
||||
* Function for installing given widget
|
||||
* @param Request $request
|
||||
*
|
||||
* @return mixed
|
||||
* @return array
|
||||
*/
|
||||
public static function install();
|
||||
|
||||
/**
|
||||
* Function for uninstalling widget
|
||||
*/
|
||||
public static function uninstall();
|
||||
public static function save(Request $request);
|
||||
}
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace App\Widgets\Contracts;
|
||||
namespace App\CMS\Contracts\Widgets;
|
||||
|
||||
use App\Models\Widget;
|
||||
use App\Models\WidgetType;
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
|
||||
interface WidgetRenderer
|
||||
{
|
||||
@@ -11,7 +11,7 @@ interface WidgetRenderer
|
||||
*
|
||||
* This method renders some HTML code for displaying.
|
||||
*
|
||||
* @param object $settings
|
||||
* @param Widget $settings
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\ActionLogType;
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\ActionLogType;
|
||||
use App\Models\ActionLog\ActionLogType;
|
||||
|
||||
class ActionLogTypesForLogger extends BaseEnumeration
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\CMS\Exceptions\Enumerations\EnumerationExistsException;
|
||||
|
||||
abstract class BaseEnumeration
|
||||
{
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\Content;
|
||||
|
||||
use App\CMS\Contracts\Repositories\Content;
|
||||
|
||||
class ContentStatuses extends BaseEnumeration
|
||||
{
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\Module;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\Module;
|
||||
|
||||
+5
-2
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\Module;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ModulesHandlerToId extends BaseEnumeration
|
||||
{
|
||||
@@ -12,7 +13,9 @@ class ModulesHandlerToId extends BaseEnumeration
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
$modules = Module::all(['handler', 'id']);
|
||||
$modules = Cache::rememberForever('module-handler-to-id-enumeration', function () {
|
||||
return Module::all(['handler', 'id']);
|
||||
});
|
||||
|
||||
foreach ($modules as $module) {
|
||||
self::push($module->handler, $module->id);
|
||||
@@ -6,9 +6,9 @@
|
||||
* Time: 10:33
|
||||
*/
|
||||
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\TemplatePath;
|
||||
use App\Models\Templates\TemplatePath;
|
||||
|
||||
class TemplatePaths extends BaseEnumeration
|
||||
{
|
||||
+2
-2
@@ -6,9 +6,9 @@
|
||||
* Time: 10:33
|
||||
*/
|
||||
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\TemplatePath;
|
||||
use App\Models\Templates\TemplatePath;
|
||||
|
||||
class TemplatePathsHumanReadable extends BaseEnumeration
|
||||
{
|
||||
+2
-2
@@ -6,9 +6,9 @@
|
||||
* Time: 10:33
|
||||
*/
|
||||
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\TemplatePath;
|
||||
use App\Models\Templates\TemplatePath;
|
||||
|
||||
class TemplatePathsHumanReadableRootOnly extends BaseEnumeration
|
||||
{
|
||||
@@ -6,9 +6,9 @@
|
||||
* Time: 15:50
|
||||
*/
|
||||
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\Template;
|
||||
use App\Models\Templates\Template;
|
||||
|
||||
class Templates extends BaseEnumeration
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Time: 23:20
|
||||
*/
|
||||
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\WidgetType;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
|
||||
class WidgetTypes extends BaseEnumeration
|
||||
{
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Enumerations;
|
||||
namespace App\CMS\Enumerations;
|
||||
|
||||
use App\Models\WidgetType;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
|
||||
class WidgetTypesWithHandlers extends BaseEnumeration
|
||||
{
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Enumerations\Exceptions;
|
||||
namespace App\CMS\Exceptions\Enumerations;
|
||||
|
||||
class EnumerationExistsException extends \Exception {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace App\CMS\Exceptions\FileManager;
|
||||
|
||||
class SubdirectoryExistsInDirectory extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?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
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Widgets\Exceptions;
|
||||
namespace App\CMS\Widgets\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Widgets\Exceptions;
|
||||
namespace App\CMS\Widgets\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
namespace App\Handlers;
|
||||
namespace App\CMS\Handlers;
|
||||
|
||||
use App\Enumerations\TemplatePathsHumanReadableRootOnly;
|
||||
use App\Enumerations\WidgetTypes;
|
||||
use App\Handlers\Contracts\AppHandler;
|
||||
use App\Handlers\Contracts\BaseModuleHandler;
|
||||
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
|
||||
@@ -35,7 +34,6 @@ abstract class BaseHandler implements BaseModuleHandler
|
||||
* Submenus can be registered later
|
||||
*/
|
||||
$menu->dropdown(trans('admin/mainMenu.contentPages'), function ($sub) {
|
||||
$sub->addDivider(9999);
|
||||
$sub->route('content.overview', trans('admin/mainMenu.contentPageOverview'), [], 10000, ['icon' => 'fa fa-fw fa-list']);
|
||||
}, 20, ['icon' => 'fa fa-fw fa-database']);
|
||||
|
||||
@@ -97,22 +95,11 @@ abstract class BaseHandler implements BaseModuleHandler
|
||||
}, 60, ['icon' => 'fa fa-fw fa-file-code-o']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// $menu->dropdown(trans('admin/mainMenu.customFields'), function ($sub) {
|
||||
// $sub->route('customfields.new', trans('admin/mainMenu.customFieldsNew'), [], 10, ['icon' => 'fa fa-fw fa-code']);
|
||||
// $sub->route('customfields.overview', trans('admin/mainMenu.customFieldsOverview'), [], 50, ['icon' => 'fa fa-fw fa-code-fork']);
|
||||
// }, 30, ['icon' => 'fa fa-fw fa-code']);
|
||||
|
||||
$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']);
|
||||
|
||||
|
||||
});
|
||||
|
||||
// order
|
||||
|
||||
// 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']);
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace App\Handlers;
|
||||
namespace App\CMS\Handlers;
|
||||
|
||||
use App\Handlers\Contracts\AppHandler;
|
||||
use App\CMS\Contracts\Modules\AppHandler;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Content;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
/**
|
||||
* Class Handler
|
||||
@@ -11,20 +11,10 @@ use App\Models\Content;
|
||||
* 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\Handlers
|
||||
* @package App\CMS\Handlers\
|
||||
*/
|
||||
abstract class Handler extends BaseHandler implements AppHandler
|
||||
{
|
||||
/**
|
||||
* todo: Temporary method, will be implemented for each Handler
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supportCategories()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getHistoryHandler()
|
||||
{
|
||||
return History::class;
|
||||
@@ -64,16 +54,7 @@ abstract class Handler extends BaseHandler implements AppHandler
|
||||
'files' => 'admin.content.formParts.files'
|
||||
];
|
||||
}
|
||||
|
||||
public static function delete(Content $content)
|
||||
{
|
||||
// temporarily nothing to do
|
||||
}
|
||||
|
||||
public static function loadExtraData(Content $content) {
|
||||
// temporarily nothing to do
|
||||
}
|
||||
|
||||
|
||||
public static function getExtendedFormInputsEdit()
|
||||
{
|
||||
return self::getExtendedFormInputsCreate();
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace App\Handlers;
|
||||
namespace App\CMS\Handlers;
|
||||
|
||||
use App\Enumerations\ContentStatuses;
|
||||
use App\Handlers\Contracts\HistoryHandler;
|
||||
use App\Helpers\Differ;
|
||||
use App\CMS\Enumerations\ContentStatuses;
|
||||
use App\CMS\Handlers\Contracts\HistoryHandler;
|
||||
use App\CMS\Helpers\Differ;
|
||||
|
||||
class History implements HistoryHandler
|
||||
{
|
||||
@@ -43,7 +43,7 @@ class History implements HistoryHandler
|
||||
'to' => $statuses[$changeset->new_value]
|
||||
]);
|
||||
break;
|
||||
case 'is_homepage':
|
||||
case 'isHomepage':
|
||||
return trans('admin/history.setupAsHomepage');
|
||||
break;
|
||||
default:
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Handlers\Registrators\Items;
|
||||
namespace App\CMS\Handlers\Registrators\Items;
|
||||
|
||||
class SettingExtension
|
||||
{
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Handlers\Registrators;
|
||||
namespace App\CMS\Handlers\Registrators;
|
||||
|
||||
use App\Widgets\Contracts\MenuExtensionHandler;
|
||||
use App\CMS\Widgets\Contracts\MenuExtensionHandler;
|
||||
|
||||
class MenuExtensionRegistrator {
|
||||
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
namespace App\Handlers\Registrators;
|
||||
namespace App\CMS\Handlers\Registrators;
|
||||
|
||||
use App\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\Handlers\Contracts\SearchHandler;
|
||||
use App\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\Handlers\Registrators\Items\SearchEngine;
|
||||
use App\CMS\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\CMS\Handlers\Contracts\SearchHandler;
|
||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\CMS\Handlers\Registrators\Items\SearchEngine;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
|
||||
class SearchEngineRegistrator
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace App\Handlers\Registrators;
|
||||
namespace App\CMS\Handlers\Registrators;
|
||||
|
||||
use App\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\Handlers\Registrators\Items\SettingExtension;
|
||||
use App\CMS\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\CMS\Handlers\Registrators\Items\SettingExtension;
|
||||
|
||||
class SettingsExtensionRegistrator
|
||||
{
|
||||
+25
-12
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
namespace App\Handlers\Registrators;
|
||||
namespace App\CMS\Handlers\Registrators;
|
||||
|
||||
use App\Enumerations\TemplatePaths;
|
||||
use App\Enumerations\Templates;
|
||||
use App\Models\Template;
|
||||
use App\Models\TemplatePath;
|
||||
use App\CMS\Contracts\Repositories\Template;
|
||||
use App\CMS\Enumerations\TemplatePaths;
|
||||
use App\CMS\Enumerations\Templates;
|
||||
use App\Models\Templates\Template as TemplateModel;
|
||||
use App\Models\Templates\TemplatePath;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
@@ -134,7 +135,10 @@ class TemplateRegistrator
|
||||
*/
|
||||
protected function relativePath($directory)
|
||||
{
|
||||
return trim(str_replace(base_path(), '', $directory), '/');
|
||||
$directory = str_replace('/', DIRECTORY_SEPARATOR, $directory);
|
||||
$directory = str_replace('\\', DIRECTORY_SEPARATOR, $directory);
|
||||
|
||||
return trim(str_replace(base_path(), '', $directory), '\\/');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,6 +149,10 @@ class TemplateRegistrator
|
||||
*/
|
||||
protected function scanForSubdirectories($directory, $name)
|
||||
{
|
||||
if (!is_dir($directory)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$directories = File::directories($directory);
|
||||
|
||||
foreach ($directories as $dir) {
|
||||
@@ -194,7 +202,7 @@ class TemplateRegistrator
|
||||
* @param $path
|
||||
* @param $templatePathId
|
||||
*
|
||||
* @throws \App\Enumerations\Exceptions\EnumerationExistsException
|
||||
* @throws \App\CMS\Enumerations\Exceptions\EnumerationExistsException
|
||||
*/
|
||||
protected function registerTemplates($path, $templatePathId)
|
||||
{
|
||||
@@ -222,7 +230,7 @@ class TemplateRegistrator
|
||||
];
|
||||
|
||||
// save template into database
|
||||
$newTemplate = Template::create($params);
|
||||
$newTemplate = TemplateModel::create($params);
|
||||
|
||||
// push template into enumeration - so it will not be registered again
|
||||
Templates::push($newTemplate->id, $templateName);
|
||||
@@ -238,7 +246,7 @@ class TemplateRegistrator
|
||||
* @param null $parent
|
||||
*
|
||||
* @return mixed|null
|
||||
* @throws \App\Enumerations\Exceptions\EnumerationExistsException
|
||||
* @throws \App\CMS\Enumerations\Exceptions\EnumerationExistsException
|
||||
*/
|
||||
protected function saveTemplatePath($path, $name, $parent = null)
|
||||
{
|
||||
@@ -295,12 +303,17 @@ class TemplateRegistrator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getTemplateName($template)
|
||||
protected function getTemplateName($template)
|
||||
{
|
||||
$templateName = str_replace($this->registeredPath . DIRECTORY_SEPARATOR, '', $template);
|
||||
$templateName = $template;
|
||||
|
||||
$templateName = str_replace($this->registeredPath, '', $templateName);
|
||||
$templateName = str_replace('\\', DIRECTORY_SEPARATOR, $templateName);
|
||||
$templateName = str_replace('/', DIRECTORY_SEPARATOR, $templateName);
|
||||
$templateName = str_replace(DIRECTORY_SEPARATOR, '.', $templateName);
|
||||
$templateName = str_replace(Template::TEMPLATE_SUFFIX, '', $templateName);
|
||||
$templateName = preg_replace('/\.{2,}/', '.', $templateName);
|
||||
|
||||
return $this->namespace . $templateName;
|
||||
return $this->namespace . trim($templateName, '.');
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
namespace App\Handlers\Registrators;
|
||||
namespace App\CMS\Handlers\Registrators;
|
||||
|
||||
use App\Enumerations\WidgetTypesWithHandlers;
|
||||
use App\Models\WidgetType;
|
||||
use App\CMS\Enumerations\WidgetTypesWithHandlers;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
|
||||
class WidgetRegistrator
|
||||
{
|
||||
protected $registeredWidgets = [];
|
||||
|
||||
|
||||
/**
|
||||
* Method used for registering new widgets
|
||||
*
|
||||
@@ -51,7 +50,9 @@ class WidgetRegistrator
|
||||
]);
|
||||
|
||||
// install widget (if neccessary)
|
||||
call_user_func($classname . '::install');
|
||||
if (is_callable([$classname, 'install'])) {
|
||||
call_user_func($classname . '::install');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Handlers\Search;
|
||||
namespace App\CMS\Handlers\Search;
|
||||
|
||||
use App\Models\Content as ContentModel;
|
||||
use App\Models\Content\Content as ContentModel;
|
||||
|
||||
class Content extends Search
|
||||
{
|
||||
@@ -16,9 +16,9 @@ class Content extends Search
|
||||
{
|
||||
$token = $this->tokenize($term);
|
||||
|
||||
return ContentModel::where('content', 'LIKE', $token)
|
||||
->orWhere('meta_description', 'LIKE', $token)
|
||||
->orWhere('meta_keywords', 'LIKE', $token)
|
||||
return ContentModel::where('pageContent', 'LIKE', $token)
|
||||
->orWhere('metaDescription', 'LIKE', $token)
|
||||
->orWhere('metaKeywords', 'LIKE', $token)
|
||||
->orWhere('title', 'LIKE', $token)
|
||||
->orWhere('url', 'LIKE', $token)
|
||||
->get();
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Handlers\Search;
|
||||
namespace App\CMS\Handlers\Search;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\FileManager\File;
|
||||
|
||||
class Files extends Search
|
||||
{
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace App\Handlers\Search\Presenters;
|
||||
namespace App\CMS\Handlers\Search\Presenters;
|
||||
|
||||
use App\Enumerations\ContentStatuses;
|
||||
use App\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\CMS\Enumerations\ContentStatuses;
|
||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
||||
|
||||
class AdminContent implements SearchPresenterHandler
|
||||
{
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Handlers\Search\Presenters;
|
||||
namespace App\CMS\Handlers\Search\Presenters;
|
||||
|
||||
use App\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
||||
|
||||
class AdminFiles implements SearchPresenterHandler
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Handlers\Search;
|
||||
namespace App\CMS\Handlers\Search;
|
||||
|
||||
use App\Handlers\Contracts\SearchHandler;
|
||||
use App\CMS\Handlers\Contracts\SearchHandler;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
|
||||
abstract class Search implements SearchHandler
|
||||
@@ -0,0 +1,132 @@
|
||||
<?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 () {
|
||||
$template = Module::where('is_template', true)
|
||||
->where('enabled', true)
|
||||
->first();
|
||||
|
||||
// todo remove after adding $casts into Module model
|
||||
if ($template) {
|
||||
$template->module_settings = json_decode($template->module_settings);
|
||||
}
|
||||
|
||||
return $template;
|
||||
});
|
||||
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare Content object to be rendered using Blade template
|
||||
*
|
||||
* @param Content $content
|
||||
*/
|
||||
public static function beforeRender(Content & $content)
|
||||
{
|
||||
call_user_func_array([self::handler(), 'beforeRender'], [&$content]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify input data into format which can be understood by edit template
|
||||
*
|
||||
* @param Content $content
|
||||
*/
|
||||
public static function beforePopulatingEditForm(Content & $content)
|
||||
{
|
||||
call_user_func_array([self::handler(), 'beforePopulatingEditForm'], [&$content]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slightly modify Content object before saving into database.
|
||||
*
|
||||
* This way we can do almost whatever we want - even in template
|
||||
*
|
||||
* @param Content $content
|
||||
* @param $request
|
||||
*/
|
||||
public static function beforeSave(Content & $content, $request)
|
||||
{
|
||||
call_user_func_array([self::handler(), 'beforeSave'], [&$content, $request]);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
class Date
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
/*
|
||||
Paul's Simple Differ Algorithm v 0.1
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\FileManager\File;
|
||||
|
||||
class FileManager
|
||||
{
|
||||
@@ -17,7 +17,7 @@ class FileManager
|
||||
switch ($type) {
|
||||
case 'image':
|
||||
|
||||
$url = Template::thumbnail($file->filename);
|
||||
$url = Path::thumbnail($file->filename);
|
||||
|
||||
return '<img src="' . $url . '" alt="' . $file->description . '" />';
|
||||
break;
|
||||
@@ -98,7 +98,7 @@ class FileManager
|
||||
return $string;
|
||||
break;
|
||||
case 'application':
|
||||
return '<iframe src = "'.asset('resources/assets/admin/js/viewerJs/').'/#'.Template::upload($file->filename).'" style="width: 100%; height: 50em" allowfullscreen webkitallowfullscreen></iframe>';
|
||||
return '<iframe src = "'.asset('resources/assets/admin/js/viewerJs/').'/#'.Path::upload($file->filename).'" style="width: 100%; height: 50em" allowfullscreen webkitallowfullscreen></iframe>';
|
||||
break;
|
||||
default:
|
||||
return self::getPreview($file);
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
class Gravatar
|
||||
{
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
use App\Handlers\Contracts\AppHandler;
|
||||
use App\Models\Content;
|
||||
use App\CMS\Handlers\Contracts\AppHandler;
|
||||
use App\Models\Content\Content;
|
||||
use Webwizo\Shortcodes\Facades\Shortcode;
|
||||
|
||||
/**
|
||||
@@ -10,7 +10,7 @@ use Webwizo\Shortcodes\Facades\Shortcode;
|
||||
*
|
||||
* Simple class for rendering page for visitor
|
||||
*
|
||||
* @package App\Helpers
|
||||
* @package App\CMS\Helpers
|
||||
*/
|
||||
class PageRenderer
|
||||
{
|
||||
@@ -23,9 +23,6 @@ class PageRenderer
|
||||
*/
|
||||
public static function render(Content $page)
|
||||
{
|
||||
// decode module settings
|
||||
$page->module_settings = json_decode($page->module_settings);
|
||||
|
||||
// do something template-specific
|
||||
$parameters = call_user_func_array([CurrentTemplate::handler(), 'beforeRender'], [&$page]);
|
||||
|
||||
@@ -33,7 +30,7 @@ class PageRenderer
|
||||
* @var $handler AppHandler
|
||||
*/
|
||||
// get handler
|
||||
$handler = new $page->module_handler;
|
||||
$handler = new $page->moduleHandler;
|
||||
|
||||
$page->content = Shortcode::compile($page->content);
|
||||
|
||||
@@ -1,48 +1,11 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
|
||||
class Template
|
||||
class Path
|
||||
{
|
||||
/**
|
||||
* Getter for real template name
|
||||
*
|
||||
* @param $template
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL to uploaded file
|
||||
*
|
||||
@@ -95,25 +58,4 @@ class Template
|
||||
|
||||
return config('app.url') . '/assets/' . config('app.theme') . '/' . $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print date in configured format
|
||||
*
|
||||
* @param $datestamp
|
||||
* @param bool $withTime
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public static function date($datestamp, $withTime = true)
|
||||
{
|
||||
$timestamp = strtotime($datestamp);
|
||||
|
||||
if ($timestamp <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$format = $withTime ? config('app.datetime_format') : config('app.date_format');
|
||||
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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,15 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
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\Helpers
|
||||
* @package App\CMS\Helpers
|
||||
*/
|
||||
class Settings
|
||||
{
|
||||
@@ -76,8 +77,10 @@ class Settings
|
||||
private static function init()
|
||||
{
|
||||
if (!self::$initialized) {
|
||||
$model = new SettingsModel();
|
||||
self::$settings = $model->getAll();
|
||||
self::$settings = Cache::remember('settings', config('cache.settingCacheLifetime'), function () {
|
||||
$model = new SettingsModel();
|
||||
return $model->getAll();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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,7 +1,8 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
namespace App\CMS\Helpers;
|
||||
|
||||
use App\Models\WidgetArea;
|
||||
use App\Models\Widgets\WidgetArea;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class WidgetAreas
|
||||
{
|
||||
@@ -14,22 +15,21 @@ class WidgetAreas
|
||||
protected static function saveRenderedWidgetArea($widgets)
|
||||
{
|
||||
foreach ($widgets as $widget) {
|
||||
if (!isset(self::$widgetAreas[$widget->widget_area_code]))
|
||||
if (!isset(self::$widgetAreas[$widget->widget_area_code])) {
|
||||
self::$widgetAreas[$widget->widget_area_code] = '';
|
||||
}
|
||||
|
||||
$handler = $widget->widget_type_handler;
|
||||
$widget->settings = json_decode($widget->settings);
|
||||
$presenter = call_user_func([$handler, 'getPresenter']);
|
||||
|
||||
self::$widgetAreas[$widget->widget_area_code] .= call_user_func([$presenter, 'render'], $widget);
|
||||
self::$widgetAreas[$widget->widget_area_code] .= Widget::render($widget);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function loadWidgetArea($uniqueCode)
|
||||
{
|
||||
$widgetArea = new WidgetArea();
|
||||
$widgets = $widgetArea->getWidgets($uniqueCode)
|
||||
$widgets = Cache::remember('widget-' . $uniqueCode, setting('widgetCacheLifetime', 5), function () use ($uniqueCode) {
|
||||
$widgetArea = new WidgetArea();
|
||||
return $widgetArea->getWidgets($uniqueCode)
|
||||
->get();
|
||||
});
|
||||
|
||||
WidgetArea::where('code', $uniqueCode)
|
||||
->increment('viewed');
|
||||
@@ -39,12 +39,15 @@ class WidgetAreas
|
||||
|
||||
protected static function initWidgetAreas()
|
||||
{
|
||||
if (self::$initialized)
|
||||
if (self::$initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
$widgetArea = new WidgetArea();
|
||||
$widgets = $widgetArea->getWidgets()
|
||||
$widgets = Cache::remember('widgets', setting('widgetCacheLifetime', 5), function () {
|
||||
$widgetArea = new WidgetArea();
|
||||
return $widgetArea->getWidgets()
|
||||
->get();
|
||||
});
|
||||
|
||||
self::saveRenderedWidgetArea($widgets);
|
||||
self::$initialized = true;
|
||||
@@ -14,7 +14,7 @@ function e($value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for \App\Helpers\Settings::get()
|
||||
* Shortcut for \App\CMS\Helpers\Settings::get()
|
||||
*
|
||||
* @param $key
|
||||
* @param null $default
|
||||
@@ -22,9 +22,13 @@ function e($value)
|
||||
* @return null|string
|
||||
*/
|
||||
function setting($key, $default = null) {
|
||||
return \App\Helpers\Settings::get($key, $default);
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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))];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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 [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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|void
|
||||
*/
|
||||
public function handle($data, $parameters)
|
||||
{
|
||||
/**
|
||||
* @var $page Content
|
||||
*/
|
||||
list($page, $titlePhoto, $relatedFiles) = $parameters;
|
||||
|
||||
// let template to modify request and content page
|
||||
CurrentTemplate::beforeSave($page, $data);
|
||||
|
||||
// upload file - if provided
|
||||
$data['titlePhoto'] = isset($data['existingTitlePhoto']) ? $data['existingTitlePhoto'] : null;
|
||||
|
||||
if (!is_null($titlePhoto)) {
|
||||
$file = $this->file->upload($titlePhoto);
|
||||
$data['titlePhoto'] = $file ? $file['filename'] : null;
|
||||
}
|
||||
|
||||
$page->update($data);
|
||||
$this->module->callOnString($page->moduleHandler, 'edit', [$page, $data]);
|
||||
|
||||
// move to interaction
|
||||
$keepAssigned = isset($data->keepAssigned) ? $data->keepAssigned : [];
|
||||
$page->uploadRelatedFiles($relatedFiles, $keepAssigned);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?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, $titlePhoto, $relatedFiles) = $parameters;
|
||||
|
||||
// upload file - if provided
|
||||
$file = !is_null($titlePhoto) ? $this->file->upload($titlePhoto) : null;
|
||||
|
||||
$data['userId'] = \Auth::user()->id;
|
||||
$data['language'] = LaravelLocalization::getCurrentLocale();
|
||||
$data['titlePhoto'] = $file ? $file['filename'] : null;
|
||||
$data['moduleHandler'] = $moduleHandler;
|
||||
|
||||
$page = Content::create($data);
|
||||
|
||||
// save module-specific stuff
|
||||
$this->module->callOnString($moduleHandler, 'createNew', [&$page, $data]);
|
||||
|
||||
// let template to modify data and content page
|
||||
CurrentTemplate::beforeSave($page, $data);
|
||||
|
||||
// save content of page before (possible) uploading related files
|
||||
$page->save();
|
||||
|
||||
// upload files assigned to content page
|
||||
$page->uploadRelatedFiles($relatedFiles);
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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 [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?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;
|
||||
|
||||
// todo this should probably go into validation, but we are not able to get $data in getValidationRules
|
||||
// check if created folder does not exist in current directory
|
||||
if ($this->repository->checkIfNameExists($data['name'], $data['parentDirectory'])) {
|
||||
throw new SubdirectoryExistsInDirectory();
|
||||
}
|
||||
|
||||
// todo use Directory::create() and rename columns/fields in request
|
||||
// create new database entry
|
||||
$directory = new Directory();
|
||||
$directory->name = $data['name'];
|
||||
$directory->parent_id = $data['parentDirectory'];
|
||||
$directory->user_id = \Auth::user()->id;
|
||||
$directory->description = $data['description'];
|
||||
$directory->save();
|
||||
|
||||
return $directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data array input data
|
||||
*
|
||||
* @return array
|
||||
* @throws SubdirectoryExistsInDirectory
|
||||
*/
|
||||
public function getValidationRules($data = [])
|
||||
{
|
||||
return [
|
||||
'name' => 'required|max:255',
|
||||
'parentDirectory' => 'exists:directories,id'
|
||||
];
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\MenuPresenters;
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\MenuItem;
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
@@ -77,6 +77,6 @@ class FoundationDrilldownMenuPresenter extends Presenter
|
||||
<ul class="vertical menu">
|
||||
' . $this->getChildMenuItems($item) . '
|
||||
</ul>
|
||||
</li>' . PHP_EOL;;
|
||||
</li>' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\MenuPresenters;
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
|
||||
@@ -56,6 +56,6 @@ class FoundationDropdownMenuPresenter extends Presenter
|
||||
<ul class="vertical menu">
|
||||
' . $this->getChildMenuItems($item) . '
|
||||
</ul>
|
||||
</li>' . PHP_EOL;;
|
||||
</li>' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\MenuPresenters;
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
class FoundationInitializedDropdownMenuPresenter extends FoundationDropdownMenuPresenter
|
||||
{
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\MenuPresenters;
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\MenuItem;
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\MenuPresenters;
|
||||
namespace App\CMS\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\MenuItem;
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
@@ -0,0 +1,168 @@
|
||||
<?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,25 +1,32 @@
|
||||
<?php
|
||||
namespace App\Cms\Repositories\ActionLog;
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Class ActionLog
|
||||
*/
|
||||
class ActionLog extends Model
|
||||
class Actions
|
||||
{
|
||||
protected $table = 'action_log';
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'type_id',
|
||||
'user_id',
|
||||
'ip',
|
||||
'user_agent',
|
||||
'parameters'
|
||||
];
|
||||
protected $guarded = [];
|
||||
/**
|
||||
* @param null $userId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLoggedActions($userId = null)
|
||||
{
|
||||
$actions = $this->getLogActionsQuery(true);
|
||||
|
||||
$user = null;
|
||||
if ($userId) {
|
||||
$user = User::findOrFail($userId);
|
||||
$actions->where('users.id', $userId);
|
||||
}
|
||||
|
||||
$actions = $actions->paginate(25);
|
||||
|
||||
$this->translateLogMessages($actions);
|
||||
|
||||
return [$user, $actions];
|
||||
}
|
||||
|
||||
/**
|
||||
* Query factory for loading action logs with their type (therefore with name and value)
|
||||
@@ -36,7 +43,6 @@ class ActionLog extends Model
|
||||
->orderBy('action_log.created_at', 'DESC');
|
||||
|
||||
if ($joinUser) {
|
||||
|
||||
$actions = $actions->join('users', 'users.id', '=', 'action_log.user_id')
|
||||
->select('action_log.*', 'action_log_types.*', 'users.email', 'users.name as user_name');
|
||||
}
|
||||
@@ -75,8 +81,6 @@ class ActionLog extends Model
|
||||
* Method used for translating and filling parameters into value of log.
|
||||
*
|
||||
* @param $messages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function translateLogMessages(&$messages)
|
||||
{
|
||||
@@ -0,0 +1,133 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
$pages = $query->paginate(setting('paginatedResults', 20));
|
||||
|
||||
return $pages;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace App\CMS\Repositories;
|
||||
|
||||
abstract class Repository
|
||||
{
|
||||
protected $model;
|
||||
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array([$this->model, $method], $args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Shortcodes;
|
||||
namespace App\CMS\Shortcodes;
|
||||
|
||||
use App\Models\Widget as WidgetModel;
|
||||
use App\Models\Widgets\Widget as WidgetModel;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class Widget
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
namespace App\Widgets\HtmlCode;
|
||||
namespace App\CMS\Widgets\HtmlCode;
|
||||
|
||||
use App\CMS\Contracts\Widgets\PublicWidget;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Widget;
|
||||
use App\Widgets\Contracts\WidgetRenderer;
|
||||
use App\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Widgets\NonInstallableWidget;
|
||||
use App\Models\Widgets\Widget;
|
||||
|
||||
class HtmlCode extends NonInstallableWidget
|
||||
class HtmlCode implements PublicWidget
|
||||
{
|
||||
/**
|
||||
* Name getter
|
||||
@@ -40,25 +39,17 @@ class HtmlCode extends NonInstallableWidget
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Widget $widget
|
||||
* @param \stdClass $data
|
||||
* @param Request $data
|
||||
*
|
||||
* @return Widget
|
||||
* @return array
|
||||
* @throws MissingParameterException
|
||||
*/
|
||||
public static function save(Widget $widget, \stdClass $data)
|
||||
public static function save(Request $data)
|
||||
{
|
||||
if (!isset($data->code) || empty($data->code)) {
|
||||
throw new MissingParameterException('code');
|
||||
}
|
||||
|
||||
$widgetSettings = [
|
||||
'code' => $data->code,
|
||||
'containerClass' => isset($data->containerClass) ? $data->containerClass : ''
|
||||
];
|
||||
|
||||
$widget->settings = json_encode($widgetSettings);
|
||||
|
||||
return $widget;
|
||||
return ['code' => $data->code];
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace App\Widgets\HtmlCode\Presenters;
|
||||
namespace App\CMS\Widgets\HtmlCode\Presenters;
|
||||
|
||||
use App\Models\Widget;
|
||||
use App\Models\WidgetType;
|
||||
use App\Widgets\Contracts\WidgetRenderer;
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use App\CMS\Contracts\Widgets\WidgetRenderer;
|
||||
|
||||
class HtmlCode implements WidgetRenderer
|
||||
{
|
||||
@@ -52,7 +52,7 @@ class HtmlCode implements WidgetRenderer
|
||||
*/
|
||||
public static function renderEditForm(Widget $widget)
|
||||
{
|
||||
$settings = json_decode($widget->settings);
|
||||
$settings = $widget->settings;
|
||||
return view('admin.widgets.htmlCode.edit', ['widget' => $widget, 'settings' => $settings]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Widgets\Menu\Extensions;
|
||||
namespace App\CMS\Widgets\Menu\Extensions;
|
||||
|
||||
use App\Widgets\Contracts\MenuExtensionHandler;
|
||||
use App\CMS\Widgets\Contracts\MenuExtensionHandler;
|
||||
|
||||
class URL implements MenuExtensionHandler {
|
||||
public function getPossibleValues()
|
||||
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
namespace App\Widgets\Menu;
|
||||
namespace App\CMS\Widgets\Menu;
|
||||
|
||||
use App\Models\Content;
|
||||
use App\Widgets\Contracts\WidgetRenderer;
|
||||
use App\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Widgets\NonInstallableWidget;
|
||||
use App\CMS\Contracts\Widgets\PublicWidget;
|
||||
use App\CMS\Widgets\Contracts\WidgetRenderer;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content\Content;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
||||
|
||||
class Menu extends NonInstallableWidget
|
||||
class Menu implements PublicWidget
|
||||
{
|
||||
/**
|
||||
* Name getter
|
||||
@@ -45,7 +47,7 @@ class Menu extends NonInstallableWidget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function save(\App\Models\Widget $widget, \stdClass $data)
|
||||
public static function save(Request $data)
|
||||
{
|
||||
if (!isset($data->settings) || empty($data->settings) || !json_decode($data->settings)) {
|
||||
throw new MissingParameterException('settings');
|
||||
@@ -60,22 +62,15 @@ class Menu extends NonInstallableWidget
|
||||
}
|
||||
}
|
||||
|
||||
$settings = [
|
||||
'links' => $links,
|
||||
'containerClass' => $data->containerClass
|
||||
];
|
||||
|
||||
$widget->settings = json_encode($settings);
|
||||
|
||||
return $widget;
|
||||
return ['links' => $links];
|
||||
}
|
||||
|
||||
public static function selectContentPages($ids)
|
||||
{
|
||||
$allowedStatuses = [Content::STATUS_PUBLIC];
|
||||
$allowedStatuses = [IContent::STATUS_PUBLIC];
|
||||
|
||||
if (\Auth::user()) {
|
||||
$allowedStatuses[] = Content::STATUS_PROTECTED;
|
||||
$allowedStatuses[] = IContent::STATUS_PROTECTED;
|
||||
}
|
||||
|
||||
$pages = Content::where('language', LaravelLocalization::getCurrentLocale())
|
||||
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
namespace App\Widgets\Menu\Presenters;
|
||||
namespace App\CMS\Widgets\Menu\Presenters;
|
||||
|
||||
use App\Models\Content;
|
||||
use App\Models\Widget;
|
||||
use App\Models\WidgetType;
|
||||
use App\Widgets\Contracts\WidgetRenderer;
|
||||
use App\Widgets\Menu\Menu as WidgetMenu;
|
||||
use App\CMS\Contracts\Repositories\Content as ContentContract;
|
||||
use App\CMS\Contracts\Widgets\WidgetRenderer;
|
||||
use App\CMS\Widgets\Menu\Menu as WidgetMenu;
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
@@ -43,8 +43,9 @@ class Menu implements WidgetRenderer
|
||||
|
||||
$code = '<ul class="menu ' . $widget->container_class . '"';
|
||||
|
||||
if ($widget->container_id)
|
||||
$code .= ' id="'.e($widget->container_id).'"';
|
||||
if ($widget->container_id) {
|
||||
$code .= ' id="' . e($widget->container_id) . '"';
|
||||
}
|
||||
|
||||
$code .= '>';
|
||||
|
||||
@@ -54,8 +55,8 @@ class Menu implements WidgetRenderer
|
||||
}
|
||||
|
||||
$page = $pages[$pageId];
|
||||
$active = ($page->is_homepage && $route == 'page.index') || ($route == 'page.content' && isset($parameters['url']) && $parameters['url'] == $page->url);
|
||||
$route = $page->is_homepage ? route('page.index') : route('page.content', ['url' => $page->url]);
|
||||
$active = ($page->isHomepage && $route == 'page.index') || ($route == 'page.content' && isset($parameters['url']) && $parameters['url'] == $page->url);
|
||||
$route = $page->isHomepage ? route('page.index') : route('page.content', ['url' => $page->url]);
|
||||
|
||||
$code .= '<li';
|
||||
if ($active) {
|
||||
@@ -78,24 +79,19 @@ class Menu implements WidgetRenderer
|
||||
*/
|
||||
public static function renderAddForm(WidgetType $type)
|
||||
{
|
||||
$extensions = App::make('registerMenuExtension')
|
||||
->get();
|
||||
|
||||
$widget = new Widget();
|
||||
$content = new Content();
|
||||
$content = app(ContentContract::class);
|
||||
|
||||
// get list of all pages
|
||||
$pages = $content->getOverview()
|
||||
->get();
|
||||
$pages = $content->getOverview();
|
||||
$widget->settings = new \stdClass();
|
||||
$widget->settings->links = [];
|
||||
|
||||
$widget->settingsObj = new \stdClass();
|
||||
$widget->settingsObj->links = new \stdClass();
|
||||
|
||||
return view('admin.widgets.menu.new', [
|
||||
'type' => $type,
|
||||
'widget' => $widget,
|
||||
'pages' => $pages,
|
||||
'extensions' => $extensions
|
||||
'type' => $type,
|
||||
'widget' => $widget,
|
||||
'pages' => $pages,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -108,20 +104,19 @@ class Menu implements WidgetRenderer
|
||||
*/
|
||||
public static function renderEditForm(Widget $widget)
|
||||
{
|
||||
// $extensions = App::make('registerMenuExtension')
|
||||
// ->get();
|
||||
$content = new Content();
|
||||
/**
|
||||
* @var $content ContentContract
|
||||
*/
|
||||
$content = App::make(ContentContract::class);
|
||||
|
||||
// get list of all pages
|
||||
$pages = $content->getOverview()
|
||||
->get();
|
||||
$pages = $content->getOverview();
|
||||
|
||||
// make object from JSON
|
||||
$widget->settingsObj = json_decode($widget->settings);
|
||||
if (!isset($widget->settingsObj->links)) {
|
||||
if (!isset($widget->settings->links)) {
|
||||
$links = new \stdClass();
|
||||
} else {
|
||||
$links = (array)$widget->settingsObj->links;
|
||||
$links = (array)$widget->settings->links;
|
||||
}
|
||||
|
||||
// sort links using "order"
|
||||
@@ -129,7 +124,7 @@ class Menu implements WidgetRenderer
|
||||
return $a->order - $b->order;
|
||||
});
|
||||
|
||||
$widget->settingsObj->links = (object)$links;
|
||||
$widget->settings->links = (object)$links;
|
||||
|
||||
return view('admin.widgets.menu.edit', ['widget' => $widget, 'pages' => $pages]);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user