diff --git a/app/Console/Commands/Translations.php b/app/Console/Commands/TranslateDirectory.php similarity index 97% rename from app/Console/Commands/Translations.php rename to app/Console/Commands/TranslateDirectory.php index 23911980..22e1bcf5 100644 --- a/app/Console/Commands/Translations.php +++ b/app/Console/Commands/TranslateDirectory.php @@ -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']); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 962299bc..4c3aadf1 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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, diff --git a/app/Handlers/Contracts/BaseModuleHandler.php b/app/Handlers/Contracts/BaseModuleHandler.php index dab8a282..9cd17c6b 100644 --- a/app/Handlers/Contracts/BaseModuleHandler.php +++ b/app/Handlers/Contracts/BaseModuleHandler.php @@ -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(); } \ No newline at end of file diff --git a/app/Handlers/Contracts/ContentTitles.php b/app/Handlers/Contracts/ContentTitles.php new file mode 100644 index 00000000..5d44f24f --- /dev/null +++ b/app/Handlers/Contracts/ContentTitles.php @@ -0,0 +1,40 @@ + 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 diff --git a/app/Http/Controllers/Admin/Contents/EditContent.php b/app/Http/Controllers/Admin/Contents/EditContent.php index 00201cc0..fda4f63e 100644 --- a/app/Http/Controllers/Admin/Contents/EditContent.php +++ b/app/Http/Controllers/Admin/Contents/EditContent.php @@ -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 diff --git a/database/migrations/2016_09_24_175541_FixForeignKeysOnActionLog.php b/database/migrations/2016_09_24_175541_FixForeignKeysOnActionLog.php new file mode 100644 index 00000000..c24b2248 --- /dev/null +++ b/database/migrations/2016_09_24_175541_FixForeignKeysOnActionLog.php @@ -0,0 +1,44 @@ +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 + } +} diff --git a/modules/Blog/Article/Handlers/Article.php b/modules/Blog/Article/Handlers/Article.php index 047be96b..bc5481b9 100644 --- a/modules/Blog/Article/Handlers/Article.php +++ b/modules/Blog/Article/Handlers/Article.php @@ -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'); } } \ No newline at end of file diff --git a/modules/Blog/Article/Providers/ArticleServiceProvider.php b/modules/Blog/Article/Providers/ArticleServiceProvider.php index c05cc17a..188e2fef 100644 --- a/modules/Blog/Article/Providers/ArticleServiceProvider.php +++ b/modules/Blog/Article/Providers/ArticleServiceProvider.php @@ -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'; diff --git a/modules/Blog/Article/Resources/lang/cs/article.php b/modules/Blog/Article/Resources/lang/cs/article.php index 15b79dfb..fd1c65c6 100644 --- a/modules/Blog/Article/Resources/lang/cs/article.php +++ b/modules/Blog/Article/Resources/lang/cs/article.php @@ -2,5 +2,5 @@ return [ "allowComments" => "Povolit komentáře?", "new" => "Napsat", -"overview" => "Všchny články", +"overview" => "Všechny články", ]; diff --git a/modules/Blog/Article/Resources/lang/cs/module.php b/modules/Blog/Article/Resources/lang/cs/module.php index eceb1960..f000fdb7 100644 --- a/modules/Blog/Article/Resources/lang/cs/module.php +++ b/modules/Blog/Article/Resources/lang/cs/module.php @@ -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", ]; diff --git a/modules/Blog/Article/Resources/lang/en/comments.php b/modules/Blog/Article/Resources/lang/en/comments.php index 8eb1d04c..9d8818cd 100644 --- a/modules/Blog/Article/Resources/lang/en/comments.php +++ b/modules/Blog/Article/Resources/lang/en/comments.php @@ -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', + ], + ] ]; \ 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 bf8644c0..8b9f7e18 100644 --- a/modules/Blog/Article/Resources/lang/en/module.php +++ b/modules/Blog/Article/Resources/lang/en/module.php @@ -4,6 +4,8 @@ return [ 'description' => 'Base submodule for blog', 'comments' => 'Comments', 'commentsOverview' => 'All comments', - 'allArticles' => 'All articles', - 'blog' => 'Blog' + 'blog' => 'Blog', + 'allArticles' => 'All articles', + 'newArticle' => 'Write new article', + 'editArticle' => 'Editing article' ]; \ 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 index c7177e63..61a8c751 100644 --- a/modules/Blog/Article/Resources/views/admin/comments/overview.blade.php +++ b/modules/Blog/Article/Resources/views/admin/comments/overview.blade.php @@ -23,8 +23,6 @@
- - - - {{--{{$title}}
+{!! $title !!}
'.trans($homepage->module_name).'
-'.str_limit(strip_tags($homepage->content), 200).'
', + 'title' => $homepage->title.' '.trans($homepage->module_name).'', + 'body' => ''.str_limit(strip_tags($homepage->content), 200).'
', 'footerClass' => 'text-right', 'footer' => '' ]) @@ -37,10 +34,8 @@ Improvement: http://www.html5rocks.com/en/tutorials/dnd/basics/ @include('admin.snippets.card', [ - 'title' => $allPages[$pageId]->title, - 'body' => ' -'.trans($allPages[$pageId]->module_name).'
-'.str_limit(strip_tags($allPages[$pageId]->content), 200).'
', + 'title' => $allPages[$pageId]->title.' '.trans($allPages[$pageId]->module_name).'', + 'body' => ''.str_limit(strip_tags($allPages[$pageId]->content), 200).'
', 'footerClass' => 'text-right', 'footer' => ' @@ -59,21 +54,29 @@ Improvement: http://www.html5rocks.com/en/tutorials/dnd/basics/{{$page->title}}
+{{$page->title}} + @lang($page->module_name) +
- (@lang($page->module_name)) -
-{{str_limit(strip_tags($page->content), 100)}}
+ {{str_limit(strip_tags($page->content), 100)}}