Merge branch 'module_blog' into dev

This commit is contained in:
Michal Kváček
2016-09-20 15:34:44 +02:00
64 changed files with 692 additions and 357 deletions
+6 -2
View File
@@ -40,8 +40,6 @@ class InstallModule extends Command
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
@@ -56,6 +54,9 @@ class InstallModule extends Command
// get config
$config = $this->loadConfig();
if (empty($config))
return;
// check if it is valid
$this->checkMandatoryFields($config);
@@ -78,6 +79,9 @@ class InstallModule extends Command
$basePath = $this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR;
$path = $basePath . 'Config' . DIRECTORY_SEPARATOR . 'config.php';
if (basename($basePath) == 'Database')
return [];
// check if module has Config/config.php file
if (!file_exists($path)) {
$path = $basePath . 'info.php';
+9
View File
@@ -38,6 +38,15 @@ class Translations extends Command
if (!is_dir($defaultLocalesDir)) {
// this is the place for checking for submodules
$modulePath = dirname(dirname($dir));
if (file_exists($modulePath . '/info.php')) {
$modules = File::directories($modulePath);
foreach ($modules as $module) {
$this->call('translate:dir', ['dir' => $module . '/Resources/lang']);
}
}
return;
}
@@ -197,8 +197,6 @@ class TemplateRegistrator
'editable' => 1
];
echo 'ukladam do db '.$templateName."\n";
// save template into database
$newTemplate = Template::create($params);
+10 -4
View File
@@ -32,11 +32,16 @@ class ContentOverview extends Controller
{
$moduleFilterHandler = false;
$perPage = Input::get('perPage') ? Input::get('perPage') : 20;
$pageHeading = 'admin/contents.overview';
// does user want to filter results using module?
if (is_numeric($moduleId)) {
$module = Module::findOrFail($moduleId);
$moduleFilterHandler = $module->handler;
if (is_callable([$module->handler, 'getOverviewTitle'])) {
$pageHeading = call_user_func([$module->handler, 'getOverviewTitle']);
}
}
// get pages for overview
@@ -47,10 +52,11 @@ class ContentOverview extends Controller
$homepage = $this->content->getHomepage();
return view('admin.content.overview', [
'pages' => $pages,
'homepage' => $homepage,
'statuses' => ContentStatuses::getWithTranslations(),
'module' => isset($module) ? $module : null
'pages' => $pages,
'homepage' => $homepage,
'pageHeading' => $pageHeading,
'statuses' => ContentStatuses::getWithTranslations(),
'module' => isset($module) ? $module : null
]);
}
}
@@ -116,7 +116,9 @@ class CreateNewContent extends Controller
}
// upload file - if provided
$page->uploadTitlePhoto($request);
$file = $page->uploadTitlePhoto($request);
$page->title_photo = $file ? $file['filename'] : null;
// save module-specific stuff
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
+7 -4
View File
@@ -118,12 +118,14 @@ class EditContent extends Controller
->with('error', trans('admin/contents.invalidPage'));
}
// upload file - if provided
$file = $page->uploadTitlePhoto($request);
$request->url = Str::slug($request->url);
$request->parentPage = $request->parentPage ? $request->parentPage : null;
$request->titlePhotoFilename = $page->title_photo;
// upload file - if provided
$page->uploadTitlePhoto($request);
$request->titlePhotoFilename = $file ? $file['filename'] : null;
// array of fields in database and fields from request
$fields = [
@@ -142,7 +144,8 @@ class EditContent extends Controller
];
// save new values with history
$data = self::getFields($request, $fields);
$data = self::getFields($request, array_values($fields));
list($revision, $changedColumns) = $page->updateWithHistory($fields, $data);
$changedColumns += call_user_func_array([$page->module_handler, 'edit'], [&$page, $request, $revision]);
@@ -53,6 +53,9 @@ class ContentPage extends Controller
// add one new "view" for page
$page->view();
// decode module settings
$page->module_settings = json_decode($page->module_settings);
// get handler
$handler = new $page->module_handler;
+3 -3
View File
@@ -293,10 +293,10 @@ class Content extends Model
public function uploadTitlePhoto(Request $request)
{
if ($request->hasFile('titlePhoto')) {
$file = $this->file->upload($request->file('titlePhoto'), $request);
$this->title_photo = $file['filename'];
return $this->file->upload($request->file('titlePhoto'), $request);
}
return null;
}
/**
+8
View File
@@ -73,6 +73,14 @@ class GlobalViewDataProvider extends ServiceProvider
return preg_replace($pattern, $code, $view);
});
// shortcut for displaying Gravatar
Blade::extend(function ($view) {
$pattern = $this->createPattern('gravatar');
$code = '<?php echo \App\Helpers\Gravatar::img($2); ?>';
return preg_replace($pattern, $code, $view);
});
// shortcut for assets (placed in /public/assets/<theme>
Blade::extend(function ($view) {
$pattern = $this->createPattern('asset');
+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');
});
@@ -0,0 +1,6 @@
<?php
return [
"allowComments" => "Povolit komentáře?",
"new" => "Napsat",
"overview" => "Všchny č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,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\\": ""
}
}
}
+8 -1
View File
@@ -1,5 +1,12 @@
<?php
return [
'name' => 'ArticleList'
'name' => 'Article list',
'translatedName' => 'articlelist::module.name',
'translatedDescription' => 'articlelist::module.description',
'alias' => 'blog-articlelist',
'handler' => \Modules\Blog\ArticleList\Handlers\ArticleList::class,
'providers' => [\Modules\Blog\ArticleList\Providers\ArticleListServiceProvider::class],
'files' => ['start.php'],
'order' => 0,
];
@@ -1,20 +0,0 @@
<?php namespace Modules\Blog\ArticleList\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class ArticleListDatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// $this->call("OthersTableSeeder");
}
}
@@ -0,0 +1,155 @@
<?php
namespace Modules\Blog\ArticleList\Handlers;
use App\Enumerations\ModulesHandlerToId;
use App\Handlers\Handler;
use App\Http\Controllers\Controller;
use App\Http\Requests\Request;
use App\Models\Content;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Modules\Blog\Article\Handlers\Article;
use Modules\Categories\Entities\Category;
class ArticleList extends Handler
{
public static function registerAdminMenu(User $user)
{
parent::registerAdminMenu($user);
$menu = \Menu::instance('mainMenu');
$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->route('content.new', trans('articlelist::module.name'), ['id' => self::getModuleId()], 100, ['icon' => 'fa fa-fw fa-list-alt']);
}
/**
* Render given module into visitor area.
*
* @param Content $content DB model from table contents
* @param array $parameters parameters used for modifications/custom settings of given model
*
* @return mixed
*/
public function render(Content $content, $parameters)
{
$articles = Content::where('module_handler', Article::class);
// selected category?
// selected articles from archive?
$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);
}
// is given any category?
$categoryUrl = Input::get('category');
if ($categoryUrl && \Module::get('Categories')
->enabled()
) {
$category = Category::where('url', $categoryUrl)
->first();
$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);
}
// 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]);
}
// show articles only from specified user
$author = Input::get('author');
if ($author) {
$user = User::findOrFail($author);
$articles = $articles->where('user_id', $user->id);
}
$articles = $articles->orderBy('created_at', 'DESC')
->paginate(20);
return Controller::VisitorsView($content->template, ['page' => $content, 'articles' => $articles]);
}
public static function getModuleId()
{
$handler = config('articlelist.handler');
$allModules = ModulesHandlerToId::getWithTranslations();
$moduleId = isset($allModules[$handler]) ? $allModules[$handler] : null;
return $moduleId;
}
public static function supportCategories()
{
return false;
}
/**
* Save module-specific values into database
*
* @param Content $content
* @param Request $request
*
* @return mixed
* @internal param Widget $widget
*/
public static function createNew(Content &$content, Request $request)
{
}
/**
* Method used for editing existing content page.
*
* Reason why it is separated from createNew() method is simple - we need to save history of changes.
*
* @param Content $content
* @param Request $request
*
* @param $revisionID string ID of revision used
*
* @return int number of edited fields
*/
public static function edit(Content &$content, Request $request, $revisionID)
{
}
/**
* Install module
*
* @return mixed
*/
public static function install()
{
}
}
@@ -1,6 +1,9 @@
<?php namespace Modules\Blog\ArticleList\Providers;
use App\Handlers\Registrators\TemplateRegistrator;
use Illuminate\Support\ServiceProvider;
use InvalidArgumentException;
use Modules\Blog\ArticleList\Handlers\ArticleList;
class ArticleListServiceProvider extends ServiceProvider {
@@ -30,7 +33,6 @@ class ArticleListServiceProvider extends ServiceProvider {
*/
public function register()
{
//
}
/**
@@ -40,12 +42,8 @@ class ArticleListServiceProvider extends ServiceProvider {
*/
protected function registerConfig()
{
$this->publishes([
__DIR__.'/../Config/config.php' => config_path('articlelist.php'),
]);
$this->mergeConfigFrom(
__DIR__.'/../Config/config.php', 'articlelist'
);
$this->publishes([__DIR__.'/../Config/config.php' => config_path('articlelist.php')]);
$this->mergeConfigFrom(__DIR__.'/../Config/config.php', 'articlelist');
}
/**
@@ -56,16 +54,30 @@ class ArticleListServiceProvider extends ServiceProvider {
public function registerViews()
{
$viewPath = base_path('resources/views/modules/articlelist');
$sourcePath = __DIR__.'/../Resources/views';
$this->publishes([
$sourcePath => $viewPath
]);
$this->publishes([$sourcePath => $viewPath]);
$this->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/articlelist';
}, \Config::get('view.paths')), [$sourcePath]), 'articlelist');
/**
* @var $registrator TemplateRegistrator
*/
try {
// setup some global variables
$registrator = $this->app->make('registerTemplateDir');
$registrator->setBaseDirectory('resources/views/modules/articlelist/visitor');
$registrator->setNamespace('articlelist');
$registrator->setModuleId(ArticleList::getModuleId());
// register path with current template name
$registrator->register(config('app.theme'), 'articlelist::module.templatePath');
} catch (InvalidArgumentException $e) {
// ignore this exception
}
}
/**
@@ -0,0 +1,5 @@
<?php
return [
"description" => "Modul pro zobrazování seznamu článků na webu.",
"name" => "Seznam článků",
];
@@ -0,0 +1,5 @@
<?php
return [
'name' => 'Article list',
'description' => 'Module for displaying list of articles on web',
];
@@ -1,11 +0,0 @@
@extends('articlelist::layouts.master')
@section('content')
<h1>Hello World</h1>
<p>
This view is loaded from module: {!! config('articlelist.name') !!}
</p>
@stop
@@ -1,12 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Module ArticleList</title>
</head>
<body>
@yield('content')
</body>
</html>
-12
View File
@@ -1,12 +0,0 @@
<?php
return [
'name' => 'Comments',
'translatedName' => 'comments::module.name',
'translatedDescription' => 'comments::module.description',
'alias' => 'blog-comments',
'handler' => \Modules\Blog\Comments\Handlers\Comments::class,
'providers' => [\Modules\Blog\Comments\Providers\CommentsServiceProvider::class],
'files' => ['start.php'],
'order' => 0,
];
@@ -1,37 +0,0 @@
<?php
namespace Modules\Blog\Comments\Handlers;
use App\Enumerations\ModulesHandlerToId;
use App\Handlers\BaseHandler;
use App\Models\User;
class Comments extends BaseHandler
{
public static function getModuleId()
{
$handler = config('comments.handler');
$allModules = ModulesHandlerToId::getWithTranslations();
$moduleId = isset($allModules[$handler]) ? $allModules[$handler] : null;
return $moduleId;
}
/**
* Install module
*
* @return mixed
*/
public static function install()
{
// nothing to do
}
public static function registerAdminMenu(User $user)
{
$menu = \Menu::instance('mainMenu');
$menu->dropdown(trans('comments::module.name'), function ($sub) {
$sub->route('comments.overview', trans('comments::module.overview'), [], 10, ['icon' => 'fa fa-fw fa-commenting-o']);
}, 10, ['icon' => 'fa fa-fw fa-comments-o']);
}
}
@@ -1,12 +0,0 @@
<?php namespace Modules\Blog\Comments\Http\Controllers;
use Pingpong\Modules\Routing\Controller;
class CommentsController extends Controller {
public function index()
{
return view('articlelist::index');
}
}
-6
View File
@@ -1,6 +0,0 @@
<?php
Route::group(['middleware' => 'web', 'prefix' => 'comments', 'namespace' => 'Modules\Blog\Comments\Http\Controllers'], function()
{
Route::get('/', 'CommentsController@index')->name('comments.overview');
});
@@ -1,89 +0,0 @@
<?php namespace Modules\Blog\Comments\Providers;
use Illuminate\Support\ServiceProvider;
class CommentsServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
}
/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([__DIR__.'/../Config/config.php' => config_path('comments.php')]);
$this->mergeConfigFrom(__DIR__.'/../Config/config.php', 'comments');
}
/**
* Register views.
*
* @return void
*/
public function registerViews()
{
$viewPath = base_path('resources/views/modules/comments');
$sourcePath = __DIR__.'/../Resources/views';
$this->publishes([$sourcePath => $viewPath]);
$this->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/comments';
}, \Config::get('view.paths')), [$sourcePath]), 'comments');
}
/**
* Register translations.
*
* @return void
*/
public function registerTranslations()
{
$langPath = base_path('resources/lang/modules/comments');
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, 'comments');
} else {
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'comments');
}
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}
}
@@ -1,6 +0,0 @@
<?php
return [
'name' => 'Comments',
'description' => "Bring comment support to blog module",
'overview' => 'All comments'
];
-15
View File
@@ -1,15 +0,0 @@
<?php
/*
|--------------------------------------------------------------------------
| Register Namespaces And Routes
|--------------------------------------------------------------------------
|
| When a module starting, this file will executed automatically. This helps
| to register some namespaces like translator or view. Also this file
| will load the routes file for each module. You may also modify
| this file as you want.
|
*/
require __DIR__ . '/Http/routes.php';
@@ -0,0 +1,51 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateComments extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->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');
}
}
+4 -3
View File
@@ -1,6 +1,7 @@
<?php
return [
'name' => 'Blog',
'description' => '',
'hasSubmodules' => true,
'name' => 'Blog',
'translatedName' => 'article::module.blog',
'description' => 'article.module.blogDescription',
'hasSubmodules' => true,
];
+6 -3
View File
@@ -14191,7 +14191,6 @@ img {
.timeline > li {
position: relative;
}
.timeline > li:before,
@@ -14204,7 +14203,6 @@ img {
clear: both;
}
.timeline > li > .timeline-panel {
width: 46%;
float: left;
@@ -14250,7 +14248,7 @@ img {
top: 26px;
left: 50%;
margin-left: -14px;
background-color: #ddd;
background-color: #DDD;
z-index: 100;
border-radius: 50%;
}
@@ -14349,6 +14347,7 @@ img {
.ace-editor-container {
position: relative;
}
.ace-editor {
position: absolute !important;
width: 100%;
@@ -14365,6 +14364,10 @@ img {
padding: .5em;
}
.header-block img {
margin-right: 10px;
}
.truncate {
width: 90%;
white-space: nowrap;
+1
View File
@@ -3,6 +3,7 @@ return [
'overview' => 'List of all files',
'upload' => 'Upload new file',
'edit' => 'Edit file :name',
'delete' => 'Delete',
'fileInfo' => 'Information',
'createdAt' => 'Uploaded',
'updatedAt' => 'Last change',
@@ -1,6 +1,6 @@
@extends('admin.layoutWithNavigation')
@section('pageHeading', @trans('admin/contents.overview'))
@section('pageHeading', @trans(isset($pageHeading) ? $pageHeading : 'admin/contents.overview'))
@section('headerButtons')
@if($module)
@@ -2,8 +2,8 @@
@section('pageHeading', @trans('admin/fileManager.edit', ['name' => $file->original_filename]))
@section('headerButtons')
<a href="{{route('upload.delete', ['id' => $file->id])}}" class="btn btn-danger btn-sm rounded" title="@lang('admin/fileManager.delete')">
<i class="fa fa-remove"></i>
<a href="{{route('upload.delete', ['id' => $file->id])}}" class="btn btn-danger btn-sm confirm rounded" title="@lang('admin/fileManager.delete')">
<i class="fa fa-trash"></i>
</a>
@endsection
@@ -9,12 +9,12 @@
<a href="{{route('upload.detail', ['id' => $file->id])}}">
{{str_limit($file->original_filename, 10)}}
</a>
</a>```
@if(!isset($hideDelete) || !$hideDelete)
<a href="{{route('upload.delete', ['id' => $file->id])}}" class="btn btn-sm btn-danger"
<a href="{{route('upload.delete', ['id' => $file->id])}}" class="btn btn-sm btn-danger confirm"
title="@lang('admin/fileManager.delete')">
<i class="fa fa-remove"></i>
<i class="fa fa-trash"></i>
</a>
@endif
</div>
@@ -38,7 +38,7 @@
@if (in_array($widget->id, $associatedWidgetIds))
<a href="{{route('widgets.deleteAssociation', ['widgetId' => $widget->id, 'widgetArea' => $widgetArea->id])}}"
class="button column confirm large-6 alert">
<i class="fa fa-remove"></i>
<i class="fa fa-trash"></i>
</a>
@else
<a href="{{route('widgets.makeAssociation', ['widgetId' => $widget->id, 'widgetArea' => $widgetArea->id])}}"
@@ -6,4 +6,16 @@
<hr>
{!! $page->content !!}
<form action="{{route('comments.new', ['id' => $page->id])}}" method="post">
{!! csrf_field() !!}
<input type="text" name="name">
<input type="email" name="email">
<textarea name="message" id="" cols="30" rows="10">
</textarea>
<input type="submit">
</form>
@endsection
@@ -0,0 +1 @@
{{dd($page)}}