Skip to content

Commit

Permalink
Merge pull request #2076 from LuckyCyborg/4.0
Browse files Browse the repository at this point in the history
[4.0] Improve the Content module
  • Loading branch information
LuckyCyborg authored May 8, 2018
2 parents 13ec70d + 3366f8a commit 893ee88
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 67 deletions.
2 changes: 1 addition & 1 deletion app/Platform/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Define The Application Version
//--------------------------------------------------------------------------

define('VERSION', '4.0.59');
define('VERSION', '4.0.60');

//--------------------------------------------------------------------------
// Set PHP Error Reporting Options
Expand Down
9 changes: 4 additions & 5 deletions modules/Content/Controllers/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ public function index($name = null)
App::abort(404);
}

// Calculate the View used for rendering this Post instance.
if (is_null($postType = PostType::make($post->type))) {
App::abort(404);
} else if (! $postType->public() && Auth::guest()) {
App::abort(404);
$postType = PostType::make($post->type);

if (! $postType->public() && Auth::guest()) {
App::abort(403);
}

return View::make($postType->view(), compact('post'))
Expand Down
2 changes: 1 addition & 1 deletion modules/Content/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
PostType::register('block', array(
'model' => 'Modules\Content\Models\Block',

'view' => null, // The Blocks are rendered via the Modules\Content\BlockHandler.
'view' => null, // The Blocks are rendered via the Modules\Content\Widgets\BlockHandler.

'labels' => array(
'name' => __d('content', 'Block'),
Expand Down
13 changes: 11 additions & 2 deletions modules/Content/Platform/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct($name, array $config)
$this->model = $model;

// Initialize the properties from config.
$this->view = Arr::get($config, 'view');
$this->view = Arr::get($config, 'view', 'Modules/Content::Content/Post');

$this->label = Arr::get($config, 'label');

Expand Down Expand Up @@ -147,8 +147,17 @@ public function hasArchive()
return $this->hasArchive;
}

public function rewrite()
public function rewrite($key = null)
{
if (! is_null($key)) {
return Arr::get($this->rewrite, $key);
}

return $this->rewrite;
}

public function slug()
{
return Arr::get($this->rewrite, 'slug');
}
}
15 changes: 14 additions & 1 deletion modules/Content/Platform/PostTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,20 @@ public function getTypes()

public function getNames()
{
return array_keys($this->types);
return array_map(function ($type)
{
return $type->name();

}, $this->types);
}

public function getSlugs()
{
return array_map(function ($type)
{
return $type->slug();

}, $this->types);
}

public function getTypeModel($name)
Expand Down
86 changes: 29 additions & 57 deletions modules/Content/Routes/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

// The Content dispatching.
Route::get('content/archive/{year}/{month}', array(
'uses' => 'Content@archive',
'uses' => 'Content@archive',

'where' => array(
'year' => '\d+',
'month' => '\d+',
Expand All @@ -30,19 +31,9 @@

Route::get('content/search', 'Content@search');

Route::get('content/{type}/{slug}', array(
'uses' => 'Content@taxonomy',
'where' => array(
'type' => '(category|tag)',
),
));
Route::get('content/{type}/{slug}', array('uses' => 'Content@taxonomy'))->where('type', '(category|tag)');

Route::get('content/{slug?}', array(
'uses' => 'Content@index',
'where' => array(
'slug' => '(.*)',
),
));
Route::get('content/{slug?}', array('uses' => 'Content@index'))->where('slug', '(.*)');

// Content unlocking for the Password Protected pages and posts.
Route::post('content/{id}', 'Content@unlock')->where('id', '\d+');
Expand All @@ -52,10 +43,8 @@


// The Adminstration Routes.
Route::group(array('prefix' => 'admin', 'namespace' => 'Admin'), function ()
Route::group(array('prefix' => 'admin', 'namespace' => 'Admin', 'where' => array('id' => '\d+')), function ()
{
$types = PostType::getNames();

// The Media CRUD.
Route::get( 'media', array('middleware' => 'auth', 'uses' => 'Attachments@index'));
Route::post('media/update/{field}', array('middleware' => 'auth', 'uses' => 'Attachments@update'));
Expand All @@ -71,8 +60,8 @@
// The Menus CRUD.
Route::get( 'menus', array('middleware' => 'auth', 'uses' => 'Menus@index'));
Route::post('menus', array('middleware' => 'auth', 'uses' => 'Menus@store'));
Route::post('menus/{id}', array('middleware' => 'auth', 'uses' => 'Menus@update'))->where('id', '\d+');
Route::post('menus/{id}/destroy', array('middleware' => 'auth', 'uses' => 'Menus@destroy'))->where('id', '\d+');
Route::post('menus/{id}', array('middleware' => 'auth', 'uses' => 'Menus@update'));
Route::post('menus/{id}/destroy', array('middleware' => 'auth', 'uses' => 'Menus@destroy'));

Route::get( 'menus/{id}', array('middleware' => 'auth', 'uses' => 'Menus@items'));
Route::post('menus/{id}/post', array('middleware' => 'auth', 'uses' => 'Menus@addPost'));
Expand All @@ -84,38 +73,29 @@

// The Comments CRUD.
Route::get( 'comments', array('middleware' => 'auth', 'uses' => 'Comments@index'));
Route::get( 'comments/{id}', array('middleware' => 'auth', 'uses' => 'Comments@load'))->where('id', '\d+');
Route::post('comments/{id}', array('middleware' => 'auth', 'uses' => 'Comments@update'))->where('id', '\d+');
Route::post('comments/{id}/destroy', array('middleware' => 'auth', 'uses' => 'Comments@destroy'))->where('id', '\d+');
Route::get( 'comments/{id}', array('middleware' => 'auth', 'uses' => 'Comments@load'));
Route::post('comments/{id}', array('middleware' => 'auth', 'uses' => 'Comments@update'));
Route::post('comments/{id}/destroy', array('middleware' => 'auth', 'uses' => 'Comments@destroy'));

Route::post('comments/{id}/approve', array('middleware' => 'auth', 'uses' => 'Comments@approve'))->where('id', '\d+');
Route::post('comments/{id}/unapprove', array('middleware' => 'auth', 'uses' => 'Comments@unapprove'))->where('id', '\d+');
Route::post('comments/{id}/approve', array('middleware' => 'auth', 'uses' => 'Comments@approve'));
Route::post('comments/{id}/unapprove', array('middleware' => 'auth', 'uses' => 'Comments@unapprove'));

// The Posts CRUD.
$route = Route::get( 'content/create/{type}', array('middleware' => 'auth', 'uses' => 'Posts@create'));

$route->where('type', '(' .implode('|', $types) .')');
Route::get('content/create/{type}', array('middleware' => 'auth', 'uses' => 'Posts@create'))
->where('type', '(' .implode('|', PostType::getNames()) .')');

//
Route::get( 'content/{id}/edit', array('middleware' => 'auth', 'uses' => 'Posts@edit'));
Route::post('content/{id}', array('middleware' => 'auth', 'uses' => 'Posts@update'))->where('id', '\d+');
Route::post('content/{id}/restore', array('middleware' => 'auth', 'uses' => 'Posts@restore'))->where('id', '\d+');
Route::post('content/{id}/destroy', array('middleware' => 'auth', 'uses' => 'Posts@destroy'))->where('id', '\d+');
Route::get( 'content/{id}/edit', array('middleware' => 'auth', 'uses' => 'Posts@edit'));
Route::post('content/{id}', array('middleware' => 'auth', 'uses' => 'Posts@update'));
Route::post('content/{id}/restore', array('middleware' => 'auth', 'uses' => 'Posts@restore'));
Route::post('content/{id}/destroy', array('middleware' => 'auth', 'uses' => 'Posts@destroy'));

Route::get('content/{id}/revisions', array('middleware' => 'auth', 'uses' => 'Posts@revisions'))->where('id', '\d+');
Route::get('content/{id}/revisions', array('middleware' => 'auth', 'uses' => 'Posts@revisions'));

Route::post('content/{id}/tags', array('middleware' => 'auth', 'uses' => 'Posts@addTags'))->where('id', '\d+');
Route::post('content/{id}/tags', array('middleware' => 'auth', 'uses' => 'Posts@addTags'));

Route::post('content/{postId}/tags/{tagId}/detach', array(
'middleware' => 'auth',
'uses' => 'Posts@detachTag',

// The route patterns.
'where' => array(
'id' => '\d+',
'tagId' => '\d+',
),
));
Route::post('content/{id}/tags/{tagId}/detach', array('middleware' => 'auth', 'uses' => 'Posts@detachTag'))
->where('tagId', '\d+');

// The Taxonomies listings.
Route::get('content/categories', array('middleware' => 'auth', 'uses' => 'Taxonomies@index'));
Expand All @@ -125,23 +105,15 @@
->where('type', '(category|tag)');

// The Posts listing.
$route = Route::get('content/{type?}', array('middleware' => 'auth', 'uses' => 'Posts@index'));

$route->where('type', '(' .implode('|', array_map(array('Nova\Support\Str', 'plural'), $types)) .')');
Route::get('content/{slug?}', array('middleware' => 'auth', 'uses' => 'Posts@index'))
->where('type', '(' .implode('|', PostType::getSlugs()) .')');

// The Taxonomies CRUD.
Route::post('taxonomies', array('middleware' => 'auth', 'uses' => 'Taxonomies@store'));
Route::post('taxonomies/{id}', array('middleware' => 'auth', 'uses' => 'Taxonomies@update'))->where('id', '\d+');
Route::post('taxonomies/{id}/destroy', array('middleware' => 'auth', 'uses' => 'Taxonomies@destroy'))->where('id', '\d+');
Route::post('taxonomies', array('middleware' => 'auth', 'uses' => 'Taxonomies@store'));
Route::post('taxonomies/{id}', array('middleware' => 'auth', 'uses' => 'Taxonomies@update'));
Route::post('taxonomies/{id}/destroy', array('middleware' => 'auth', 'uses' => 'Taxonomies@destroy'));

// For AJAX.
Route::get('taxonomies/{id}/{parent}', array(
'middleware' => 'auth',
'uses' => 'Taxonomies@categories',

'where' => array(
'id' => '\d+',
'parent' => '\d+',
),
));
Route::get('taxonomies/{id}/{parent}', array('middleware' => 'auth', 'uses' => 'Taxonomies@categories'))
->where('parent', '\d+');
});

0 comments on commit 893ee88

Please sign in to comment.