1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-28 23:40:41 +02:00

Site Plugin: fixes and refactoring #117

This commit is contained in:
Awilum
2019-06-07 22:58:38 +03:00
parent 610a8ea9a9
commit 2cd65d0f20

View File

@@ -3,23 +3,33 @@
namespace Flextype;
use Flextype\Component\Arr\Arr;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class SiteController extends Controller
{
public function index($request, $response, $args) {
/**
* Index page
*
* @param Request $request PSR7 request
* @param Response $response PSR7 response
* @param array $args Args
* @return Response
*/
public function index(Request $request, Response $response, array $args) {
// Get uri
$uri = $args['uri'];
// If uri is empty then it is main page else use entry uri
if ($uri === '/') {
$entry_uri = $this->container->get('registry')->get('settings.entries.main');
$entry_uri = $this->registry->get('settings.entries.main');
} else {
$entry_uri = ltrim($uri, '/');
}
// Get entry body
$entry_body = $this->container->get('entries')->fetch($entry_uri);
$entry_body = $this->entries->fetch($entry_uri);
// is entry not found
$is_entry_not_found = false;
@@ -30,10 +40,10 @@ class SiteController extends Controller
// Get 404 page if entry is not published
if (isset($entry_body['visibility']) && ($entry_body['visibility'] === 'draft' || $entry_body['visibility'] === 'hidden')) {
$entry['title'] = $this->container->get('registry')->get('settings.entries.error404.title');
$entry['description'] = $this->container->get('registry')->get('settings.entries.error404.description');
$entry['content'] = $this->container->get('registry')->get('settings.entries.error404.content');
$entry['template'] = $this->container->get('registry')->get('settings.entries.error404.template');
$entry['title'] = $this->registry->get('settings.entries.error404.title');
$entry['description'] = $this->registry->get('settings.entries.error404.description');
$entry['content'] = $this->registry->get('settings.entries.error404.content');
$entry['template'] = $this->registry->get('settings.entries.error404.template');
$is_entry_not_found = true;
@@ -42,15 +52,15 @@ class SiteController extends Controller
}
} else {
$entry['title'] = $this->container->get('registry')->get('settings.entries.error404.title');
$entry['description'] = $this->container->get('registry')->get('settings.entries.error404.description');
$entry['content'] = $this->container->get('registry')->get('settings.entries.error404.content');
$entry['template'] = $this->container->get('registry')->get('settings.entries.error404.template');
$entry['title'] = $this->registry->get('settings.entries.error404.title');
$entry['description'] = $this->registry->get('settings.entries.error404.description');
$entry['content'] = $this->registry->get('settings.entries.error404.content');
$entry['template'] = $this->registry->get('settings.entries.error404.template');
$is_entry_not_found = true;
}
$path = 'themes/' . $this->container->get('registry')->get('settings.theme') . '/' . (empty($entry['template']) ? 'templates/default' : 'templates/' . $entry['template']) . '.html';
$path = 'themes/' . $this->registry->get('settings.theme') . '/' . (empty($entry['template']) ? 'templates/default' : 'templates/' . $entry['template']) . '.html';
if ($is_entry_not_found) {
return $this->view->render($response->withStatus(404), $path, ['entry' => $entry]);