-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Kickstart CMS which can create pages
- Loading branch information
1 parent
348ac1a
commit 32e32ef
Showing
12 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "vertexvaar/bluecms", | ||
"description": "CMS component for bluesprints", | ||
"type": "library", | ||
"license": "GPL-3.0+", | ||
"authors": [ | ||
{ | ||
"name": "Oliver Eglseder", | ||
"email": "[email protected]", | ||
"homepage": "http://vxvr.de/", | ||
"role": "Developer" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"VerteXVaaR\\BlueCms\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": "8.2.*", | ||
"vertexvaar/blueweb": "*", | ||
"vertexvaar/blueauth": "*" | ||
}, | ||
"extra": { | ||
"vertexvaar/bluesprints": { | ||
"services": "svc", | ||
"view": "view" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueCms\Controller; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use VerteXVaaR\BlueAuth\Routing\Attributes\AuthorizedRoute; | ||
use VerteXVaaR\BlueCms\Entity\Page; | ||
use VerteXVaaR\BlueWeb\Controller\AbstractController; | ||
use VerteXVaaR\BlueWeb\Routing\Attributes\Route; | ||
|
||
use function base64_encode; | ||
|
||
class Backend extends AbstractController | ||
{ | ||
#[AuthorizedRoute(path: '/backend', requiredRoles: ['editor'])] | ||
public function index(): ResponseInterface | ||
{ | ||
$pages = $this->repository->findAll(Page::class); | ||
return $this->render('@vertexvaar_bluecms/backend/index.html.twig', ['pages' => $pages]); | ||
} | ||
|
||
#[AuthorizedRoute(path: '/backend/page/new', requiredRoles: ['editor'])] | ||
public function pageNew(): ResponseInterface | ||
{ | ||
return $this->render('@vertexvaar_bluecms/backend/page/new.html.twig'); | ||
} | ||
|
||
#[AuthorizedRoute(path: '/backend/page/save', requiredRoles: ['editor'], method: Route::POST)] | ||
public function pageSave(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$body = $request->getParsedBody(); | ||
$page = new Page(base64_encode($body['slug'])); | ||
$page->title = $body['title']; | ||
$this->repository->persist($page); | ||
return $this->redirect('/backend'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueCms\Controller; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use VerteXVaaR\BlueCms\Entity\Page; | ||
use VerteXVaaR\BlueWeb\Controller\AbstractController; | ||
use VerteXVaaR\BlueWeb\Routing\Attributes\Route; | ||
|
||
use function base64_encode; | ||
|
||
class Frontend extends AbstractController | ||
{ | ||
#[Route(path: '/cms{page:/.*?}', priority: -50)] | ||
public function show(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$pageIdentifier = $request->getAttribute('route')->matches['page']; | ||
$page = $this->repository->findByIdentifier(Page::class, base64_encode($pageIdentifier)); | ||
return $this->render('@vertexvaar_bluecms/frontend/show.html.twig', ['page' => $page]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueCms\Entity; | ||
|
||
use VerteXVaaR\BlueSprints\Mvcr\Model\Entity; | ||
|
||
use function base64_decode; | ||
|
||
class Page extends Entity | ||
{ | ||
public string $title = ''; | ||
public array $contents = []; | ||
|
||
public function getSlug(): string | ||
{ | ||
return base64_decode($this->identifier); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
|
||
VerteXVaaR\BlueCms\: | ||
resource: '../src/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{% extends "@vertexvaar_bluecms/layout.html.twig" %} | ||
|
||
{% block content %} | ||
<h1>Backend</h1> | ||
|
||
<a href="/backend/page/new">New page</a> | ||
|
||
<p> | ||
Pages | ||
</p> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Title</th> | ||
<th>Slug</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for page in pages %} | ||
<tr> | ||
<td>{{ page.title }}</td> | ||
<td>{{ page.slug }}</td> | ||
<td> | ||
<a href="/backend/page/edit/{{ page.identifier }}">Edit</a> | ||
<a href="/cms{{ page.slug }}">Show</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "@vertexvaar_bluecms/layout.html.twig" %} | ||
|
||
{% block content %} | ||
<h1>New Page</h1> | ||
|
||
<form action="/backend/page/save" method="post"> | ||
<label> | ||
Title | ||
<input type="text" name="title"> | ||
</label> | ||
<label> | ||
Slug | ||
<input type="text" name="slug"> | ||
</label> | ||
<button type="submit">Create</button> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends "@vertexvaar_bluecms/layout.html.twig" %} | ||
|
||
{% block head %} | ||
<title>{{ page.title }}</title> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1>Frontend</h1> | ||
|
||
<p> | ||
Showing page {{ page.title }} | ||
</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!doctype html> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
{% block head %} | ||
<title>{{ pageTitle }}</title> | ||
{% endblock %} | ||
{% block stylesheets %} | ||
<link rel="stylesheet" href="/css/darcula.min.css" /> | ||
{% endblock %} | ||
</head> | ||
|
||
<body> | ||
{% block content %}No content in here{% endblock %} | ||
{% block javascripts %} | ||
<script type="text/javascript" src="/js/highlight.min.js"></script> | ||
<script>hljs.highlightAll();</script> | ||
{% endblock %} | ||
</body> | ||
</html> |