Skip to content

Commit

Permalink
Merge branch 'atom-feed' into 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed Feb 7, 2016
2 parents ea62a30 + aa8a1bf commit d74c1e6
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 48 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
}
],
"require": {
"typicms/core": "~2.6.0"
"roumen/feed": "~2.10",
"typicms/core": "~2.7.0"
},
"autoload": {
"psr-4": {
Expand Down
43 changes: 42 additions & 1 deletion src/Http/Controllers/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -30,6 +35,42 @@ 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()->route(config('app.locale').'.news.feed');
$feed->setDateFormat('datetime'); // 'datetime', 'timestamp' or 'carbon'
$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

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.
*
Expand Down
19 changes: 5 additions & 14 deletions src/Http/Requests/FormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions src/Providers/ModuleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function register()
{
$app = $this->app;

/*
* Register sitemap package
*/
$app->register('Roumen\Feed\FeedServiceProvider');

/*
* Register route service provider
*/
Expand Down
1 change: 1 addition & 0 deletions src/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
Expand Down
11 changes: 1 addition & 10 deletions src/database/migrations/2013_11_07_185433_create_news_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

});
}

Expand Down
25 changes: 6 additions & 19 deletions src/resources/views/admin/_form.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@section('js')
<script src="{{ asset('components/ckeditor/ckeditor.js') }}"></script>
<script src="{{ asset('js/admin/form.js') }}"></script>
@stop
@endsection

@include('core::admin._buttons-form')

Expand Down Expand Up @@ -29,24 +29,11 @@
</div>
</div>


@include('core::admin._tabs-lang-form', ['target' => 'content'])

<div class="tab-content">

@foreach ($locales as $lang)

<div class="tab-pane fade @if($locale == $lang)in active @endif" id="content-{{ $lang }}">
@include('core::form._title-and-slug')
<input type="hidden" name="{{ $lang }}[status]" value="0">
{!! 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') !!}
</div>

@endforeach

</div>
@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') !!}

</div>

Expand Down
4 changes: 3 additions & 1 deletion src/resources/views/admin/_index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<span>@{{ models.length }} @choice('news::global.news', 2)</span>
</h1>

@include('core::admin._tabs-lang-list')
<div class="btn-toolbar">
@include('core::admin._lang-switcher')
</div>

<div class="table-responsive">

Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/public/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

{!! $models->appends(Request::except('page'))->render() !!}

@stop
@endsection
2 changes: 1 addition & 1 deletion src/resources/views/public/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@

@include('galleries::public._galleries')

@stop
@endsection

0 comments on commit d74c1e6

Please sign in to comment.