From 2e05dab43f4eed16987db3f734b34caaa9a877c5 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Fri, 15 Jan 2016 14:33:19 +0100 Subject: [PATCH 01/10] lang switcher --- src/resources/views/admin/_form.blade.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/resources/views/admin/_form.blade.php b/src/resources/views/admin/_form.blade.php index bed3860..ef712ed 100644 --- a/src/resources/views/admin/_form.blade.php +++ b/src/resources/views/admin/_form.blade.php @@ -29,24 +29,11 @@ - - @include('core::admin._tabs-lang-form', ['target' => 'content']) - -
- - @foreach ($locales as $lang) - -
- @include('core::form._title-and-slug') - - {!! BootForm::checkbox(trans('validation.attributes.online'), $lang.'[status]') !!} - {!! BootForm::textarea(trans('validation.attributes.summary'), $lang.'[summary]')->rows(4) !!} - {!! BootForm::textarea(trans('validation.attributes.body'), $lang.'[body]')->addClass('ckeditor') !!} -
- - @endforeach - -
+ @include('core::form._title-and-slug') + {!! TranslatableBootForm::hidden('status')->value(0) !!} + {!! TranslatableBootForm::checkbox(trans('validation.attributes.online'), 'status') !!} + {!! TranslatableBootForm::textarea(trans('validation.attributes.summary'), 'summary')->rows(4) !!} + {!! TranslatableBootForm::textarea(trans('validation.attributes.body'), 'body')->addClass('ckeditor') !!} From 8723cc63a270f266cb057344e9e6c2697493a812 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Fri, 15 Jan 2016 17:09:10 +0100 Subject: [PATCH 02/10] require core 2.7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e15d07f..51adb1b 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "typicms/core": "~2.6.0" + "typicms/core": "~2.7.0" }, "autoload": { "psr-4": { From 2fe0d347369301595be20194171bf0c51d4b45e0 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Sat, 16 Jan 2016 23:24:16 +0100 Subject: [PATCH 03/10] lang-switcher tpl --- src/resources/views/admin/_index.blade.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/resources/views/admin/_index.blade.php b/src/resources/views/admin/_index.blade.php index ebf2640..c37f424 100644 --- a/src/resources/views/admin/_index.blade.php +++ b/src/resources/views/admin/_index.blade.php @@ -5,7 +5,9 @@ @{{ models.length }} @choice('news::global.news', 2) - @include('core::admin._tabs-lang-list') +
+ @include('core::admin._lang-switcher') +
From 08ce913da91ddc0dae8e33217a072a6c1d72c276 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Mon, 18 Jan 2016 21:45:48 +0100 Subject: [PATCH 04/10] slug unique --- .../2013_11_07_185433_create_news_table.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/database/migrations/2013_11_07_185433_create_news_table.php b/src/database/migrations/2013_11_07_185433_create_news_table.php index cf20c5c..e7698fc 100644 --- a/src/database/migrations/2013_11_07_185433_create_news_table.php +++ b/src/database/migrations/2013_11_07_185433_create_news_table.php @@ -14,35 +14,26 @@ public function up() { Schema::create('news', function (Blueprint $table) { $table->engine = 'InnoDB'; - $table->increments('id'); $table->date('date'); $table->string('image')->nullable(); - $table->timestamps(); }); Schema::create('news_translations', function (Blueprint $table) { $table->engine = 'InnoDB'; - $table->increments('id'); $table->integer('news_id')->unsigned(); - $table->string('locale')->index(); - $table->boolean('status')->default(0); - $table->string('title'); $table->string('slug')->nullable(); - $table->text('summary'); $table->text('body'); - $table->timestamps(); - $table->unique(['news_id', 'locale']); + $table->unique(['locale', 'slug']); $table->foreign('news_id')->references('id')->on('news')->onDelete('cascade'); - }); } From e651e56a45adb03e4272c934819c6dbf752f099f Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Mon, 18 Jan 2016 21:45:58 +0100 Subject: [PATCH 05/10] array validation --- src/Http/Requests/FormRequest.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Http/Requests/FormRequest.php b/src/Http/Requests/FormRequest.php index 25d9c41..71ed902 100644 --- a/src/Http/Requests/FormRequest.php +++ b/src/Http/Requests/FormRequest.php @@ -8,20 +8,11 @@ class FormRequest extends AbstractFormRequest { public function rules() { - $rules = [ - 'date' => 'required|date', - 'image' => 'image|max:2000', + return [ + 'date' => 'required|date', + 'image' => 'image|max:2000', + '*.title' => 'max:255', + '*.slug' => 'alpha_dash|max:255', ]; - foreach (config('translatable.locales') as $locale) { - $rules[$locale.'.slug'] = [ - 'required_with:'.$locale.'.title', - 'required_if:'.$locale.'.status,1', - 'alpha_dash', - 'max:255', - ]; - $rules[$locale.'.title'] = 'max:255'; - } - - return $rules; } } From 255d3495021d086b95f75179d3798fa579df6a49 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Tue, 19 Jan 2016 14:45:25 +0100 Subject: [PATCH 06/10] endsection in place of stop --- src/resources/views/admin/_form.blade.php | 2 +- src/resources/views/public/index.blade.php | 2 +- src/resources/views/public/show.blade.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/resources/views/admin/_form.blade.php b/src/resources/views/admin/_form.blade.php index ef712ed..8021d37 100644 --- a/src/resources/views/admin/_form.blade.php +++ b/src/resources/views/admin/_form.blade.php @@ -1,7 +1,7 @@ @section('js') -@stop +@endsection @include('core::admin._buttons-form') diff --git a/src/resources/views/public/index.blade.php b/src/resources/views/public/index.blade.php index 0e7a410..c37633b 100644 --- a/src/resources/views/public/index.blade.php +++ b/src/resources/views/public/index.blade.php @@ -14,4 +14,4 @@ {!! $models->appends(Request::except('page'))->render() !!} -@stop +@endsection diff --git a/src/resources/views/public/show.blade.php b/src/resources/views/public/show.blade.php index 0c92f38..a6cea2e 100644 --- a/src/resources/views/public/show.blade.php +++ b/src/resources/views/public/show.blade.php @@ -23,4 +23,4 @@ @include('galleries::public._galleries') -@stop +@endsection From 3121a7ef70f69acc3e2a369e02a89b04a6ef6817 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Sun, 7 Feb 2016 16:36:41 +0100 Subject: [PATCH 07/10] atom feed --- composer.json | 1 + src/Http/Controllers/PublicController.php | 44 ++++++++++++++++++++++- src/Providers/ModuleProvider.php | 5 +++ src/Providers/RouteServiceProvider.php | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 51adb1b..2383e34 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ } ], "require": { + "roumen/feed": "~2.10", "typicms/core": "~2.7.0" }, "autoload": { diff --git a/src/Http/Controllers/PublicController.php b/src/Http/Controllers/PublicController.php index 0a34b1c..8c79bc8 100644 --- a/src/Http/Controllers/PublicController.php +++ b/src/Http/Controllers/PublicController.php @@ -4,13 +4,18 @@ use Illuminate\Pagination\LengthAwarePaginator as Paginator; use Illuminate\Support\Facades\Request; +use Roumen\Feed\Feed; +use TypiCMS\Modules\Core\Facades\TypiCMS; use TypiCMS\Modules\Core\Http\Controllers\BasePublicController; use TypiCMS\Modules\News\Repositories\NewsInterface; class PublicController extends BasePublicController { - public function __construct(NewsInterface $news) + private $feed; + + public function __construct(NewsInterface $news, Feed $feed) { + $this->feed = $feed; parent::__construct($news); } @@ -30,6 +35,43 @@ public function index() ->with(compact('models')); } + /** + * Generate Atom feed. + */ + public function feed() + { + $page = TypiCMS::getPageLinkedToModule('news'); + if (!$page) { + return; + } + $feed = $this->feed; + if (config('typicms.cache')) { + $feed->setCache(60, 'typicmsNewsFeed'); + } + if (!$feed->isCached()) { + $models = $this->repository->latest(10, ['translations']); + + $feed->title = $page->title.' – '.TypiCMS::title(); + $feed->description = $page->body; + if (config('typicms.image')) { + $feed->logo = url('uploads/settings/'.config('typicms.image')); + } + $feed->link = url('feed'); + $feed->setDateFormat('datetime'); // 'datetime', 'timestamp' or 'carbon' + $feed->pubdate = $models[0]->created_at; + $feed->lang = config('app.locale'); + $feed->setShortening(true); // true or false + $feed->setTextLimit(100); // maximum length of description text + + foreach ($models as $model) { + $feed->add($model->title, null, url($model->uri()), $model->created_at, $model->summary, $model->body); + } + + } + + return $feed->render('atom'); + } + /** * Show news. * diff --git a/src/Providers/ModuleProvider.php b/src/Providers/ModuleProvider.php index 2b20556..1769ed1 100644 --- a/src/Providers/ModuleProvider.php +++ b/src/Providers/ModuleProvider.php @@ -49,6 +49,11 @@ public function register() { $app = $this->app; + /* + * Register sitemap package + */ + $app->register('Roumen\Feed\FeedServiceProvider'); + /* * Register route service provider */ diff --git a/src/Providers/RouteServiceProvider.php b/src/Providers/RouteServiceProvider.php index f76cd04..650ffae 100644 --- a/src/Providers/RouteServiceProvider.php +++ b/src/Providers/RouteServiceProvider.php @@ -36,6 +36,7 @@ public function map(Router $router) foreach (config('translatable.locales') as $lang) { if ($uri = $page->uri($lang)) { $router->get($uri, $options + ['as' => $lang.'.news', 'uses' => 'PublicController@index']); + $router->get($uri.'/feed', $options + ['as' => $lang.'.news.feed', 'uses' => 'PublicController@feed']); $router->get($uri.'/{slug}', $options + ['as' => $lang.'.news.slug', 'uses' => 'PublicController@show']); } } From 04f5331ebaa589f9db186f0eb0e04da2d343a8ca Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Sun, 7 Feb 2016 10:36:52 -0500 Subject: [PATCH 08/10] Applied fixes from StyleCI --- src/Http/Controllers/PublicController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Http/Controllers/PublicController.php b/src/Http/Controllers/PublicController.php index 8c79bc8..21d51e4 100644 --- a/src/Http/Controllers/PublicController.php +++ b/src/Http/Controllers/PublicController.php @@ -66,7 +66,6 @@ public function feed() foreach ($models as $model) { $feed->add($model->title, null, url($model->uri()), $model->created_at, $model->summary, $model->body); } - } return $feed->render('atom'); From be16ca6472f94d358f1791ab019c9ea3cd7ea6b2 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Sun, 7 Feb 2016 16:43:13 +0100 Subject: [PATCH 09/10] self url --- src/Http/Controllers/PublicController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/Controllers/PublicController.php b/src/Http/Controllers/PublicController.php index 21d51e4..d58471f 100644 --- a/src/Http/Controllers/PublicController.php +++ b/src/Http/Controllers/PublicController.php @@ -56,7 +56,7 @@ public function feed() if (config('typicms.image')) { $feed->logo = url('uploads/settings/'.config('typicms.image')); } - $feed->link = url('feed'); + $feed->link = url()->route(config('app.locale').'.news.feed'); $feed->setDateFormat('datetime'); // 'datetime', 'timestamp' or 'carbon' $feed->pubdate = $models[0]->created_at; $feed->lang = config('app.locale'); From 9f8ae4d952be6246724cf79ecc996b76fe67c515 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Sun, 7 Feb 2016 16:50:16 +0100 Subject: [PATCH 10/10] feed when empty --- src/Http/Controllers/PublicController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/Controllers/PublicController.php b/src/Http/Controllers/PublicController.php index d58471f..42b9681 100644 --- a/src/Http/Controllers/PublicController.php +++ b/src/Http/Controllers/PublicController.php @@ -58,7 +58,7 @@ public function feed() } $feed->link = url()->route(config('app.locale').'.news.feed'); $feed->setDateFormat('datetime'); // 'datetime', 'timestamp' or 'carbon' - $feed->pubdate = $models[0]->created_at; + $feed->pubdate = isset($models[0]) and $models[0]->created_at; $feed->lang = config('app.locale'); $feed->setShortening(true); // true or false $feed->setTextLimit(100); // maximum length of description text