FEATURE: translations

This commit is contained in:
Peter Hrdlica
2016-09-29 23:04:26 +02:00
235 changed files with 2665 additions and 6171 deletions
+26
View File
@@ -0,0 +1,26 @@
<?php namespace Modules\Blog\Article\Entities;
use App\Models\Content;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $fillable = [
'user_id',
'content_id',
'content',
'email',
'name'
];
public function author()
{
return $this->belongsTo(User::class, 'user_id');
}
public function article()
{
return $this->belongsTo(Content::class, 'content_id');
}
}
+25 -1
View File
@@ -8,6 +8,7 @@ use App\Http\Controllers\Controller;
use App\Http\Requests\Request;
use App\Models\Content;
use App\Models\User;
use Modules\Blog\Article\Entities\Comment;
class Article extends Handler
{
@@ -21,6 +22,14 @@ class Article extends Handler
*/
public function render(Content $content, $parameters)
{
$content->comments = [];
if (isset($content->module_settings->allowComments) && $content->module_settings->allowComments) {
$content->comments = Comment::where('content_id', $content->id)
->where('approved', 1)
->orderBy('created_at')
->get();
}
return Controller::VisitorsView($content->template, ['page' => $content]);
}
@@ -79,6 +88,11 @@ class Article extends Handler
return $changedColumns;
}
public static function getOverviewTitle()
{
return trans('article::module.allArticles');
}
/**
*
* @param User $user
@@ -89,10 +103,20 @@ class Article extends Handler
$menu = \Menu::instance('mainMenu');
$menu->dropdown(trans('article::module.name'), function ($sub) {
$blogSubmenu = $menu->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' => self::getModuleId()], 10, ['icon' => 'fa fa-fw fa-pencil']);
$sub->route('content.overview', trans('article::article.overview'), ['id' => self::getModuleId()], 30, ['icon' => 'fa fa-fw fa-book']);
}, 10, ['icon' => 'fa fa-fw fa-book']);
$blogSubmenu->dropdown(trans('article::module.comments'), function ($sub) {
$sub->route('comments.overview', trans('article::module.commentsOverview'), [], 10, ['icon' => 'fa fa-fw fa-commenting-o']);
}, 20, ['icon' => 'fa fa-fw fa-comments-o']);
}
public static function getModuleId()
@@ -0,0 +1,19 @@
<?php
namespace Modules\Blog\Article\Http\Controllers\Admin;
use Modules\Blog\Article\Entities\Comment;
use Pingpong\Modules\Routing\Controller;
class CommentsOverview extends Controller
{
public function getOverview()
{
$comments = Comment::with('article')
->with('author')
->orderBy('approved')
->orderBy('created_at', 'DESC')
->paginate(20);
return view('article::admin/comments.overview', ['comments' => $comments]);
}
}
@@ -0,0 +1,33 @@
<?php
namespace Modules\Blog\Article\Http\Controllers\Admin;
use Modules\Blog\Article\Entities\Comment;
use Pingpong\Modules\Routing\Controller;
class EditComment extends Controller
{
public function approve($id)
{
$comment = Comment::findOrFail($id);
$comment->approved = 1;
$comment->save();
// Event::fire(ApprovedComment);
return redirect()
->back()
->with('success', trans('article::comments.approved'));
}
public function delete($id)
{
$comment = Comment::findOrFail($id);
$comment->delete();
// Event::fire(DeletedComment);
return redirect()
->back()
->with('success', trans('article::comments.deleted'));
}
}
@@ -0,0 +1,48 @@
<?php
namespace Modules\Blog\Article\Http\Controllers\Visitor;
use App\Models\Content;
use Illuminate\Support\Facades\Auth;
use Modules\Blog\Article\Entities\Comment;
use Modules\Blog\Article\Handlers\Article;
use Pingpong\Modules\Routing\Controller;
class CreateNewComment extends Controller
{
public function postNew(\Modules\Blog\Article\Http\Requests\CreateNewComment $request, $articleId)
{
$article = Content::where('id', $articleId)
->where('module_handler', Article::class)
->firstOrFail();
$article->module_settings = json_decode($article->module_settings);
if (!isset($article->module_settings->allowComments) || !$article->module_settings->allowComments) {
return redirect()
->route('page.content', ['url' => $article->url])
->with('error', trans('article::comments.disabledComments'));
}
$content = $request->message;
$user = Auth::user();
if ($user) {
$name = $user->name;
$email = $user->email;
} else {
$name = $request->name;
$email = $request->email;
}
Comment::create([
'user_id' => $user ? $user->id : null,
'content_id' => $article->id,
'name' => $name,
'email' => $email,
'content' => $content
]);
return redirect()
->route('page.content', ['url' => $article->url])
->with('success', trans('article::comments.saved'));
}
}
@@ -0,0 +1,28 @@
<?php
namespace Modules\Blog\Article\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Support\Facades\Auth;
class CreateNewComment extends Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$user = Auth::user();
$required = ['message' => 'required'];
if (!$user) {
$required['name'] = 'required';
$required['email'] = 'required|email';
}
return $required;
}
}
+18 -15
View File
@@ -1,25 +1,28 @@
<?php
// routes for comments
Route::group([
'middleware' => 'web',
'prefix' => 'article',
'namespace' => 'Modules\Blog\Article\Http\Controllers'
'middleware' => ['web', 'auth', 'adminMenu'],
'prefix' => 'admin/comments',
'namespace' => 'Modules\Blog\Article\Http\Controllers\Admin'
], function () {
Route::get('/', 'CategoriesOverview@getOverview')
->name('article.overview');
Route::get('/new', 'CreateNewCategory@getNew')
->name('article.new');
Route::get('/', 'CommentsOverview@getOverview')
->name('comments.overview');
Route::post('/new', 'CreateNewCategory@postNew')
->name('article.postNew');
Route::get('/delete/{id}', 'EditComment@delete')
->name('comments.delete');
Route::get('/edit/{id}', 'EditCategory@getEdit')
->name('article.edit');
Route::get('/approve/{id}', 'EditComment@approve')
->name('comments.approve');
});
Route::post('/edit/{id}', 'EditCategory@postEdit')
->name('article.postEdit');
Route::group([
'middleware' => ['web'],
'prefix' => 'comments',
'namespace' => 'Modules\Blog\Article\Http\Controllers\Visitor'
], function () {
Route::get('/delete/{id}', 'EditCategory@delete')
->name('article.delete');
Route::post('/new/{id}', 'CreateNewComment@postNew')
->name('comments.new');
});
@@ -62,22 +62,6 @@ class ArticleServiceProvider extends ServiceProvider {
$this->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/article';
}, \Config::get('view.paths')), [$sourcePath]), 'article');
/**
* @var $registrator TemplateRegistrator
*/
try {
// setup some global variables
$registrator = $this->app->make('registerTemplateDir');
$registrator->setBaseDirectory('resources/views/modules/article/visitor');
$registrator->setNamespace('article');
$registrator->setModuleId(Article::getModuleId());
// register path with current template name
$registrator->register(config('app.theme'), 'article::admin/adminMenu.templatePath');
} catch (InvalidArgumentException $e) {
// ignore this exception
}
}
/**
@@ -0,0 +1,6 @@
<?php
return [
"allowComments" => "Povolit komentáře?",
"new" => "Napsat",
"overview" => "Všechny články",
];
@@ -0,0 +1,8 @@
<?php
return [
"approve" => "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",
];
@@ -0,0 +1,9 @@
<?php
return [
"allArticles" => "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.",
"name" => "Články",
];
@@ -0,0 +1,8 @@
<?php
return [
'createdAt' => 'Created at :date',
'commentedArticle' => 'Article',
'approve' => 'Approve comment',
'approved' => 'Comment successfully approved',
'deleted' => 'Comment deleted'
];
@@ -1,5 +1,9 @@
<?php
return [
'name' => 'Article',
'description' => 'Base submodule for blog'
'name' => 'Articles',
'description' => 'Base submodule for blog',
'comments' => 'Comments',
'commentsOverview' => 'All comments',
'allArticles' => 'All articles',
'blog' => 'Blog'
];
@@ -0,0 +1,6 @@
<?php
return [
"allowComments" => "Povoliť komentáre?",
"new" => " Napísať nový",
"overview" => "Všetky články",
];
@@ -0,0 +1,8 @@
<?php
return [
"approve" => "Schváliť komentár",
"approved" => "Komentár úspešne schválený.",
"commentedArticle" => "Článok",
"createdAt" => "Vytvorené: :date",
"deleted" => "Komentár zmazaný.",
];
@@ -0,0 +1,9 @@
<?php
return [
"allArticles" => "Všetky články",
"blog" => "Blog",
"comments" => "Komentáre",
"commentsOverview" => "Všetky komentáre",
"description" => "Základný submodul pre blog",
"name" => "Články",
];
@@ -0,0 +1,68 @@
@extends('admin.layoutWithNavigation')
@section('pageHeading', trans('article::module.comments'))
@section('content')
@if (count($comments))
@foreach($comments as $comment)
<div class="card @if(!$comment->approved) card-warning @else card-default @endif">
<div class="card-header">
<div class="header-block">
<p class="title">
<img src="@gravatar($comment->author->email, 25)" class="img-rounded" alt="">
{{$comment->author->name}} ({{$comment->author->email}})
</p>
</div>
</div>
<div class="card-block">
<p>
{{$comment->content}}
</p>
</div>
<div class="card-footer">
@lang('article::comments.createdAt', ['date' => \App\Helpers\Template::date($comment->created_at)]) |
@lang('article::comments.commentedArticle'): <a href="{{route('page.content', ['url' => $comment->article->url])}}" target="_blank">
{{$comment->article->title}}
</a>
<div class="pull-right">
@if (!$comment->approved)
<a href="{{route('comments.approve', ['id' => $comment->id])}}" class="btn btn-sm btn-success" title="@lang('article::comments.approve')"
data-toggle="tooltip"><i class="fa fa-fw fa-check"></i></a>
@endif
<a href="{{route('comments.delete', ['id' => $comment->id])}}" class="btn btn-sm btn-warning"><i class="fa fa-fw fa-trash"></i></a>
</div>
</div>
</div>
{{--<div class="comment row">--}}
{{--<div class="col-lg-2">--}}
{{--<img class="img-rounded" src="@gravatar($comment->author->email)" alt="">--}}
{{--{{$comment->author->name}}--}}
{{--@date($comment->created_at)--}}
{{--</div>--}}
{{--<div class="col-lg-10">{{$comment->content}}</div>--}}
{{--<div class="col-lg2">--}}
{{--</div>--}}
{{--</div>--}}
@endforeach
@else
<div class="alert alert-info">
@lang('article::comments.noComments')
</div>
@endif
@endsection
@@ -1,89 +1,89 @@
<div class="row">
<div class="columns large-6">
<label>
@lang('admin/contents.field_title')
<div class="col-lg-6">
<input type="text" name="title" required class="form-control slug-source"
placeholder="@lang('admin/contents.field_title')"
value="{{old('title', $page->title)}}" />
<input type="text" name="title" class="slug-source" placeholder="@lang('admin/contents.field_title')"
value="{{old('title', $page->title)}}" />
</label>
@include('admin.snippets.hasError', ['field' => 'title'])
</div>
<div class="columns large-4">
<label>
@lang('admin/contents.field_url')
<div class="col-lg-4">
<input type="text" name="url" class="slug-target" placeholder="@lang('admin/contents.field_url')"
value="{{old('url', $page->url)}}" />
<input type="text" name="url" required class="form-control slug-target"
placeholder="@lang('admin/contents.field_url')"
value="{{old('url', $page->url)}}" />
@if (isset($errors) && $errors->has('url'))
<div class="callout alert">
{{ $errors->first('url') }}
</div>
@endif
</label>
@include('admin.snippets.hasError', ['field' => 'url'])
</div>
<div class="column large-2 text-center">
<div class="col-lg-2 text-center">
<label>
@lang('admin/contents.lockUrl')<br />
<input type="checkbox" value="1" id="lockUrl"
<input class="checkbox" value="1" id="lockUrl"
@if(old('lockUrl') || ($page->id > 0 && \Illuminate\Support\Str::slug($page->title) != $page->url)) checked
@endif name="lockUrl" />
@endif name="lockUrl" type="checkbox">
<span>@lang('admin/contents.lockUrl')</span>
</label>
</div>
</div>
<div class="row">
<div class="columns large-6">
<label>
<select name="status">
@foreach($contentStatuses as $status => $translation)
<option value="{{$status}}" @if(old('status', $page->status) == $status) selected @endif>
{{$translation}}
</option>
@endforeach
</select>
</label>
<div class="col-lg-6">
<select class="form-control" name="status">
@foreach($contentStatuses as $status => $translation)
<option value="{{$status}}" @if(old('status', $page->status) == $status) selected @endif>
{{$translation}}
</option>
@endforeach
</select>
@if (isset($errors) && $errors->has('status'))
<div class="callout alert">
{{ $errors->first('status') }}
</div>
@endif
@include('admin.snippets.hasError', ['field' => 'status'])
</div>
<div class="column large-6">
<div class="col-lg-4">
<select class="form-control" name="parentPage">
<option value="">@lang('admin/contents.noParentPage')</option>
@foreach($rootPages as $rootPage)
<option value="{{$rootPage->id}}"
@if(old('parent_page', $page->parent_id) == $rootPage->id) selected @endif>
{{$rootPage->title}}
</option>
@endforeach
</select>
@include('admin.snippets.hasError', ['field' => 'parentPage'])
</div>
<div class="col-lg-2 text-center">
<label>
@lang('article::article.allowComments')
<input type="checkbox" value="1" @if(old('allowComments', isset($page->module_settings->allowComments) ? $page->module_settings->allowComments : true)) checked @endif name="allowComments" />
<input class="checkbox" value="1"
@if(old('allowComments', isset($page->module_settings->allowComments) ? $page->module_settings->allowComments : true)) checked
@endif name="allowComments" type="checkbox">
<span>@lang('article::article.allowComments')</span>
</label>
</div>
@if($module->support_categories && count($categories))
<div class="column large-12">
<label>
@lang('admin/contents.category')
<select name="category">
<option value=""> ---</option>
@foreach($categories as $category)
<option value="{{$category->id}}"
@if($category->id == old('category', $page->category_id)) selected @endif>
{{str_repeat(' - ', $category->real_depth)}} {{$category->name}}
</option>
@endforeach
</select>
</label>
<div class="col-lg-12">
<select class="form-control" name="category">
<option value="">@lang('admin/contents.noCategory')</option>
@foreach($categories as $category)
<option value="{{$category->id}}"
@if($category->id == old('category', $page->category_id)) selected @endif>
{{str_repeat(' - ', $category->real_depth)}} {{$category->name}}
</option>
@endforeach
</select>
</div>
@endif
</div>
<div class="row">
<div class="columns large-12">
<label>
<textarea name="pageContent" id="pageContent" class="wysiwyg-editor">
{{old('pageContent', $page->content)}}
</textarea>
</label>
<div class="col-lg-12">
<textarea name="pageContent" id="pageContent" class="wysiwyg-editor">
{{old('pageContent', $page->content)}}
</textarea>
</div>
</div>
</div>
-15
View File
@@ -1,15 +0,0 @@
{
"name": "pingpong-modules/article",
"description": "",
"authors": [
{
"name": "Pingpong Labs",
"email": "pingpong.labs@gmail.com"
}
],
"autoload": {
"psr-4": {
"Modules\\Article\\": ""
}
}
}