From 35bda2828c35ff5ca084fff64ad2d09affa094b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Fri, 10 Feb 2017 13:45:41 +0100 Subject: [PATCH 1/2] FEATURE: merge template namespace and module alias --- app/Http/Controllers/Controller.php | 2 +- modules/Blog/Article/Config/config.php | 2 +- modules/Blog/Article/Handlers/Article.php | 5 +++-- .../Controllers/Visitor/CreateNewComment.php | 12 +++--------- modules/Blog/Article/Http/routes.php | 2 +- modules/Blog/ArticleList/Config/config.php | 2 +- .../Blog/ArticleList/Handlers/ArticleList.php | 17 ++++++----------- 7 files changed, 16 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 0610b67d..4c01a2dd 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -27,6 +27,6 @@ class Controller extends BaseController { $view = Template::name($template); - return view($view, $data, $mergeData); + return response(view($view, $data, $mergeData))->header('X-Powered-By', strrev('zc.ytiranib.www//:sptth | .o.r.s ytiranib | SMCiniM')); } } diff --git a/modules/Blog/Article/Config/config.php b/modules/Blog/Article/Config/config.php index f509e809..fb19fdc4 100644 --- a/modules/Blog/Article/Config/config.php +++ b/modules/Blog/Article/Config/config.php @@ -4,7 +4,7 @@ return [ 'name' => 'Articles', 'translatedName' => 'article::module.name', 'translatedDescription' => 'article::module.description', - 'alias' => 'blog-article', + 'alias' => 'article', 'handler' => \Modules\Blog\Article\Handlers\Article::class, 'providers' => [\Modules\Blog\Article\Providers\ArticleServiceProvider::class], 'files' => ['start.php'], diff --git a/modules/Blog/Article/Handlers/Article.php b/modules/Blog/Article/Handlers/Article.php index ff9d82d5..f8234344 100644 --- a/modules/Blog/Article/Handlers/Article.php +++ b/modules/Blog/Article/Handlers/Article.php @@ -11,6 +11,7 @@ use App\Models\ActionLog\ActionLogType; use App\Models\Content\Content; use App\Models\Module; use App\Models\User; +use Illuminate\Support\Collection; use Modules\Blog\Article\Entities\Comment; class Article extends Handler implements ContentTitles, AdvancedContentModifier, InstallableModule @@ -25,8 +26,8 @@ class Article extends Handler implements ContentTitles, AdvancedContentModifier, */ public function render(Content $content, $parameters) { - $content->comments = []; - if (isset($content->moduleSettings->allowComments) && $content->moduleSettings->allowComments) { + $content->comments = new Collection(); + if (isset($content->moduleSettings['allowComments']) && $content->moduleSettings['allowComments']) { $content->comments = Comment::where('content_id', $content->id) ->with('author') ->where('approved', 1) diff --git a/modules/Blog/Article/Http/Controllers/Visitor/CreateNewComment.php b/modules/Blog/Article/Http/Controllers/Visitor/CreateNewComment.php index 8af7ba9b..c274f653 100644 --- a/modules/Blog/Article/Http/Controllers/Visitor/CreateNewComment.php +++ b/modules/Blog/Article/Http/Controllers/Visitor/CreateNewComment.php @@ -11,15 +11,9 @@ use Pingpong\Modules\Routing\Controller; class CreateNewComment extends Controller { - public function postNew(\Modules\Blog\Article\Http\Requests\CreateNewComment $request, $articleId) + public function store(\Modules\Blog\Article\Http\Requests\CreateNewComment $request, \Modules\Blog\Article\Entities\Article $article) { - $article = Content::where('id', $articleId) - ->where('moduleHandler', Article::class) - ->firstOrFail(); - - $article->moduleSettings = json_decode($article->moduleSettings); - - if (!isset($article->moduleSettings->allowComments) || !$article->moduleSettings->allowComments) { + if (!isset($article->moduleSettings['allowComments']) || !$article->moduleSettings['allowComments']) { return redirect() ->route('page.content', ['url' => $article->url]) ->with('error', trans('article::comments.disabledComments')); @@ -28,7 +22,7 @@ class CreateNewComment extends Controller $content = $request->message; $user = Auth::user(); if ($user) { - $name = $user->name; + $name = is_null($user->name) ? $user->email : $user->name; $email = $user->email; } else { $name = $request->name; diff --git a/modules/Blog/Article/Http/routes.php b/modules/Blog/Article/Http/routes.php index 2a03f970..145c30ba 100644 --- a/modules/Blog/Article/Http/routes.php +++ b/modules/Blog/Article/Http/routes.php @@ -22,7 +22,7 @@ Route::group([ // public routes Route::group(['middleware' => ['web'], 'namespace' => 'Visitor'], function () { - Route::post('comments/new/{id}', 'CreateNewComment@postNew') + Route::post('comments/new/{article}', 'CreateNewComment@store') ->name('comments.new'); }); }); \ No newline at end of file diff --git a/modules/Blog/ArticleList/Config/config.php b/modules/Blog/ArticleList/Config/config.php index 89dcd425..f4017088 100644 --- a/modules/Blog/ArticleList/Config/config.php +++ b/modules/Blog/ArticleList/Config/config.php @@ -4,7 +4,7 @@ return [ 'name' => 'Article list', 'translatedName' => 'articlelist::module.name', 'translatedDescription' => 'articlelist::module.description', - 'alias' => 'blog-articlelist', + 'alias' => 'articlelist', 'handler' => \Modules\Blog\ArticleList\Handlers\ArticleList::class, 'providers' => [\Modules\Blog\ArticleList\Providers\ArticleListServiceProvider::class], 'files' => ['start.php'], diff --git a/modules/Blog/ArticleList/Handlers/ArticleList.php b/modules/Blog/ArticleList/Handlers/ArticleList.php index 36da6853..fc8c86cf 100644 --- a/modules/Blog/ArticleList/Handlers/ArticleList.php +++ b/modules/Blog/ArticleList/Handlers/ArticleList.php @@ -1,6 +1,7 @@ orderBy('created_at', 'DESC'); // show articles for not-logged users of even for logged onew? - if (!Auth::user()) { - $articles = $articles->where('status', Content::STATUS_PUBLIC); - } else { - $articles = $articles->whereIn('status', [Content::STATUS_PUBLIC, Content::STATUS_PROTECTED]); - } + $articles = !Auth::user() ? $articles->where('status', IContent::STATUS_PUBLIC) : $articles->whereIn('status', [ + IContent::STATUS_PUBLIC, + IContent::STATUS_PROTECTED + ]); // selected articles from archive? self::archive($articles); @@ -129,12 +129,7 @@ class ArticleList extends Handler $articles = $articles->where('user_id', $user->id); } - $articles = $articles->paginate(20); - - // decode module settings - foreach ($articles as $article) { - $article->moduleSettings = json_decode($article->moduleSettings); - } + $articles = $articles->paginate(setting('articlesPerPage', 20)); return Controller::VisitorsView($content->template, [ 'page' => $content, From f69b8f39ad3051b50b903729210635fb0855f6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Fri, 10 Feb 2017 13:49:17 +0100 Subject: [PATCH 2/2] FEATURE: rename alias in database --- ...0_124658_update_alias_for_subdomodules.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 modules/Blog/Database/Migrations/2017_02_10_124658_update_alias_for_subdomodules.php diff --git a/modules/Blog/Database/Migrations/2017_02_10_124658_update_alias_for_subdomodules.php b/modules/Blog/Database/Migrations/2017_02_10_124658_update_alias_for_subdomodules.php new file mode 100644 index 00000000..76970aeb --- /dev/null +++ b/modules/Blog/Database/Migrations/2017_02_10_124658_update_alias_for_subdomodules.php @@ -0,0 +1,34 @@ +update(['alias' => 'articlelist']); + Module::where('alias', 'blog-article') + ->update(['alias' => 'article']); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Module::where('alias', 'articlelist') + ->update(['alias' => 'blog-articlelist']); + Module::where('alias', 'article') + ->update(['alias' => 'blog-article']); + } +}