FEATURE: move module blog into own repository
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'name' => '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,
|
|
||||||
];
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Entities;
|
|
||||||
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
|
|
||||||
class Article extends Content
|
|
||||||
{
|
|
||||||
protected $table = 'contents';
|
|
||||||
|
|
||||||
public function comments()
|
|
||||||
{
|
|
||||||
return $this->hasMany(Comment::class, 'content_id')
|
|
||||||
->where('approved', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?php namespace Modules\Blog\Article\Entities;
|
|
||||||
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Comment extends Model
|
|
||||||
{
|
|
||||||
protected $fillable = [
|
|
||||||
'user_id',
|
|
||||||
'content_id',
|
|
||||||
'content',
|
|
||||||
'email',
|
|
||||||
'name',
|
|
||||||
'approved'
|
|
||||||
];
|
|
||||||
|
|
||||||
public function author()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class, 'user_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function article()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Content::class, 'content_id');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Events;
|
|
||||||
|
|
||||||
use App\Events\Event;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Modules\Blog\Article\Entities\Comment;
|
|
||||||
|
|
||||||
class ApprovedComment extends Event
|
|
||||||
{
|
|
||||||
use SerializesModels;
|
|
||||||
/**
|
|
||||||
* @var Comment
|
|
||||||
*/
|
|
||||||
public $comment;
|
|
||||||
|
|
||||||
public function __construct(Comment $comment)
|
|
||||||
{
|
|
||||||
$this->comment = $comment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Events;
|
|
||||||
|
|
||||||
use App\Events\Event;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Modules\Blog\Article\Entities\Comment;
|
|
||||||
|
|
||||||
class CreatedComment extends Event
|
|
||||||
{
|
|
||||||
use SerializesModels;
|
|
||||||
/**
|
|
||||||
* @var Comment
|
|
||||||
*/
|
|
||||||
public $comment;
|
|
||||||
|
|
||||||
public function __construct(Comment $comment)
|
|
||||||
{
|
|
||||||
$this->comment = $comment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Events;
|
|
||||||
|
|
||||||
use App\Events\Event;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Modules\Blog\Article\Entities\Comment;
|
|
||||||
|
|
||||||
class DeletedComment extends Event
|
|
||||||
{
|
|
||||||
use SerializesModels;
|
|
||||||
/**
|
|
||||||
* @var Comment
|
|
||||||
*/
|
|
||||||
public $comment;
|
|
||||||
|
|
||||||
public function __construct(Comment $comment)
|
|
||||||
{
|
|
||||||
$this->comment = $comment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Handlers;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\AdvancedContentModifier;
|
|
||||||
use App\CMS\Contracts\Content\ContentTitles;
|
|
||||||
use App\CMS\Contracts\Modules\InstallableModule;
|
|
||||||
use App\CMS\Handlers\AdminHandler;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\ActionLog\ActionLogType;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\Module;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Modules\Blog\Article\Entities\Comment;
|
|
||||||
|
|
||||||
class Article extends AdminHandler implements ContentTitles, AdvancedContentModifier, InstallableModule
|
|
||||||
{
|
|
||||||
public static function getExtendedFormInputsCreate()
|
|
||||||
{
|
|
||||||
$sections = parent::getExtendedFormInputsCreate();
|
|
||||||
|
|
||||||
$sections['basicInfo'] = 'article::admin.content.basicInfo';
|
|
||||||
|
|
||||||
return $sections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getExtendedFormInputsEdit()
|
|
||||||
{
|
|
||||||
return self::getExtendedFormInputsCreate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register admin menu
|
|
||||||
*
|
|
||||||
* @param User $user
|
|
||||||
*/
|
|
||||||
public static function registerAdminMenu(User $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->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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Http\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Admin\Controller;
|
|
||||||
use Modules\Blog\Article\Entities\Comment;
|
|
||||||
|
|
||||||
class CommentsOverview extends Controller
|
|
||||||
{
|
|
||||||
public function getOverview()
|
|
||||||
{
|
|
||||||
$comments = Comment::with('article')
|
|
||||||
->with('author')
|
|
||||||
->orderBy('approved')
|
|
||||||
->orderBy('created_at', 'DESC')
|
|
||||||
->paginate(25);
|
|
||||||
|
|
||||||
return view('article::admin/comments.overview', ['comments' => $comments]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Http\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Admin\Controller;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
use Modules\Blog\Article\Entities\Comment;
|
|
||||||
use Modules\Blog\Article\Events\ApprovedComment;
|
|
||||||
use Modules\Blog\Article\Events\DeletedComment;
|
|
||||||
|
|
||||||
class EditComment extends Controller
|
|
||||||
{
|
|
||||||
public function approve($id)
|
|
||||||
{
|
|
||||||
$comment = Comment::findOrFail($id);
|
|
||||||
$comment->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'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\Blog\Article\Http\Controllers\Visitor;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
use Modules\Blog\Article\Entities\Article;
|
|
||||||
use Modules\Blog\Article\Entities\Comment;
|
|
||||||
use Modules\Blog\Article\Events\CreatedComment;
|
|
||||||
use Modules\Blog\Article\Http\Requests\CreateNewComment as CreateNewCommentRequest;
|
|
||||||
|
|
||||||
class CreateNewComment extends Controller
|
|
||||||
{
|
|
||||||
public function store(CreateNewCommentRequest $request, Article $article)
|
|
||||||
{
|
|
||||||
if (!isset($article->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'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
Route::group([
|
|
||||||
'prefix' => 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');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\Blog\Article\Listeners;
|
|
||||||
|
|
||||||
use App\Listeners\Loggers\Logger;
|
|
||||||
use Modules\Blog\Article\Events\ApprovedComment;
|
|
||||||
|
|
||||||
class LogCommentApproval extends Logger
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle the event.
|
|
||||||
*
|
|
||||||
* @param ApprovedComment $event
|
|
||||||
*/
|
|
||||||
public function handle(ApprovedComment $event)
|
|
||||||
{
|
|
||||||
$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 'commentApproved';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\Blog\Article\Listeners;
|
|
||||||
|
|
||||||
use App\Listeners\Loggers\Logger;
|
|
||||||
use Modules\Blog\Article\Events\DeletedComment;
|
|
||||||
|
|
||||||
class LogDeletedComment extends Logger
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle the event.
|
|
||||||
*
|
|
||||||
* @param DeletedComment $event
|
|
||||||
*/
|
|
||||||
public function handle(DeletedComment $event)
|
|
||||||
{
|
|
||||||
$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 'commentDeleted';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\Blog\Article\Listeners;
|
|
||||||
|
|
||||||
use App\Listeners\Loggers\Logger;
|
|
||||||
use Modules\Blog\Article\Events\CreatedComment;
|
|
||||||
|
|
||||||
class LogNewComment extends Logger
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle the event.
|
|
||||||
*
|
|
||||||
* @param CreatedComment $event
|
|
||||||
*/
|
|
||||||
public function handle(CreatedComment $event)
|
|
||||||
{
|
|
||||||
// log only logged-in users
|
|
||||||
if (!$event->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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Modificators;
|
|
||||||
|
|
||||||
class PerexCreator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \DOMDocument
|
|
||||||
*/
|
|
||||||
protected $DOMDocument;
|
|
||||||
protected $perex;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->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), '<p><strong><em><b><i><u>');
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Pipeline\DisplayContent;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Modules\Blog\Article\Entities\Comment;
|
|
||||||
use Modules\Blog\Article\Handlers\Article;
|
|
||||||
|
|
||||||
class LoadCommentsForBlogpost implements Process
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $content
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function handle(Content & $content)
|
|
||||||
{
|
|
||||||
if ($content->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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\Article\Pipeline\SaveContent;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use Modules\Blog\Article\Handlers\Article;
|
|
||||||
|
|
||||||
class TurnCommentsOnOrOff implements Process
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $content
|
|
||||||
* @param array $input
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function handle(Content & $content, array & $input)
|
|
||||||
{
|
|
||||||
if (trim($content->moduleHandler, '\\') !== Article::class) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$settings = $content->moduleSettings;
|
|
||||||
$settings['allowComments'] = isset($input['allowComments']) ? (int)$input['allowComments'] : 0;
|
|
||||||
$content->moduleSettings = $settings;
|
|
||||||
$content->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Modules\Blog\Article\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
|
||||||
use Modules\Blog\Article\Events\ApprovedComment;
|
|
||||||
use Modules\Blog\Article\Events\CreatedComment;
|
|
||||||
use Modules\Blog\Article\Events\DeletedComment;
|
|
||||||
use Modules\Blog\Article\Listeners\LogCommentApproval;
|
|
||||||
use Modules\Blog\Article\Listeners\LogDeletedComment;
|
|
||||||
use Modules\Blog\Article\Listeners\LogNewComment;
|
|
||||||
|
|
||||||
class ArticleEventServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The event listener mappings for the application.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $listen = [
|
|
||||||
ApprovedComment::class => [LogCommentApproval::class],
|
|
||||||
DeletedComment::class => [LogDeletedComment::class],
|
|
||||||
CreatedComment::class => [LogNewComment::class],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php namespace Modules\Blog\Article\Providers;
|
|
||||||
|
|
||||||
use App\CMS\Modules\ServiceProviders\ServiceProvider;
|
|
||||||
use Modules\Blog\Article\Pipeline\DisplayContent\LoadCommentsForBlogpost;
|
|
||||||
use Modules\Blog\Article\Pipeline\SaveContent\TurnCommentsOnOrOff;
|
|
||||||
|
|
||||||
class ArticleServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Boot the application events.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
$this->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__;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
"allowComments" => "Povolit komentáře?",
|
|
||||||
"new" => "Napsat",
|
|
||||||
"overview" => "Všechny články",
|
|
||||||
];
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?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",
|
|
||||||
"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",
|
|
||||||
];
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?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.",
|
|
||||||
"editArticle" => "Upravuji článek",
|
|
||||||
"name" => "Články",
|
|
||||||
"newArticle" => "Napsat nový článek",
|
|
||||||
"templatePath" => "Články",
|
|
||||||
];
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
'allowComments' => 'Allow comments?',
|
|
||||||
'new' => 'Write new',
|
|
||||||
'overview' => 'All articles'
|
|
||||||
];
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
'createdAt' => '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',
|
|
||||||
],
|
|
||||||
]
|
|
||||||
];
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
'name' => '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',
|
|
||||||
];
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
"allowComments" => "Povoliť komentáre?",
|
|
||||||
"new" => " Napísať nový",
|
|
||||||
"overview" => "Všetky články",
|
|
||||||
];
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
"approve" => "Schváliť komentár",
|
|
||||||
"approved" => "Komentár úspešne schválený.",
|
|
||||||
"commentedArticle" => "Článok",
|
|
||||||
"createdAt" => "Vytvorené: :date",
|
|
||||||
"deleted" => "Komentár zmazaný.",
|
|
||||||
];
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<?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",
|
|
||||||
];
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
@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->email, 25)" class="img-rounded" alt="">
|
|
||||||
{{$comment->name}} ({{$comment->email}})
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card-block">
|
|
||||||
<p>
|
|
||||||
{{$comment->content}}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="card-footer">
|
|
||||||
@lang('article::comments.createdAt', ['date' => \App\CMS\Helpers\Date::date($comment->created_at)])
|
|
||||||
|
|
|
||||||
|
|
||||||
@lang('article::comments.commentedArticle'):
|
|
||||||
|
|
||||||
@if(!is_null($comment->article))
|
|
||||||
<a href="{{route('page.content', ['url' => $comment->article->url])}}" target="_blank">
|
|
||||||
{{$comment->article->title}}
|
|
||||||
</a>
|
|
||||||
@else
|
|
||||||
@lang('article::comments.unknownArticle')
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<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 confirm btn-warning"><i class="fa fa-fw fa-trash"></i></a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endforeach
|
|
||||||
@else
|
|
||||||
<div class="alert alert-info">
|
|
||||||
@lang('article::comments.noComments')
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
@endsection
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
<div class="row">
|
|
||||||
<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)}}" />
|
|
||||||
|
|
||||||
@include('admin.snippets.hasError', ['field' => 'title'])
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-4">
|
|
||||||
|
|
||||||
<input type="text" name="url" required class="form-control slug-target"
|
|
||||||
placeholder="@lang('admin/contents.field_url')"
|
|
||||||
value="{{old('url', $page->url)}}" />
|
|
||||||
|
|
||||||
@include('admin.snippets.hasError', ['field' => 'url'])
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-2 text-center">
|
|
||||||
<label>
|
|
||||||
<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" type="checkbox">
|
|
||||||
<span>@lang('admin/contents.lockUrl')</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<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>
|
|
||||||
|
|
||||||
@include('admin.snippets.hasError', ['field' => 'status'])
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-4">
|
|
||||||
<select class="form-control" name="parentId">
|
|
||||||
<option value="">@lang('admin/contents.noParentPage')</option>
|
|
||||||
|
|
||||||
@foreach($rootPages as $rootPage)
|
|
||||||
<option value="{{$rootPage->id}}"
|
|
||||||
@if(old('parentId', $page->parentId) == $rootPage->id) selected @endif>
|
|
||||||
{{$rootPage->title}}
|
|
||||||
</option>
|
|
||||||
@endforeach
|
|
||||||
</select>
|
|
||||||
|
|
||||||
@include('admin.snippets.hasError', ['field' => 'parentPage'])
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-lg-2 text-center">
|
|
||||||
<label>
|
|
||||||
<input class="checkbox" value="1"
|
|
||||||
@if(old('allowComments', isset($page->moduleSettings->allowComments) ? $page->moduleSettings->allowComments : true)) checked
|
|
||||||
@endif name="allowComments" type="checkbox">
|
|
||||||
<span>@lang('article::article.allowComments')</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@if($module->support_categories && count($categories))
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<select class="form-control" name="categoryId">
|
|
||||||
<option value="">@lang('admin/contents.noCategory')</option>
|
|
||||||
@foreach($categories as $category)
|
|
||||||
<option value="{{$category->id}}"
|
|
||||||
@if($category->id == old('categoryId', $page->categoryId)) selected @endif>
|
|
||||||
{{str_repeat(' - ', $category->real_depth)}} {{$category->name}}
|
|
||||||
</option>
|
|
||||||
@endforeach
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<textarea name="pageContent" id="pageContent" class="wysiwyg-editor">
|
|
||||||
{{old('pageContent', $page->pageContent)}}
|
|
||||||
</textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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__ . DIRECTORY_SEPARATOR.'Http'.DIRECTORY_SEPARATOR.'routes.php';
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'name' => '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,
|
|
||||||
];
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\ArticleList\Handlers;
|
|
||||||
|
|
||||||
use App\CMS\Handlers\AdminHandler;
|
|
||||||
use App\Models\User;
|
|
||||||
|
|
||||||
class ArticleList extends AdminHandler
|
|
||||||
{
|
|
||||||
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' => config('articlelist.alias')], 100, ['icon' => 'fa fa-fw fa-list-alt']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function supportCategories()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php namespace Modules\Blog\ArticleList\Http\Controllers;
|
|
||||||
|
|
||||||
use Pingpong\Modules\Routing\Controller;
|
|
||||||
|
|
||||||
class ArticleListController extends Controller {
|
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
return view('articlelist::index');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<?php
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Modules\Blog\ArticleList\Pipeline\DisplayContent;
|
|
||||||
|
|
||||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
|
||||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
|
||||||
use App\Models\Content\Content;
|
|
||||||
use App\Models\User;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Input;
|
|
||||||
use Modules\Blog\Article\Entities\Article as ArticleModel;
|
|
||||||
use Modules\Blog\Article\Handlers\Article;
|
|
||||||
use Modules\Blog\ArticleList\Handlers\ArticleList;
|
|
||||||
|
|
||||||
class LoadArticlesForList implements Process
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Process and modify given page
|
|
||||||
*
|
|
||||||
* @param Content $page
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function handle(Content & $page)
|
|
||||||
{
|
|
||||||
// load articles only for article list
|
|
||||||
if ($page->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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?php namespace Modules\Blog\ArticleList\Providers;
|
|
||||||
|
|
||||||
use App\CMS\Modules\ServiceProviders\ServiceProvider;
|
|
||||||
use Modules\Blog\ArticleList\Pipeline\DisplayContent\LoadArticlesForList;
|
|
||||||
|
|
||||||
class ArticleListServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
protected function setModuleAlias()
|
|
||||||
{
|
|
||||||
$this->alias = 'articlelist';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setModulePath()
|
|
||||||
{
|
|
||||||
$this->path = __DIR__;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
app('displayPipeline')->add(LoadArticlesForList::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
"description" => "Modul pro zobrazování seznamu článků na webu.",
|
|
||||||
"name" => "Seznam článků",
|
|
||||||
"templatePath" => "Seznam článků",
|
|
||||||
];
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
'name' => 'Article list',
|
|
||||||
'description' => 'Module for displaying list of articles on web',
|
|
||||||
'templatePath' => 'Article list',
|
|
||||||
];
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
"description" => "Modul pre zobrazenie zoznamu článkov na webe",
|
|
||||||
"name" => "Zoznam článkov",
|
|
||||||
];
|
|
||||||
@@ -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__ . DIRECTORY_SEPARATOR.'Http'.DIRECTORY_SEPARATOR.'routes.php';
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
<?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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use App\Models\Module;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
|
|
||||||
class UpdateAliasForSubdomodules extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Module::where('alias', 'blog-articlelist')
|
|
||||||
->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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
'name' => 'Blog',
|
|
||||||
'translatedName' => 'article::module.blog',
|
|
||||||
'description' => 'article.module.blogDescription',
|
|
||||||
'hasSubmodules' => true,
|
|
||||||
];
|
|
||||||
Reference in New Issue
Block a user