FEATURE: move blog module into own repository
This commit is contained in:
Executable
+12
@@ -0,0 +1,12 @@
|
||||
<?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,
|
||||
];
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
<?php namespace Modules\Blog\ArticleList\Http\Controllers;
|
||||
|
||||
use Pingpong\Modules\Routing\Controller;
|
||||
|
||||
class ArticleListController extends Controller {
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('articlelist::index');
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
"description" => "Modul pro zobrazování seznamu článků na webu.",
|
||||
"name" => "Seznam článků",
|
||||
"templatePath" => "Seznam článků",
|
||||
];
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'name' => 'Article list',
|
||||
'description' => 'Module for displaying list of articles on web',
|
||||
'templatePath' => 'Article list',
|
||||
];
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
"description" => "Modul pre zobrazenie zoznamu článkov na webe",
|
||||
"name" => "Zoznam článkov",
|
||||
];
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
{"name":"Blog\/ArticleList","description":"articlelist::module.description","alias":"articlelist","providers":["Modules\\Blog\\ArticleList\\Providers\\ArticleListServiceProvider"],"aliases":[],"order":0,"files":["start.php"],"active":1}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?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';
|
||||
Reference in New Issue
Block a user