diff --git a/app/Console/Commands/InstallModule.php b/app/Console/Commands/InstallModule.php index 2a9a0c7c..ad5fffc5 100644 --- a/app/Console/Commands/InstallModule.php +++ b/app/Console/Commands/InstallModule.php @@ -40,8 +40,6 @@ class InstallModule extends Command /** * Execute the console command. - * - * @return mixed */ public function handle() { @@ -56,6 +54,9 @@ class InstallModule extends Command // get config $config = $this->loadConfig(); + if (empty($config)) + return; + // check if it is valid $this->checkMandatoryFields($config); @@ -78,6 +79,9 @@ class InstallModule extends Command $basePath = $this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR; $path = $basePath . 'Config' . DIRECTORY_SEPARATOR . 'config.php'; + if (basename($basePath) == 'Database') + return []; + // check if module has Config/config.php file if (!file_exists($path)) { $path = $basePath . 'info.php'; diff --git a/app/Console/Commands/Translations.php b/app/Console/Commands/Translations.php index aca0693c..333cb971 100644 --- a/app/Console/Commands/Translations.php +++ b/app/Console/Commands/Translations.php @@ -38,6 +38,15 @@ class Translations extends Command if (!is_dir($defaultLocalesDir)) { // this is the place for checking for submodules + + $modulePath = dirname(dirname($dir)); + + if (file_exists($modulePath . '/info.php')) { + $modules = File::directories($modulePath); + foreach ($modules as $module) { + $this->call('translate:dir', ['dir' => $module . '/Resources/lang']); + } + } return; } diff --git a/app/Handlers/Registrators/TemplateRegistrator.php b/app/Handlers/Registrators/TemplateRegistrator.php index 6788df67..0af44c8e 100644 --- a/app/Handlers/Registrators/TemplateRegistrator.php +++ b/app/Handlers/Registrators/TemplateRegistrator.php @@ -197,8 +197,6 @@ class TemplateRegistrator 'editable' => 1 ]; - echo 'ukladam do db '.$templateName."\n"; - // save template into database $newTemplate = Template::create($params); diff --git a/app/Http/Controllers/Admin/ContentOverview.php b/app/Http/Controllers/Admin/ContentOverview.php index d6b95f39..f026f209 100644 --- a/app/Http/Controllers/Admin/ContentOverview.php +++ b/app/Http/Controllers/Admin/ContentOverview.php @@ -32,11 +32,16 @@ class ContentOverview extends Controller { $moduleFilterHandler = false; $perPage = Input::get('perPage') ? Input::get('perPage') : 20; + $pageHeading = 'admin/contents.overview'; // does user want to filter results using module? if (is_numeric($moduleId)) { $module = Module::findOrFail($moduleId); $moduleFilterHandler = $module->handler; + + if (is_callable([$module->handler, 'getOverviewTitle'])) { + $pageHeading = call_user_func([$module->handler, 'getOverviewTitle']); + } } // get pages for overview @@ -47,10 +52,11 @@ class ContentOverview extends Controller $homepage = $this->content->getHomepage(); return view('admin.content.overview', [ - 'pages' => $pages, - 'homepage' => $homepage, - 'statuses' => ContentStatuses::getWithTranslations(), - 'module' => isset($module) ? $module : null + 'pages' => $pages, + 'homepage' => $homepage, + 'pageHeading' => $pageHeading, + 'statuses' => ContentStatuses::getWithTranslations(), + 'module' => isset($module) ? $module : null ]); } } \ No newline at end of file diff --git a/app/Http/Controllers/Admin/CreateNewContent.php b/app/Http/Controllers/Admin/CreateNewContent.php index 1beee33b..bb7fd2f9 100644 --- a/app/Http/Controllers/Admin/CreateNewContent.php +++ b/app/Http/Controllers/Admin/CreateNewContent.php @@ -116,7 +116,9 @@ class CreateNewContent extends Controller } // upload file - if provided - $page->uploadTitlePhoto($request); + $file = $page->uploadTitlePhoto($request); + + $page->title_photo = $file ? $file['filename'] : null; // save module-specific stuff call_user_func_array([$module->handler, 'createNew'], [&$page, $request]); diff --git a/app/Http/Controllers/Admin/EditContent.php b/app/Http/Controllers/Admin/EditContent.php index cae69a9a..f9122625 100644 --- a/app/Http/Controllers/Admin/EditContent.php +++ b/app/Http/Controllers/Admin/EditContent.php @@ -118,12 +118,14 @@ class EditContent extends Controller ->with('error', trans('admin/contents.invalidPage')); } + // upload file - if provided + $file = $page->uploadTitlePhoto($request); + $request->url = Str::slug($request->url); $request->parentPage = $request->parentPage ? $request->parentPage : null; - $request->titlePhotoFilename = $page->title_photo; - // upload file - if provided - $page->uploadTitlePhoto($request); + $request->titlePhotoFilename = $file ? $file['filename'] : null; + // array of fields in database and fields from request $fields = [ @@ -142,7 +144,8 @@ class EditContent extends Controller ]; // save new values with history - $data = self::getFields($request, $fields); + $data = self::getFields($request, array_values($fields)); + list($revision, $changedColumns) = $page->updateWithHistory($fields, $data); $changedColumns += call_user_func_array([$page->module_handler, 'edit'], [&$page, $request, $revision]); diff --git a/app/Http/Controllers/Visitor/ContentPage.php b/app/Http/Controllers/Visitor/ContentPage.php index 1ea86abb..9c7293ad 100644 --- a/app/Http/Controllers/Visitor/ContentPage.php +++ b/app/Http/Controllers/Visitor/ContentPage.php @@ -53,6 +53,9 @@ class ContentPage extends Controller // add one new "view" for page $page->view(); + // decode module settings + $page->module_settings = json_decode($page->module_settings); + // get handler $handler = new $page->module_handler; diff --git a/app/Models/Content.php b/app/Models/Content.php index 19128cfe..6bd88997 100644 --- a/app/Models/Content.php +++ b/app/Models/Content.php @@ -293,10 +293,10 @@ class Content extends Model public function uploadTitlePhoto(Request $request) { if ($request->hasFile('titlePhoto')) { - $file = $this->file->upload($request->file('titlePhoto'), $request); - - $this->title_photo = $file['filename']; + return $this->file->upload($request->file('titlePhoto'), $request); } + + return null; } /** diff --git a/app/Providers/GlobalViewDataProvider.php b/app/Providers/GlobalViewDataProvider.php index c0c92845..3b7193b2 100644 --- a/app/Providers/GlobalViewDataProvider.php +++ b/app/Providers/GlobalViewDataProvider.php @@ -73,6 +73,14 @@ class GlobalViewDataProvider extends ServiceProvider return preg_replace($pattern, $code, $view); }); + // shortcut for displaying Gravatar + Blade::extend(function ($view) { + $pattern = $this->createPattern('gravatar'); + $code = ''; + + return preg_replace($pattern, $code, $view); + }); + // shortcut for assets (placed in /public/assets/ Blade::extend(function ($view) { $pattern = $this->createPattern('asset'); diff --git a/modules/Blog/Article/Entities/Comment.php b/modules/Blog/Article/Entities/Comment.php new file mode 100644 index 00000000..4b42d711 --- /dev/null +++ b/modules/Blog/Article/Entities/Comment.php @@ -0,0 +1,26 @@ +belongsTo(User::class, 'user_id'); + } + + public function article() + { + return $this->belongsTo(Content::class, 'content_id'); + } +} \ No newline at end of file diff --git a/modules/Blog/Article/Http/Controllers/.gitkeep b/modules/Blog/Article/Events/ApprovedComment.php similarity index 100% rename from modules/Blog/Article/Http/Controllers/.gitkeep rename to modules/Blog/Article/Events/ApprovedComment.php diff --git a/modules/Blog/ArticleList/Assets/.gitkeep b/modules/Blog/Article/Events/DeletedComment.php similarity index 100% rename from modules/Blog/ArticleList/Assets/.gitkeep rename to modules/Blog/Article/Events/DeletedComment.php diff --git a/modules/Blog/Article/Handlers/Article.php b/modules/Blog/Article/Handlers/Article.php index 90d0f39d..2b58be8d 100644 --- a/modules/Blog/Article/Handlers/Article.php +++ b/modules/Blog/Article/Handlers/Article.php @@ -8,6 +8,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Request; use App\Models\Content; use App\Models\User; +use Modules\Blog\Article\Entities\Comment; class Article extends Handler { @@ -21,6 +22,14 @@ class Article extends Handler */ public function render(Content $content, $parameters) { + $content->comments = []; + if (isset($content->module_settings->allowComments) && $content->module_settings->allowComments) { + $content->comments = Comment::where('content_id', $content->id) + ->where('approved', 1) + ->orderBy('created_at') + ->get(); + } + return Controller::VisitorsView($content->template, ['page' => $content]); } @@ -79,6 +88,11 @@ class Article extends Handler return $changedColumns; } + public static function getOverviewTitle() + { + return trans('article::module.allArticles'); + } + /** * * @param User $user @@ -89,10 +103,20 @@ class Article extends Handler $menu = \Menu::instance('mainMenu'); - $menu->dropdown(trans('article::module.name'), function ($sub) { + $blogSubmenu = $menu->whereTitle(trans('article::module.blog')); + if (!$blogSubmenu) { + $blogSubmenu = $menu->dropdown(trans('article::module.blog'), function ($sub) { + }, 20, ['icon' => 'fa fa-fw fa-book']); + } + + $blogSubmenu->dropdown(trans('article::module.name'), function ($sub) { $sub->route('content.new', trans('article::article.new'), ['id' => self::getModuleId()], 10, ['icon' => 'fa fa-fw fa-pencil']); $sub->route('content.overview', trans('article::article.overview'), ['id' => self::getModuleId()], 30, ['icon' => 'fa fa-fw fa-book']); }, 10, ['icon' => 'fa fa-fw fa-book']); + + $blogSubmenu->dropdown(trans('article::module.comments'), function ($sub) { + $sub->route('comments.overview', trans('article::module.commentsOverview'), [], 10, ['icon' => 'fa fa-fw fa-commenting-o']); + }, 20, ['icon' => 'fa fa-fw fa-comments-o']); } public static function getModuleId() diff --git a/modules/Blog/Article/Http/Controllers/Admin/CommentsOverview.php b/modules/Blog/Article/Http/Controllers/Admin/CommentsOverview.php new file mode 100644 index 00000000..8e55b3b9 --- /dev/null +++ b/modules/Blog/Article/Http/Controllers/Admin/CommentsOverview.php @@ -0,0 +1,19 @@ +with('author') + ->orderBy('approved') + ->orderBy('created_at', 'DESC') + ->paginate(20); + + return view('article::admin/comments.overview', ['comments' => $comments]); + } +} \ No newline at end of file diff --git a/modules/Blog/Article/Http/Controllers/Admin/EditComment.php b/modules/Blog/Article/Http/Controllers/Admin/EditComment.php new file mode 100644 index 00000000..ed4de413 --- /dev/null +++ b/modules/Blog/Article/Http/Controllers/Admin/EditComment.php @@ -0,0 +1,33 @@ +approved = 1; + $comment->save(); + + // Event::fire(ApprovedComment); + + return redirect() + ->back() + ->with('success', trans('article::comments.approved')); + } + + public function delete($id) + { + $comment = Comment::findOrFail($id); + $comment->delete(); + + // Event::fire(DeletedComment); + + return redirect() + ->back() + ->with('success', trans('article::comments.deleted')); + } +} \ No newline at end of file diff --git a/modules/Blog/Article/Http/Controllers/Visitor/CreateNewComment.php b/modules/Blog/Article/Http/Controllers/Visitor/CreateNewComment.php new file mode 100644 index 00000000..3a5b17ac --- /dev/null +++ b/modules/Blog/Article/Http/Controllers/Visitor/CreateNewComment.php @@ -0,0 +1,48 @@ +where('module_handler', Article::class) + ->firstOrFail(); + + $article->module_settings = json_decode($article->module_settings); + + if (!isset($article->module_settings->allowComments) || !$article->module_settings->allowComments) { + return redirect() + ->route('page.content', ['url' => $article->url]) + ->with('error', trans('article::comments.disabledComments')); + } + + $content = $request->message; + $user = Auth::user(); + if ($user) { + $name = $user->name; + $email = $user->email; + } else { + $name = $request->name; + $email = $request->email; + } + + Comment::create([ + 'user_id' => $user ? $user->id : null, + 'content_id' => $article->id, + 'name' => $name, + 'email' => $email, + 'content' => $content + ]); + + return redirect() + ->route('page.content', ['url' => $article->url]) + ->with('success', trans('article::comments.saved')); + } +} \ No newline at end of file diff --git a/modules/Blog/Article/Http/Requests/CreateNewComment.php b/modules/Blog/Article/Http/Requests/CreateNewComment.php new file mode 100644 index 00000000..18044f43 --- /dev/null +++ b/modules/Blog/Article/Http/Requests/CreateNewComment.php @@ -0,0 +1,28 @@ + 'required']; + + if (!$user) { + $required['name'] = 'required'; + $required['email'] = 'required|email'; + } + + return $required; + } +} diff --git a/modules/Blog/Article/Http/routes.php b/modules/Blog/Article/Http/routes.php index b9ad36f4..de6f6be4 100644 --- a/modules/Blog/Article/Http/routes.php +++ b/modules/Blog/Article/Http/routes.php @@ -1,25 +1,28 @@ 'web', - 'prefix' => 'article', - 'namespace' => 'Modules\Blog\Article\Http\Controllers' + 'middleware' => ['web', 'auth', 'adminMenu'], + 'prefix' => 'admin/comments', + 'namespace' => 'Modules\Blog\Article\Http\Controllers\Admin' ], function () { - Route::get('/', 'CategoriesOverview@getOverview') - ->name('article.overview'); - Route::get('/new', 'CreateNewCategory@getNew') - ->name('article.new'); + Route::get('/', 'CommentsOverview@getOverview') + ->name('comments.overview'); - Route::post('/new', 'CreateNewCategory@postNew') - ->name('article.postNew'); + Route::get('/delete/{id}', 'EditComment@delete') + ->name('comments.delete'); - Route::get('/edit/{id}', 'EditCategory@getEdit') - ->name('article.edit'); + Route::get('/approve/{id}', 'EditComment@approve') + ->name('comments.approve'); +}); - Route::post('/edit/{id}', 'EditCategory@postEdit') - ->name('article.postEdit'); +Route::group([ + 'middleware' => ['web'], + 'prefix' => 'comments', + 'namespace' => 'Modules\Blog\Article\Http\Controllers\Visitor' + ], function () { - Route::get('/delete/{id}', 'EditCategory@delete') - ->name('article.delete'); + Route::post('/new/{id}', 'CreateNewComment@postNew') + ->name('comments.new'); }); \ No newline at end of file diff --git a/modules/Blog/ArticleList/Config/.gitkeep b/modules/Blog/Article/Listeners/CommentEditLogger.php similarity index 100% rename from modules/Blog/ArticleList/Config/.gitkeep rename to modules/Blog/Article/Listeners/CommentEditLogger.php diff --git a/modules/Blog/ArticleList/Console/.gitkeep b/modules/Blog/Article/Providers/ArticleEventServiceProvider.php similarity index 100% rename from modules/Blog/ArticleList/Console/.gitkeep rename to modules/Blog/Article/Providers/ArticleEventServiceProvider.php diff --git a/modules/Blog/Article/Resources/lang/cs/article.php b/modules/Blog/Article/Resources/lang/cs/article.php new file mode 100644 index 00000000..15b79dfb --- /dev/null +++ b/modules/Blog/Article/Resources/lang/cs/article.php @@ -0,0 +1,6 @@ + "Povolit komentáře?", +"new" => "Napsat", +"overview" => "Všchny články", +]; diff --git a/modules/Blog/Article/Resources/lang/cs/comments.php b/modules/Blog/Article/Resources/lang/cs/comments.php new file mode 100644 index 00000000..12062efe --- /dev/null +++ b/modules/Blog/Article/Resources/lang/cs/comments.php @@ -0,0 +1,8 @@ + "Schválit komentář a zobrazovat ho u článku", +"approved" => "Komentář úspěšně schválen", +"commentedArticle" => "Komentovaný článek", +"createdAt" => "Vloženo :date", +"deleted" => "Komentář smazán", +]; diff --git a/modules/Blog/Article/Resources/lang/cs/module.php b/modules/Blog/Article/Resources/lang/cs/module.php new file mode 100644 index 00000000..eceb1960 --- /dev/null +++ b/modules/Blog/Article/Resources/lang/cs/module.php @@ -0,0 +1,9 @@ + "Všechny články", +"blog" => "Blog", +"comments" => "Komentáře", +"commentsOverview" => "Všechny komentáře", +"description" => "Základní submodul pro blog. Tento modul umožňuje psát články.", +"name" => "Články", +]; diff --git a/modules/Blog/Article/Resources/lang/en/comments.php b/modules/Blog/Article/Resources/lang/en/comments.php new file mode 100644 index 00000000..8eb1d04c --- /dev/null +++ b/modules/Blog/Article/Resources/lang/en/comments.php @@ -0,0 +1,8 @@ + 'Created at :date', + 'commentedArticle' => 'Article', + 'approve' => 'Approve comment', + 'approved' => 'Comment successfully approved', + 'deleted' => 'Comment deleted' +]; \ No newline at end of file diff --git a/modules/Blog/Article/Resources/lang/en/module.php b/modules/Blog/Article/Resources/lang/en/module.php index a448c978..bf8644c0 100644 --- a/modules/Blog/Article/Resources/lang/en/module.php +++ b/modules/Blog/Article/Resources/lang/en/module.php @@ -1,5 +1,9 @@ 'Article', - 'description' => 'Base submodule for blog' + 'name' => 'Articles', + 'description' => 'Base submodule for blog', + 'comments' => 'Comments', + 'commentsOverview' => 'All comments', + 'allArticles' => 'All articles', + 'blog' => 'Blog' ]; \ No newline at end of file diff --git a/modules/Blog/Article/Resources/views/admin/comments/overview.blade.php b/modules/Blog/Article/Resources/views/admin/comments/overview.blade.php new file mode 100644 index 00000000..c7177e63 --- /dev/null +++ b/modules/Blog/Article/Resources/views/admin/comments/overview.blade.php @@ -0,0 +1,68 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', trans('article::module.comments')) + +@section('content') + @if (count($comments)) + @foreach($comments as $comment) + +
+
+
+

+ + {{$comment->author->name}} ({{$comment->author->email}}) +

+
+
+
+

+ {{$comment->content}} +

+
+ +
+ + + + {{--
--}} + {{--
--}} + {{----}} + + {{--{{$comment->author->name}}--}} + + {{--@date($comment->created_at)--}} + + {{--
--}} + {{--
{{$comment->content}}
--}} + {{--
--}} + + + + {{--
--}} + {{--
--}} + @endforeach + @else +
+ @lang('article::comments.noComments') +
+ @endif +@endsection \ No newline at end of file diff --git a/modules/Blog/Article/Resources/views/admin/content/basicInfo.blade.php b/modules/Blog/Article/Resources/views/admin/content/basicInfo.blade.php index e150c58f..ec02b51e 100644 --- a/modules/Blog/Article/Resources/views/admin/content/basicInfo.blade.php +++ b/modules/Blog/Article/Resources/views/admin/content/basicInfo.blade.php @@ -1,89 +1,89 @@
-
-