Merge branch 'dev' into template_support
This commit is contained in:
@@ -6,7 +6,7 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Translations extends Command
|
||||
class TranslateDirectory extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
@@ -40,7 +40,8 @@ class Translations extends Command
|
||||
|
||||
$modulePath = dirname(dirname($dir));
|
||||
|
||||
if (is_dir(base_path($modulePath . '/Resources/lang'))) {
|
||||
// does exist directory with translations?
|
||||
if (is_dir(base_path($modulePath . '/Resources/lang')) || file_exists(base_path($modulePath.DIRECTORY_SEPARATOR.'info.php'))) {
|
||||
$modules = File::directories($modulePath);
|
||||
foreach ($modules as $module) {
|
||||
$this->call('translate:dir', ['dir' => $module . '/Resources/lang']);
|
||||
@@ -18,7 +18,7 @@ class Kernel extends ConsoleKernel
|
||||
Commands\ChangePassword::class,
|
||||
Commands\InstallModule::class,
|
||||
Commands\InstallAllModules::class,
|
||||
Commands\Translations::class,
|
||||
Commands\TranslateDirectory::class,
|
||||
Commands\TranslateAll::class,
|
||||
Commands\InitDatabaseSchema::class,
|
||||
Commands\SetTemplate::class,
|
||||
|
||||
@@ -5,8 +5,6 @@ use App\Models\User;
|
||||
|
||||
interface BaseModuleHandler
|
||||
{
|
||||
// public static function getModuleId();
|
||||
|
||||
/**
|
||||
* Register admin menu (or multiple ones)
|
||||
*
|
||||
@@ -18,9 +16,10 @@ interface BaseModuleHandler
|
||||
public static function registerAdminMenu(User $user);
|
||||
|
||||
/**
|
||||
* Install module
|
||||
* Install module.
|
||||
*
|
||||
* @return mixed
|
||||
* This method is called after inserting info about module into database. It can be called only using Artisan in
|
||||
* CLI.
|
||||
*/
|
||||
public static function install();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
|
||||
use App\Models\Content;
|
||||
|
||||
/**
|
||||
* Interface ContentTitles
|
||||
*
|
||||
* Classes which implement this interface get the ability to rewrite default text on edit/create/overview of content
|
||||
* page.
|
||||
*
|
||||
* @package App\Handlers\Contracts
|
||||
*/
|
||||
interface ContentTitles
|
||||
{
|
||||
/**
|
||||
* Get translated title for pages overview of given type.
|
||||
*
|
||||
* This value is used for rendering list of all content pages of given type in administration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getOverviewTitle();
|
||||
|
||||
/**
|
||||
* Title displayed above for for creating new content page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCreateNewTitle();
|
||||
|
||||
/**
|
||||
* Title for form displayed for editin content page
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getEditTitle(Content $content);
|
||||
}
|
||||
@@ -17,6 +17,13 @@ use Modules\Categories\Entities\Category;
|
||||
use Pingpong\Modules\Facades\Module as ModuleInstance;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class CreateNewContent
|
||||
*
|
||||
* Controller for creating new content page.
|
||||
*
|
||||
* @package App\Http\Controllers\Admin\Contents
|
||||
*/
|
||||
class CreateNewContent extends Controller
|
||||
{
|
||||
/**
|
||||
@@ -28,6 +35,14 @@ class CreateNewContent extends Controller
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* CreateNewContent constructor.
|
||||
*
|
||||
* Sets File and Content models into class variables
|
||||
*
|
||||
* @param File $file
|
||||
* @param Content $content
|
||||
*/
|
||||
public function __construct(File $file, Content $content)
|
||||
{
|
||||
parent::__construct();
|
||||
@@ -47,12 +62,19 @@ class CreateNewContent extends Controller
|
||||
$module = Module::findOrFail($moduleId);
|
||||
$statuses = ContentStatuses::getWithTranslations();
|
||||
|
||||
// set default page title
|
||||
$pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]);
|
||||
if (is_callable([$module->handler, 'getCreateNewTitle'])) {
|
||||
$pageHeading = call_user_func([$module->handler, 'getCreateNewTitle']);
|
||||
}
|
||||
|
||||
// get list of usable templates
|
||||
$templates = Template::where('module_id', $moduleId)
|
||||
->select(['template_name', 'name', 'description'])
|
||||
->get();
|
||||
$categoryModule = ModuleInstance::get('categories');
|
||||
|
||||
// add categories, if supported
|
||||
$categoryModule = ModuleInstance::get('categories');
|
||||
$categories = [];
|
||||
if ($module->support_categories && $categoryModule->enabled()) {
|
||||
$categories = Category::where('module_id', $moduleId)
|
||||
@@ -64,6 +86,7 @@ class CreateNewContent extends Controller
|
||||
|
||||
// render view
|
||||
return view('admin.content.new', [
|
||||
'pageHeading' => $pageHeading,
|
||||
'contentStatuses' => $statuses,
|
||||
'templates' => $templates,
|
||||
'moduleId' => $moduleId,
|
||||
@@ -89,7 +112,6 @@ class CreateNewContent extends Controller
|
||||
*/
|
||||
public function postNew(CreateNewContentRequest $request, $moduleId)
|
||||
{
|
||||
$page = new Content();
|
||||
try {
|
||||
$module = Module::findOrFail($moduleId);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
@@ -99,6 +121,10 @@ class CreateNewContent extends Controller
|
||||
->with('error', trans('admin/contents.invalidModule'));
|
||||
}
|
||||
|
||||
// create new page
|
||||
$page = new Content();
|
||||
$page->template = $request->template;
|
||||
|
||||
// setup basic info
|
||||
$page->user_id = \Auth::user()->id;
|
||||
$page->language = LaravelLocalization::getCurrentLocale();
|
||||
@@ -110,10 +136,10 @@ class CreateNewContent extends Controller
|
||||
$page->meta_description = $request->metaDescription;
|
||||
$page->content = $request->pageContent;
|
||||
$page->status = $request->status;
|
||||
$page->template = $request->template;
|
||||
$page->module_handler = $module->handler;
|
||||
$page->category_id = (int)$request->category > 0 ? $request->category : null;
|
||||
|
||||
// is any parent page specified?
|
||||
if ($request->parentPage) {
|
||||
$page->parent_id = $request->parentPage;
|
||||
}
|
||||
@@ -124,12 +150,12 @@ class CreateNewContent extends Controller
|
||||
$page->title_photo = $file ? $file['filename'] : null;
|
||||
|
||||
// let template to modify request and content page
|
||||
|
||||
call_user_func_array([CurrentTemplate::handler(), 'beforeSave'], [&$page, $request]);
|
||||
|
||||
// save module-specific stuff
|
||||
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
|
||||
|
||||
// save content of page before (possible) uploading related files
|
||||
$page->save();
|
||||
|
||||
// upload files assigned to content page
|
||||
|
||||
@@ -35,6 +35,14 @@ class EditContent extends Controller
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* EditContent constructor.
|
||||
*
|
||||
* Load ContentHistory and File into this controller
|
||||
*
|
||||
* @param ContentHistory $history
|
||||
* @param File $file
|
||||
*/
|
||||
public function __construct(ContentHistory $history, File $file)
|
||||
{
|
||||
$this->history = $history;
|
||||
@@ -61,6 +69,11 @@ class EditContent extends Controller
|
||||
$module = Module::where('handler', $page->module_handler)
|
||||
->firstOrFail();
|
||||
|
||||
$pageHeading = trans('admin/contents.edit', ['name' => e($page->title)]);
|
||||
if (is_callable([$module->handler, 'getCreateNewTitle'])) {
|
||||
$pageHeading = call_user_func([$module->handler, 'getEditTitle'], $page);
|
||||
}
|
||||
|
||||
// get all Blade templates for rendering page
|
||||
$templates = Template::where('module_id', $module->id)
|
||||
->select(['template_name', 'name', 'description'])
|
||||
@@ -83,6 +96,7 @@ class EditContent extends Controller
|
||||
|
||||
// render view
|
||||
return view('admin.content.edit', [
|
||||
'pageHeading' => $pageHeading,
|
||||
'contentStatuses' => $statuses,
|
||||
'page' => $page,
|
||||
'module' => $module,
|
||||
@@ -286,7 +300,7 @@ class EditContent extends Controller
|
||||
} catch (NotFoundHttpException $e) {
|
||||
// page not found
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
->back()
|
||||
->with('error', trans('admin/contents.invalidPage'));
|
||||
}
|
||||
|
||||
@@ -301,7 +315,7 @@ class EditContent extends Controller
|
||||
// was something changed?
|
||||
if ($changedColumns == 0) {
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
->back()
|
||||
->with('error', trans('admin/contents.nothingToEdit'));
|
||||
}
|
||||
|
||||
@@ -310,7 +324,7 @@ class EditContent extends Controller
|
||||
|
||||
// redirect back to overview with info for user
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
->back()
|
||||
->with('success', trans('admin/contents.homepageSetup', [
|
||||
'name' => $page->title,
|
||||
'url' => $page->url
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class FixForeignKeysOnActionLog extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('action_log', function (Blueprint $table) {
|
||||
$table->dropForeign('fk_action_log_action_log_type1');
|
||||
$table->dropForeign('fk_action_log_user1');
|
||||
|
||||
|
||||
$table->foreign('type_id')
|
||||
->references('id')
|
||||
->on('action_log_types')
|
||||
->onDelete('cascade')
|
||||
->onUpdate('cascade');
|
||||
|
||||
|
||||
$table->foreign('user_id')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->onDelete('cascade')
|
||||
->onUpdate('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,17 @@
|
||||
namespace Modules\Blog\Article\Handlers;
|
||||
|
||||
use App\Enumerations\ModulesHandlerToId;
|
||||
use App\Handlers\Contracts\ContentTitles;
|
||||
use App\Handlers\Handler;
|
||||
use App\Http\Controllers\Admin\EditContent;
|
||||
use App\Http\Controllers\Admin\Contents\EditContent;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\ActionLogType;
|
||||
use App\Models\Content;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Modules\Blog\Article\Entities\Comment;
|
||||
|
||||
class Article extends Handler
|
||||
class Article extends Handler implements ContentTitles
|
||||
{
|
||||
/**
|
||||
* Render given module into visitor area.
|
||||
@@ -89,12 +90,8 @@ class Article extends Handler
|
||||
return $changedColumns;
|
||||
}
|
||||
|
||||
public static function getOverviewTitle()
|
||||
{
|
||||
return trans('article::module.allArticles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register admin menu
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
@@ -131,12 +128,63 @@ class Article extends Handler
|
||||
|
||||
/**
|
||||
* Install module
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
// seed action log types
|
||||
// Artisan::call('')
|
||||
$types = [
|
||||
[
|
||||
'string_id' => 'commentCreated',
|
||||
'name' => 'article::comments.events.names.commentCreated',
|
||||
'value' => 'article::comments.events.descriptions.commentCreated',
|
||||
],
|
||||
[
|
||||
'string_id' => 'commentDeleted',
|
||||
'name' => 'article::comments.events.names.commentDeleted',
|
||||
'value' => 'article::comments.events.descriptions.commentDeleted',
|
||||
],
|
||||
[
|
||||
'string_id' => 'commentApproved',
|
||||
'name' => 'article::comments.events.names.commentApproved',
|
||||
'value' => 'article::comments.events.descriptions.commentApproved',
|
||||
],
|
||||
|
||||
];
|
||||
foreach ($types as $type) {
|
||||
ActionLogType::create($type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translated title for pages overview of given type.
|
||||
*
|
||||
* This value is used for rendering list of all content pages of given type in administration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getOverviewTitle()
|
||||
{
|
||||
return trans('article::module.allArticles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Title displayed above for for creating new content page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCreateNewTitle()
|
||||
{
|
||||
return trans('article::module.newArticle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Title for form displayed for editin content page
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getEditTitle(Content $content)
|
||||
{
|
||||
return trans('article::module.editArticle');
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class ArticleServiceProvider extends ServiceProvider {
|
||||
$viewPath = base_path('resources/views/modules/article');
|
||||
$sourcePath = __DIR__.'/../Resources/views';
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath]);
|
||||
$this->publishes([$sourcePath => $viewPath], 'module-views');
|
||||
|
||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||
return $path . '/modules/article';
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
return [
|
||||
"allowComments" => "Povolit komentáře?",
|
||||
"new" => "Napsat",
|
||||
"overview" => "Všchny články",
|
||||
"overview" => "Všechny články",
|
||||
];
|
||||
|
||||
@@ -5,5 +5,7 @@ return [
|
||||
"comments" => "Komentáře",
|
||||
"commentsOverview" => "Všechny komentáře",
|
||||
"description" => "Základní submodul pro blog. Tento modul umožňuje psát články.",
|
||||
"editArticle" => "Upravuji článek",
|
||||
"name" => "Články",
|
||||
"newArticle" => "Napsat nový článek",
|
||||
];
|
||||
|
||||
@@ -4,5 +4,18 @@ return [
|
||||
'commentedArticle' => 'Article',
|
||||
'approve' => 'Approve comment',
|
||||
'approved' => 'Comment successfully approved',
|
||||
'deleted' => 'Comment deleted'
|
||||
'deleted' => 'Comment deleted',
|
||||
'noComments' => 'No comments available',
|
||||
'events' => [
|
||||
'names' => [
|
||||
'commentCreated' => 'Added comment',
|
||||
'commentApproved' => 'Approved comment',
|
||||
'commentDeleted' => 'Deleted comment',
|
||||
],
|
||||
'descriptions' => [
|
||||
'commentCreated' => 'Added comment from author :author with e-mail :email and following content: :content',
|
||||
'commentApproved' => 'Approved comment from author :author with e-mail :email and following content: :content',
|
||||
'commentDeleted' => 'Deleted comment from author :author with e-mail :email and following content: :content',
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -4,6 +4,8 @@ return [
|
||||
'description' => 'Base submodule for blog',
|
||||
'comments' => 'Comments',
|
||||
'commentsOverview' => 'All comments',
|
||||
'blog' => 'Blog',
|
||||
'allArticles' => 'All articles',
|
||||
'blog' => 'Blog'
|
||||
'newArticle' => 'Write new article',
|
||||
'editArticle' => 'Editing article'
|
||||
];
|
||||
@@ -23,8 +23,6 @@
|
||||
<div class="card-footer">
|
||||
@lang('article::comments.createdAt', ['date' => \App\Helpers\Template::date($comment->created_at)]) |
|
||||
|
||||
|
||||
|
||||
@lang('article::comments.commentedArticle'): <a href="{{route('page.content', ['url' => $comment->article->url])}}" target="_blank">
|
||||
{{$comment->article->title}}
|
||||
</a>
|
||||
@@ -35,30 +33,11 @@
|
||||
data-toggle="tooltip"><i class="fa fa-fw fa-check"></i></a>
|
||||
@endif
|
||||
|
||||
<a href="{{route('comments.delete', ['id' => $comment->id])}}" class="btn btn-sm btn-warning"><i class="fa fa-fw fa-trash"></i></a>
|
||||
<a href="{{route('comments.delete', ['id' => $comment->id])}}" class="btn btn-sm confirm btn-warning"><i class="fa fa-fw fa-trash"></i></a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
{{--<div class="comment row">--}}
|
||||
{{--<div class="col-lg-2">--}}
|
||||
{{--<img class="img-rounded" src="@gravatar($comment->author->email)" alt="">--}}
|
||||
|
||||
{{--{{$comment->author->name}}--}}
|
||||
|
||||
{{--@date($comment->created_at)--}}
|
||||
|
||||
{{--</div>--}}
|
||||
{{--<div class="col-lg-10">{{$comment->content}}</div>--}}
|
||||
{{--<div class="col-lg2">--}}
|
||||
|
||||
|
||||
|
||||
{{--</div>--}}
|
||||
{{--</div>--}}
|
||||
@endforeach
|
||||
@else
|
||||
<div class="alert alert-info">
|
||||
|
||||
+8
@@ -14383,3 +14383,11 @@ img {
|
||||
padding-top: 15px;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
.card .card-header .title {
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
.card .card-header .title small {
|
||||
padding-left: 10px;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('admin/contents.edit', ['name' => e($page->title)]))
|
||||
@section('pageHeading', $pageHeading)
|
||||
|
||||
@section('content')
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('admin/contents.new', ['name' => $moduleName]))
|
||||
@section('pageHeading', trans($pageHeading))
|
||||
|
||||
@section('content')
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="card {{isset($type) ? 'card-'.$type : 'card-default'}}">
|
||||
<div class="card-header">
|
||||
<div class="header-block">
|
||||
<p class="title"> {{$title}} </p>
|
||||
<p class="title"> {!! $title !!} </p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-block">
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Templates\Base\OnePage\Events;
|
||||
|
||||
use App\Models\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AddPageIntoHomepage {
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Content
|
||||
*/
|
||||
public $page;
|
||||
|
||||
public function __construct(Content $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Templates\Base\OnePage\Events;
|
||||
|
||||
use App\Models\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class RemovePageFromHomepage {
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Content
|
||||
*/
|
||||
public $page;
|
||||
|
||||
public function __construct(Content $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,10 @@ namespace Templates\Base\OnePage\Handlers;
|
||||
use App\Handlers\Contracts\TemplateHandler;
|
||||
use App\Helpers\PageRenderer;
|
||||
use App\Helpers\Settings;
|
||||
use App\Models\ActionLogType;
|
||||
use App\Models\Content;
|
||||
use App\Models\Module;
|
||||
use App\Models\Settings as SettingsModel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
@@ -58,13 +60,14 @@ abstract class OnePage implements TemplateHandler
|
||||
// create real content from pages
|
||||
$pagesRaw = $pagesInTemplates = [];
|
||||
foreach ($pages as $page) {
|
||||
// save pages as models only
|
||||
$pagesRaw[$page->url] = $page;
|
||||
|
||||
// save rendered pages
|
||||
$pagesInTemplates[$page->url] = PageRenderer::render($page)
|
||||
->render();
|
||||
}
|
||||
|
||||
// dd($pagesRaw);
|
||||
|
||||
// return pages into template
|
||||
return ['pagesHtml' => $pagesInTemplates, 'pagesRaw' => $pagesRaw];
|
||||
}
|
||||
@@ -74,14 +77,42 @@ abstract class OnePage implements TemplateHandler
|
||||
|
||||
/**
|
||||
* Install module
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
// register action log types
|
||||
|
||||
$types = [
|
||||
[
|
||||
'string_id' => 'pageRemovedFromHomepage',
|
||||
'name' => 'template::admin/setHomepage.events.names.removedPage',
|
||||
'value' => 'template::admin/setHomepage.events.descriptions.removedPage',
|
||||
],
|
||||
[
|
||||
'string_id' => 'pageAddedIntoHomepage',
|
||||
'name' => 'template::admin/setHomepage.events.names.addedPage',
|
||||
'value' => 'template::admin/setHomepage.events.descriptions.addedPage',
|
||||
],
|
||||
|
||||
];
|
||||
foreach ($types as $type) {
|
||||
ActionLogType::create($type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall template
|
||||
*
|
||||
* @param Module $template
|
||||
*/
|
||||
public static function uninstall(Module $template)
|
||||
{
|
||||
// delete action log types
|
||||
ActionLogType::whereIn('string_id', ['pageRemovedFromHomepage', 'pageAddedIntoHomepage'])
|
||||
->delete();
|
||||
|
||||
// delete settings with pages on homepage
|
||||
SettingsModel::where('key', self::HOMEPAGE_PAGES_SETTINGS_KEY)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,11 @@ namespace Templates\Base\OnePage\Http\Controllers\Admin;
|
||||
use App\Helpers\Settings;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Models\Content;
|
||||
use App\Models\Settings as SettingsModel;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
use Templates\Base\OnePage\Events\AddPageIntoHomepage;
|
||||
use Templates\Base\OnePage\Events\RemovePageFromHomepage;
|
||||
use Templates\Base\OnePage\Handlers\OnePage;
|
||||
|
||||
class SetHomepage extends Controller
|
||||
@@ -79,19 +83,19 @@ class SetHomepage extends Controller
|
||||
{
|
||||
$page = Content::findOrFail($id);
|
||||
|
||||
if ($page->is_template) {
|
||||
if ($page->is_homepage) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans('template::admin/setHomepage.cannotSetHomepageAsPartOfHomepage'));
|
||||
}
|
||||
|
||||
// try to get page config
|
||||
$settingsEntry = \App\Models\Settings::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
|
||||
$settingsEntry = SettingsModel::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->first();
|
||||
|
||||
if (!$settingsEntry) {
|
||||
$settingsEntry = new \App\Models\Settings();
|
||||
$settingsEntry = new SettingsModel();
|
||||
$settingsEntry->language = LaravelLocalization::getCurrentLocale();
|
||||
$settingsEntry->key = OnePage::HOMEPAGE_PAGES_SETTINGS_KEY;
|
||||
$usedPagesIds = [];
|
||||
@@ -99,6 +103,7 @@ class SetHomepage extends Controller
|
||||
$usedPagesIds = (array)json_decode($settingsEntry->value);
|
||||
}
|
||||
|
||||
// add page into list of used pages - if not already there
|
||||
if (!in_array($id, $usedPagesIds)) {
|
||||
$usedPagesIds[] = $id;
|
||||
}
|
||||
@@ -106,6 +111,9 @@ class SetHomepage extends Controller
|
||||
$settingsEntry->value = json_encode($usedPagesIds);
|
||||
$settingsEntry->save();
|
||||
|
||||
// inform other application parts about this event
|
||||
Event::fire(new AddPageIntoHomepage($page));
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('template::admin/setHomepage.successfullyAdded'));
|
||||
@@ -122,6 +130,8 @@ class SetHomepage extends Controller
|
||||
{
|
||||
$pages = (array)json_decode(Settings::get(OnePage::HOMEPAGE_PAGES_SETTINGS_KEY, '{}'));
|
||||
|
||||
$page = Content::findOrFail($id);
|
||||
|
||||
if (!in_array($id, $pages)) {
|
||||
return redirect()
|
||||
->back()
|
||||
@@ -135,10 +145,13 @@ class SetHomepage extends Controller
|
||||
$pages = array_values($pages);
|
||||
|
||||
// update in database
|
||||
\App\Models\Settings::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
|
||||
SettingsModel::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->update(['value' => json_encode($pages)]);
|
||||
|
||||
// inform other application parts about this event
|
||||
Event::fire(new RemovePageFromHomepage($page));
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('template::admin/setHomepage.successfullyRemoved'));
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Templates\Base\OnePage\Listeners;
|
||||
|
||||
use App\Listeners\Logger;
|
||||
use Templates\Base\OnePage\Events\AddPageIntoHomepage;
|
||||
|
||||
class LogAddingPage extends Logger
|
||||
{
|
||||
public function handle(AddPageIntoHomepage $event)
|
||||
{
|
||||
$parameters = [
|
||||
'id' => $event->page->id,
|
||||
'title' => $event->page->title
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
protected function getName()
|
||||
{
|
||||
return 'pageAddedIntoHomepage';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Templates\Base\OnePage\Listeners;
|
||||
|
||||
use App\Listeners\Logger;
|
||||
use Templates\Base\OnePage\Events\RemovePageFromHomepage;
|
||||
|
||||
class LogRemovingPage extends Logger
|
||||
{
|
||||
public function handle(RemovePageFromHomepage $event)
|
||||
{
|
||||
$parameters = [
|
||||
'id' => $event->page->id,
|
||||
'title' => $event->page->title
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
protected function getName()
|
||||
{
|
||||
return 'pageRemovedFromHomepage';
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,17 @@ namespace Templates\Base\OnePage\Providers;
|
||||
|
||||
use App\Events\SetHomepage;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Templates\Base\OnePage\Events\AddPageIntoHomepage;
|
||||
use Templates\Base\OnePage\Events\RemovePageFromHomepage;
|
||||
use Templates\Base\OnePage\Listeners\HomepageChanged;
|
||||
use Templates\Base\OnePage\Listeners\LogAddingPage;
|
||||
use Templates\Base\OnePage\Listeners\LogRemovingPage;
|
||||
|
||||
class EventProvider extends ServiceProvider
|
||||
{
|
||||
protected $listen = [
|
||||
SetHomepage::class => [HomepageChanged::class]
|
||||
SetHomepage::class => [HomepageChanged::class],
|
||||
AddPageIntoHomepage::class => [LogAddingPage::class],
|
||||
RemovePageFromHomepage::class => [LogRemovingPage::class],
|
||||
];
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
"cannotSetHomepageAsPartOfHomepage" => "No toto? Jak mám nastavit domovskou stárnku jako podstránku sama sebe?",
|
||||
"invalidPageId" => "Nelze odebrat stránku z titulní strany, neboť uvedené ID neexistuje.",
|
||||
"noPagesAvailable" => "Žádné stránky k dispozici.",
|
||||
"noPagesSelected" => "Nebyla vybrána žádná stránka pro zobrazení na titulní straně. Zatím...",
|
||||
|
||||
@@ -11,6 +11,16 @@ return [
|
||||
'notUsedPages' => 'Not used pages',
|
||||
'reallyRemovePage' => 'Do you really want to remove this page from homepage?',
|
||||
'cannotSetHomepageAsPartOfHomepage' => 'Cannot set currently set homepage as one of homepage pages.',
|
||||
'noHomepageSet' => 'No homepage set, following settings will not take effect!'
|
||||
|
||||
'noHomepageSet' => 'No homepage set, following settings will not take effect!',
|
||||
'addToHomepage' => 'Add page into homepage',
|
||||
'events' => [
|
||||
'names' => [
|
||||
'removedPage' => 'Removed page from homepage',
|
||||
'addedPage' => 'Added page into homepage'
|
||||
],
|
||||
'descriptions' => [
|
||||
'removedPage' => 'Removed page #:id ":title" from homepage.',
|
||||
'addedPage' => 'Added page #:id ":title" into homepage.'
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -11,14 +11,11 @@ Improvement: http://www.html5rocks.com/en/tutorials/dnd/basics/
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
|
||||
@if(isset($homepage))
|
||||
@include('admin.snippets.card', [
|
||||
'type' => 'primary',
|
||||
'title' => $homepage->title,
|
||||
'body' => '
|
||||
<p><small>'.trans($homepage->module_name).'</small></p>
|
||||
<p>'.str_limit(strip_tags($homepage->content), 200).'</p>',
|
||||
'title' => $homepage->title.' <small>'.trans($homepage->module_name).'</small>',
|
||||
'body' => '<p>'.str_limit(strip_tags($homepage->content), 200).'</p>',
|
||||
'footerClass' => 'text-right',
|
||||
'footer' => '<a href="'.route('content.edit', ['id' => $homepage->id]).'" class="btn btn-secondary btn-sm"><i class="fa fa-fw fa-pencil"></i></a>'
|
||||
])
|
||||
@@ -37,10 +34,8 @@ Improvement: http://www.html5rocks.com/en/tutorials/dnd/basics/
|
||||
|
||||
|
||||
@include('admin.snippets.card', [
|
||||
'title' => $allPages[$pageId]->title,
|
||||
'body' => '
|
||||
<p><small>'.trans($allPages[$pageId]->module_name).'</small></p>
|
||||
<p>'.str_limit(strip_tags($allPages[$pageId]->content), 200).'</p>',
|
||||
'title' => $allPages[$pageId]->title.' <small>'.trans($allPages[$pageId]->module_name).'</small>',
|
||||
'body' => '<p>'.str_limit(strip_tags($allPages[$pageId]->content), 200).'</p>',
|
||||
'footerClass' => 'text-right',
|
||||
'footer' => '
|
||||
<a href="'.route('content.edit', ['id' => $allPages[$pageId]->id]).'" class="btn btn-secondary btn-sm"><i class="fa fa-fw fa-pencil"></i></a>
|
||||
@@ -59,21 +54,29 @@ Improvement: http://www.html5rocks.com/en/tutorials/dnd/basics/
|
||||
<div class="card card-default">
|
||||
<div class="card-header">
|
||||
<div class="header-block">
|
||||
<p class="title">{{$page->title}}</p>
|
||||
<p class="title">{{$page->title}}
|
||||
<small>@lang($page->module_name)</small>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-block">
|
||||
<p>
|
||||
<small>(@lang($page->module_name))</small>
|
||||
</p>
|
||||
<p>{{str_limit(strip_tags($page->content), 100)}}</p>
|
||||
{{str_limit(strip_tags($page->content), 100)}}
|
||||
</div>
|
||||
<div class="card-footer text-right">
|
||||
<a href="{{route('content.edit', ['id' => $page->id])}}"
|
||||
class="btn btn-secondary btn-sm"><i
|
||||
class="fa fa-fw fa-pencil"></i></a>
|
||||
@if(!$page->is_homepage)
|
||||
<a href="{{route('content.setHomepage', ['id' => $page->id])}}"
|
||||
class="btn btn-secondary confirm btn-sm"
|
||||
data-toggle="tooltip" title="@lang('admin/contents.setHomepage')">
|
||||
<i class="fa fa-home"></i>
|
||||
</a>
|
||||
@endif
|
||||
<a href="{{route('template.homepage.addPage', ['id' => $page->id])}}"
|
||||
class="btn btn-sm btn-primary"><i class="fa green fa-fw fa-plus"></i></a>
|
||||
class="btn btn-sm btn-primary" data-toggle="tooltip"
|
||||
title="@lang('template::admin/setHomepage.addToHomepage')"><i
|
||||
class="fa green fa-fw fa-plus"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
|
||||
@@ -31,8 +31,13 @@ class Handler extends OnePage
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Install template
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
parent::install();
|
||||
|
||||
try {
|
||||
Artisan::call('install-module', ['name' => 'StaticPages']);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user