commit 02bd68543ea1084edbb9fdb966fa7314124caa5d Author: Michal Kváček Date: Tue Aug 22 14:07:21 2017 +0200 FEATURE: move blog module into own repository diff --git a/Article/Config/config.php b/Article/Config/config.php new file mode 100755 index 0000000..fb19fdc --- /dev/null +++ b/Article/Config/config.php @@ -0,0 +1,12 @@ + 'Articles', + 'translatedName' => 'article::module.name', + 'translatedDescription' => 'article::module.description', + 'alias' => 'article', + 'handler' => \Modules\Blog\Article\Handlers\Article::class, + 'providers' => [\Modules\Blog\Article\Providers\ArticleServiceProvider::class], + 'files' => ['start.php'], + 'order' => 0, +]; \ No newline at end of file diff --git a/Article/Entities/Article.php b/Article/Entities/Article.php new file mode 100755 index 0000000..1222a7b --- /dev/null +++ b/Article/Entities/Article.php @@ -0,0 +1,15 @@ +hasMany(Comment::class, 'content_id') + ->where('approved', true); + } +} \ No newline at end of file diff --git a/Article/Entities/Comment.php b/Article/Entities/Comment.php new file mode 100755 index 0000000..25a5e4f --- /dev/null +++ b/Article/Entities/Comment.php @@ -0,0 +1,27 @@ +belongsTo(User::class, 'user_id'); + } + + public function article() + { + return $this->belongsTo(Content::class, 'content_id'); + } +} \ No newline at end of file diff --git a/Article/Events/ApprovedComment.php b/Article/Events/ApprovedComment.php new file mode 100755 index 0000000..3fab72b --- /dev/null +++ b/Article/Events/ApprovedComment.php @@ -0,0 +1,20 @@ +comment = $comment; + } +} \ No newline at end of file diff --git a/Article/Events/CreatedComment.php b/Article/Events/CreatedComment.php new file mode 100755 index 0000000..d21f685 --- /dev/null +++ b/Article/Events/CreatedComment.php @@ -0,0 +1,20 @@ +comment = $comment; + } +} \ No newline at end of file diff --git a/Article/Events/DeletedComment.php b/Article/Events/DeletedComment.php new file mode 100755 index 0000000..048341a --- /dev/null +++ b/Article/Events/DeletedComment.php @@ -0,0 +1,20 @@ +comment = $comment; + } +} \ No newline at end of file diff --git a/Article/Handlers/Article.php b/Article/Handlers/Article.php new file mode 100755 index 0000000..f09ee57 --- /dev/null +++ b/Article/Handlers/Article.php @@ -0,0 +1,153 @@ +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' => config('article.alias')], 10, ['icon' => 'fa fa-fw fa-pencil']); + $sub->route('content.overview', trans('article::article.overview'), ['id' => config('article.alias')], 30, ['icon' => 'fa fa-fw fa-book']); + }, 10, ['icon' => 'fa fa-fw fa-book']); + + $blogSubmenu->route('comments.overview', trans('article::module.commentsOverview'), [], 20, ['icon' => 'fa fa-fw fa-commenting-o']); + } + + /** + * Install module + */ + public static function install() + { + $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); + } + } + + /** + * Uninstalls module + * + * @param Module $module + * + * @return mixed|void + */ + public static function uninstall(Module $module) + { + ActionLogType::whereIn('string_id', ['commentCreated', 'commentDeleted', 'commentApproved']) + ->delete(); + } + + /** + * 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'); + } + + /** + * 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) + { + } + + /** + * Does this module support categories? + * + * @return boolean + */ + public static function supportCategories() + { + return true; + } +} \ No newline at end of file diff --git a/Article/Http/Controllers/Admin/CommentsOverview.php b/Article/Http/Controllers/Admin/CommentsOverview.php new file mode 100644 index 0000000..239bc6d --- /dev/null +++ b/Article/Http/Controllers/Admin/CommentsOverview.php @@ -0,0 +1,19 @@ +with('author') + ->orderBy('approved') + ->orderBy('created_at', 'DESC') + ->paginate(25); + + return view('article::admin/comments.overview', ['comments' => $comments]); + } +} \ No newline at end of file diff --git a/Article/Http/Controllers/Admin/EditComment.php b/Article/Http/Controllers/Admin/EditComment.php new file mode 100755 index 0000000..bf6f699 --- /dev/null +++ b/Article/Http/Controllers/Admin/EditComment.php @@ -0,0 +1,37 @@ +approved = 1; + $comment->save(); + + Event::fire(new ApprovedComment($comment)); + + return redirect() + ->back() + ->with('success', trans('article::comments.approved')); + } + + public function delete($id) + { + $comment = Comment::findOrFail($id); + + Event::fire(new DeletedComment($comment)); + + $comment->delete(); + + return redirect() + ->back() + ->with('success', trans('article::comments.deleted')); + } +} \ No newline at end of file diff --git a/Article/Http/Controllers/Visitor/CreateNewComment.php b/Article/Http/Controllers/Visitor/CreateNewComment.php new file mode 100644 index 0000000..88ac5c9 --- /dev/null +++ b/Article/Http/Controllers/Visitor/CreateNewComment.php @@ -0,0 +1,49 @@ +moduleSettings['allowComments']) || !$article->moduleSettings['allowComments']) { + return redirect() + ->route('page.content', ['url' => $article->url]) + ->with('error', trans('article::comments.disabledComments')); + } + + $content = $request->message; + $user = Auth::user(); + if ($user) { + $name = is_null($user->name) ? $user->email : $user->name; + $email = $user->email; + } else { + $name = $request->name; + $email = $request->email; + } + + $comment = Comment::create([ + 'user_id' => $user ? $user->id : null, + 'content_id' => $article->id, + 'name' => $name, + 'email' => $email, + 'content' => $content, + 'approved' => !is_null($user) + ]); + + // fire event about new comment + Event::fire(new CreatedComment($comment)); + + return redirect() + ->route('page.content', ['url' => $article->url]) + ->with('success', trans('article::comments.saved')); + } +} \ No newline at end of file diff --git a/Article/Http/Requests/CreateNewComment.php b/Article/Http/Requests/CreateNewComment.php new file mode 100755 index 0000000..18044f4 --- /dev/null +++ b/Article/Http/Requests/CreateNewComment.php @@ -0,0 +1,28 @@ + 'required']; + + if (!$user) { + $required['name'] = 'required'; + $required['email'] = 'required|email'; + } + + return $required; + } +} diff --git a/Article/Http/routes.php b/Article/Http/routes.php new file mode 100755 index 0000000..145c30b --- /dev/null +++ b/Article/Http/routes.php @@ -0,0 +1,28 @@ + LaravelLocalization::setLocale(), + 'namespace' => 'Modules\Blog\Article\Http\Controllers' + ], function () { + Route::group([ + 'middleware' => ['admin'], + 'prefix' => 'admin/comments', + 'namespace' => 'Admin' + ], function () { + + Route::get('/', 'CommentsOverview@getOverview') + ->name('comments.overview'); + + Route::get('/delete/{id}', 'EditComment@delete') + ->name('comments.delete'); + + Route::get('/approve/{id}', 'EditComment@approve') + ->name('comments.approve'); + }); + + // public routes + Route::group(['middleware' => ['web'], 'namespace' => 'Visitor'], function () { + + Route::post('comments/new/{article}', 'CreateNewComment@store') + ->name('comments.new'); + }); +}); \ No newline at end of file diff --git a/Article/Listeners/LogCommentApproval.php b/Article/Listeners/LogCommentApproval.php new file mode 100755 index 0000000..2ff4f14 --- /dev/null +++ b/Article/Listeners/LogCommentApproval.php @@ -0,0 +1,35 @@ + $event->comment->name, + 'email' => $event->comment->email, + 'content' => $event->comment->content + ]; + + $this->saveLog($parameters); + } + + /** + * Getter for action name. Used only internally + * + * @return mixed + */ + protected function getName() + { + return 'commentApproved'; + } +} \ No newline at end of file diff --git a/Article/Listeners/LogDeletedComment.php b/Article/Listeners/LogDeletedComment.php new file mode 100755 index 0000000..0a016e0 --- /dev/null +++ b/Article/Listeners/LogDeletedComment.php @@ -0,0 +1,35 @@ + $event->comment->name, + 'email' => $event->comment->email, + 'content' => $event->comment->content + ]; + + $this->saveLog($parameters); + } + + /** + * Getter for action name. Used only internally + * + * @return mixed + */ + protected function getName() + { + return 'commentDeleted'; + } +} \ No newline at end of file diff --git a/Article/Listeners/LogNewComment.php b/Article/Listeners/LogNewComment.php new file mode 100755 index 0000000..d2e6e31 --- /dev/null +++ b/Article/Listeners/LogNewComment.php @@ -0,0 +1,40 @@ +comment->user_id) { + return; + } + + $parameters = [ + 'author' => $event->comment->name, + 'email' => $event->comment->email, + 'content' => $event->comment->content + ]; + + $this->saveLog($parameters); + } + + /** + * Getter for action name. Used only internally + * + * @return mixed + */ + protected function getName() + { + return 'commentCreated'; + } +} \ No newline at end of file diff --git a/Article/Modificators/PerexCreator.php b/Article/Modificators/PerexCreator.php new file mode 100755 index 0000000..ad76b0b --- /dev/null +++ b/Article/Modificators/PerexCreator.php @@ -0,0 +1,60 @@ +DOMDocument = new \DOMDocument('1.0', 'UTF-8'); + $this->maxLength = 300; + $this->maxImages = 2; + $this->perex = ''; + } + + private function addHtml($node) + { + $this->perex .= strip_tags($this->DOMDocument->saveHTML($node), '

'); + } + + public function create($html) + { + if (empty($html)) { + return null; + } + + $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); + $this->DOMDocument->loadHTML($html); + + $texts = $this->DOMDocument->getElementsByTagName('p'); + $images = $this->DOMDocument->getElementsByTagName('img'); + $iframes = $this->DOMDocument->getElementsByTagName('iframe'); + + $textId = 0; + $imgId = 0; + if ($texts->length > 1) { + $this->addHtml($texts[$textId++]); + } + + if (mb_strlen($this->perex) < $this->maxLength) { + if ($iframes->length > 0) { + $this->perex .= $this->DOMDocument->saveHTML($iframes[0]); + } elseif ($images->length > 0) { + while ($imgId < $images->length && $imgId < $this->maxImages) { + $this->perex .= $this->DOMDocument->saveHTML($images[$imgId++]); + } + } else { + while (mb_strlen($this->perex) < $this->maxLength && $textId < $texts->length) { + $this->addHtml($texts[$textId++]); + } + } + } + + return $this->perex; + } +} \ No newline at end of file diff --git a/Article/Pipeline/DisplayContent/LoadCommentsForBlogpost.php b/Article/Pipeline/DisplayContent/LoadCommentsForBlogpost.php new file mode 100755 index 0000000..575f924 --- /dev/null +++ b/Article/Pipeline/DisplayContent/LoadCommentsForBlogpost.php @@ -0,0 +1,33 @@ +moduleHandler != Article::class) + return; + + $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) + ->orderBy('created_at') + ->get(); + } + } +} \ No newline at end of file diff --git a/Article/Pipeline/SaveContent/TurnCommentsOnOrOff.php b/Article/Pipeline/SaveContent/TurnCommentsOnOrOff.php new file mode 100755 index 0000000..f52e4bc --- /dev/null +++ b/Article/Pipeline/SaveContent/TurnCommentsOnOrOff.php @@ -0,0 +1,29 @@ +moduleHandler, '\\') !== Article::class) { + return; + } + + $settings = $content->moduleSettings; + $settings['allowComments'] = isset($input['allowComments']) ? (int)$input['allowComments'] : 0; + $content->moduleSettings = $settings; + $content->save(); + } +} \ No newline at end of file diff --git a/Article/Providers/ArticleEventServiceProvider.php b/Article/Providers/ArticleEventServiceProvider.php new file mode 100644 index 0000000..08287d0 --- /dev/null +++ b/Article/Providers/ArticleEventServiceProvider.php @@ -0,0 +1,26 @@ + [LogCommentApproval::class], + DeletedComment::class => [LogDeletedComment::class], + CreatedComment::class => [LogNewComment::class], + ]; +} \ No newline at end of file diff --git a/Article/Providers/ArticleServiceProvider.php b/Article/Providers/ArticleServiceProvider.php new file mode 100644 index 0000000..5967f16 --- /dev/null +++ b/Article/Providers/ArticleServiceProvider.php @@ -0,0 +1,34 @@ +app->register(ArticleEventServiceProvider::class); + + // load comments for blogpost + app('displayPipeline')->add(LoadCommentsForBlogpost::class); + + app('saveContentPipeline')->add(TurnCommentsOnOrOff::class); + } + + protected function setModuleAlias() + { + $this->alias = 'article'; + } + + protected function setModulePath() + { + $this->path = __DIR__; + } +} diff --git a/Article/Resources/lang/cs/article.php b/Article/Resources/lang/cs/article.php new file mode 100755 index 0000000..fd1c65c --- /dev/null +++ b/Article/Resources/lang/cs/article.php @@ -0,0 +1,6 @@ + "Povolit komentáře?", +"new" => "Napsat", +"overview" => "Všechny články", +]; diff --git a/Article/Resources/lang/cs/comments.php b/Article/Resources/lang/cs/comments.php new file mode 100755 index 0000000..fa9aca6 --- /dev/null +++ b/Article/Resources/lang/cs/comments.php @@ -0,0 +1,22 @@ + "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", + "events" => [ + "descriptions" => [ + "commentApproved" => "Schválen komentář od autora :authro (:email) s následujícím obsahem: :content", + "commentCreated" => "Přidán komentář od autora :author (e-mail :e-mail) s následujícím obsahem: :content", + "commentDeleted" => "Smazán komentář od autora :author (:email) s následujícím obsahem: :content", + ], + "names" => [ + "commentApproved" => "Komentář schválen", + "commentCreated" => "Komentář úspěšně přidán.", + "commentDeleted" => "Smazán komentář", + ], + ], + "noComments" => "Nejsou dostupné žádné komentáře", + "unknownArticle" => "Neznámý článek", +]; diff --git a/Article/Resources/lang/cs/module.php b/Article/Resources/lang/cs/module.php new file mode 100755 index 0000000..22653ca --- /dev/null +++ b/Article/Resources/lang/cs/module.php @@ -0,0 +1,12 @@ + "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.", + "editArticle" => "Upravuji článek", + "name" => "Články", + "newArticle" => "Napsat nový článek", + "templatePath" => "Články", +]; diff --git a/Article/Resources/lang/en/article.php b/Article/Resources/lang/en/article.php new file mode 100755 index 0000000..2d1e8b4 --- /dev/null +++ b/Article/Resources/lang/en/article.php @@ -0,0 +1,6 @@ + 'Allow comments?', + 'new' => 'Write new', + 'overview' => 'All articles' +]; \ No newline at end of file diff --git a/Article/Resources/lang/en/comments.php b/Article/Resources/lang/en/comments.php new file mode 100755 index 0000000..de5e730 --- /dev/null +++ b/Article/Resources/lang/en/comments.php @@ -0,0 +1,22 @@ + 'Created at :date', + 'commentedArticle' => 'Article', + 'approve' => 'Approve comment', + 'approved' => 'Comment successfully approved', + 'deleted' => 'Comment deleted', + 'unknownArticle' => 'Unknown article', + '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/Article/Resources/lang/en/module.php b/Article/Resources/lang/en/module.php new file mode 100755 index 0000000..1e27294 --- /dev/null +++ b/Article/Resources/lang/en/module.php @@ -0,0 +1,12 @@ + 'Articles', + 'description' => 'Base submodule for blog', + 'comments' => 'Comments', + 'commentsOverview' => 'All comments', + 'blog' => 'Blog', + 'allArticles' => 'All articles', + 'newArticle' => 'Write new article', + 'editArticle' => 'Editing article', + 'templatePath' => 'Articles', +]; \ No newline at end of file diff --git a/Article/Resources/lang/sk/article.php b/Article/Resources/lang/sk/article.php new file mode 100755 index 0000000..2a3ce3a --- /dev/null +++ b/Article/Resources/lang/sk/article.php @@ -0,0 +1,6 @@ + "Povoliť komentáre?", + "new" => " Napísať nový", + "overview" => "Všetky články", +]; diff --git a/Article/Resources/lang/sk/comments.php b/Article/Resources/lang/sk/comments.php new file mode 100755 index 0000000..5bde58a --- /dev/null +++ b/Article/Resources/lang/sk/comments.php @@ -0,0 +1,8 @@ + "Schváliť komentár", + "approved" => "Komentár úspešne schválený.", + "commentedArticle" => "Článok", + "createdAt" => "Vytvorené: :date", + "deleted" => "Komentár zmazaný.", +]; diff --git a/Article/Resources/lang/sk/module.php b/Article/Resources/lang/sk/module.php new file mode 100755 index 0000000..04b574c --- /dev/null +++ b/Article/Resources/lang/sk/module.php @@ -0,0 +1,9 @@ + "Všetky články", + "blog" => "Blog", + "comments" => "Komentáre", + "commentsOverview" => "Všetky komentáre", + "description" => "Základný submodul pre blog", + "name" => "Články", +]; diff --git a/Article/Resources/views/admin/comments/overview.blade.php b/Article/Resources/views/admin/comments/overview.blade.php new file mode 100755 index 0000000..adccff8 --- /dev/null +++ b/Article/Resources/views/admin/comments/overview.blade.php @@ -0,0 +1,56 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', trans('article::module.comments')) + +@section('content') + @if (count($comments)) + @foreach($comments as $comment) + +

+
+
+

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

+
+
+
+

+ {{$comment->content}} +

+
+ +
+ @endforeach + @else +
+ @lang('article::comments.noComments') +
+ @endif +@endsection \ No newline at end of file diff --git a/Article/Resources/views/admin/content/basicInfo.blade.php b/Article/Resources/views/admin/content/basicInfo.blade.php new file mode 100755 index 0000000..dd80811 --- /dev/null +++ b/Article/Resources/views/admin/content/basicInfo.blade.php @@ -0,0 +1,89 @@ +
+
+ + + @include('admin.snippets.hasError', ['field' => 'title']) +
+
+ + + + @include('admin.snippets.hasError', ['field' => 'url']) +
+
+ +
+
+ +
+
+ + + @include('admin.snippets.hasError', ['field' => 'status']) +
+
+ + + @include('admin.snippets.hasError', ['field' => 'parentPage']) +
+ +
+ +
+ + @if($module->support_categories && count($categories)) +
+ +
+ @endif +
+ +
+
+ +
+
+ + + + + diff --git a/Article/module.json b/Article/module.json new file mode 100755 index 0000000..4b5f2ac --- /dev/null +++ b/Article/module.json @@ -0,0 +1,14 @@ +{ + "name": "Blog\/Article", + "description": "article::module.description", + "alias": "article", + "providers": [ + "Modules\\Blog\\Article\\Providers\\ArticleServiceProvider" + ], + "aliases": [], + "order": 0, + "files": [ + "start.php" + ], + "active": 1 +} \ No newline at end of file diff --git a/Article/start.php b/Article/start.php new file mode 100755 index 0000000..7d8ae75 --- /dev/null +++ b/Article/start.php @@ -0,0 +1,15 @@ + 'Article list', + 'translatedName' => 'articlelist::module.name', + 'translatedDescription' => 'articlelist::module.description', + 'alias' => 'articlelist', + 'handler' => \Modules\Blog\ArticleList\Handlers\ArticleList::class, + 'providers' => [\Modules\Blog\ArticleList\Providers\ArticleListServiceProvider::class], + 'files' => ['start.php'], + 'order' => 0, +]; \ No newline at end of file diff --git a/ArticleList/Handlers/ArticleList.php b/ArticleList/Handlers/ArticleList.php new file mode 100755 index 0000000..5641925 --- /dev/null +++ b/ArticleList/Handlers/ArticleList.php @@ -0,0 +1,28 @@ +whereTitle(trans('article::module.blog')); + if (!$blogSubmenu) { + $blogSubmenu = $menu->dropdown(trans('article::module.blog'), function ($sub) { + }, 20, ['icon' => 'fa fa-fw fa-book']); + } + + $blogSubmenu->route('content.new', trans('articlelist::module.name'), ['id' => config('articlelist.alias')], 100, ['icon' => 'fa fa-fw fa-list-alt']); + } + + public static function supportCategories() + { + return false; + } +} \ No newline at end of file diff --git a/ArticleList/Http/Controllers/.gitkeep b/ArticleList/Http/Controllers/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/ArticleList/Http/Controllers/ArticleListController.php b/ArticleList/Http/Controllers/ArticleListController.php new file mode 100755 index 0000000..df74232 --- /dev/null +++ b/ArticleList/Http/Controllers/ArticleListController.php @@ -0,0 +1,12 @@ +moduleHandler != ArticleList::class) + return; + + $articles = ArticleModel::where('moduleHandler', Article::class) + ->with('comments') + ->with('category') + ->where(function ($query) { + $query->where('publishedFrom', '<', Carbon::now()) + ->orWhereNull('publishedFrom'); + }) + ->where(function ($query) { + $query->where('publishedTo', '>', Carbon::now()) + ->orWhereNull('publishedTo'); + }) + ->orderBy('publishedFrom', 'DESC') + ->orderBy('created_at', 'DESC'); + + // show articles for not-logged users of even for logged onew? + $articles = !Auth::user() ? $articles->where('status', IContent::STATUS_PUBLIC) : $articles->whereIn('status', [ + IContent::STATUS_PUBLIC, + IContent::STATUS_PROTECTED + ]); + + // selected articles from archive? + $this->archive($articles); + + // is given any category? + $this->category($articles); + + // show articles only from specified user + $author = Input::get('author'); + if ($author) { + $user = User::findOrFail($author); + + $articles = $articles->where('user_id', $user->id); + } + + $page->articles = $articles->paginate(setting('articlesPerPage', 20)); + } + + /** + * Filter articles on article list using archive + * + * @param $articles + */ + protected function archive(&$articles) + { + $year = Input::get('y'); + $month = Input::get('m'); + $day = Input::get('d'); + + if ($year) { + $articles = $articles->where(DB::raw('YEAR(created_at)'), $year); + } + + if ($month) { + $articles = $articles->where(DB::raw('MONTH(created_at)'), $month); + } + + if ($day) { + $articles = $articles->where(DB::raw('DAY(created_at)'), $day); + } + } + + /** + * Filter article list to some specified category + * + * Category URL is specified as GET attribute "category" + * + * @param $articles + */ + protected function category(&$articles) + { + $categoryUrl = Input::get('category'); + + $categoriesEnabled = \Module::get('Categories') + ->enabled(); + + if ($categoryUrl && $categoriesEnabled) { + $category = Category::where('url', $categoryUrl) + ->firstOrFail(); + + $subcategories = $category->getChildren() + ->toArray(); + + $categories = [$category->id]; + $categories = array_merge($categories, array_map(function ($cat) { + return $cat['id']; + }, $subcategories)); + + $articles = $articles->whereIn('category_id', $categories); + } + } +} \ No newline at end of file diff --git a/ArticleList/Providers/ArticleListServiceProvider.php b/ArticleList/Providers/ArticleListServiceProvider.php new file mode 100644 index 0000000..3d5d2c5 --- /dev/null +++ b/ArticleList/Providers/ArticleListServiceProvider.php @@ -0,0 +1,24 @@ +alias = 'articlelist'; + } + + protected function setModulePath() + { + $this->path = __DIR__; + } + + public function boot() + { + parent::boot(); + + app('displayPipeline')->add(LoadArticlesForList::class); + } +} diff --git a/ArticleList/Resources/lang/cs/module.php b/ArticleList/Resources/lang/cs/module.php new file mode 100755 index 0000000..09d24c6 --- /dev/null +++ b/ArticleList/Resources/lang/cs/module.php @@ -0,0 +1,6 @@ + "Modul pro zobrazování seznamu článků na webu.", + "name" => "Seznam článků", + "templatePath" => "Seznam článků", +]; diff --git a/ArticleList/Resources/lang/en/module.php b/ArticleList/Resources/lang/en/module.php new file mode 100755 index 0000000..98b22ac --- /dev/null +++ b/ArticleList/Resources/lang/en/module.php @@ -0,0 +1,6 @@ + 'Article list', + 'description' => 'Module for displaying list of articles on web', + 'templatePath' => 'Article list', +]; \ No newline at end of file diff --git a/ArticleList/Resources/lang/sk/module.php b/ArticleList/Resources/lang/sk/module.php new file mode 100755 index 0000000..2e2a64c --- /dev/null +++ b/ArticleList/Resources/lang/sk/module.php @@ -0,0 +1,5 @@ + "Modul pre zobrazenie zoznamu článkov na webe", + "name" => "Zoznam článkov", +]; diff --git a/ArticleList/Resources/views/admin/.gitkeep b/ArticleList/Resources/views/admin/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/ArticleList/module.json b/ArticleList/module.json new file mode 100755 index 0000000..643a870 --- /dev/null +++ b/ArticleList/module.json @@ -0,0 +1 @@ +{"name":"Blog\/ArticleList","description":"articlelist::module.description","alias":"articlelist","providers":["Modules\\Blog\\ArticleList\\Providers\\ArticleListServiceProvider"],"aliases":[],"order":0,"files":["start.php"],"active":1} \ No newline at end of file diff --git a/ArticleList/start.php b/ArticleList/start.php new file mode 100755 index 0000000..7d8ae75 --- /dev/null +++ b/ArticleList/start.php @@ -0,0 +1,15 @@ +increments('id'); + $table->timestamps(); + $table->integer('user_id') + ->nullable(true) + ->default(null) + ->comment('When comment was inserted by logged user, save his ID here'); + $table->integer('content_id'); + $table->string('email'); + $table->string('name'); + $table->text('content'); + $table->boolean('approved'); + + $table->foreign('content_id') + ->references('id') + ->on('contents') + ->onDelete('cascade') + ->onUpdate('cascade'); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('set null') + ->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('comments'); + } +} diff --git a/Database/Migrations/2017_02_10_124658_update_alias_for_subdomodules.php b/Database/Migrations/2017_02_10_124658_update_alias_for_subdomodules.php new file mode 100755 index 0000000..76970ae --- /dev/null +++ b/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']); + } +} diff --git a/info.php b/info.php new file mode 100755 index 0000000..0c426fe --- /dev/null +++ b/info.php @@ -0,0 +1,7 @@ + 'Blog', + 'translatedName' => 'article::module.blog', + 'description' => 'article.module.blogDescription', + 'hasSubmodules' => true, +]; \ No newline at end of file