Skip to content

Commit

Permalink
[FEATURE] Kickstart CMS which can create pages
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexvaar committed Nov 7, 2023
1 parent 348ac1a commit 32e32ef
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .idea/bluedist.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/symfony2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"vertexvaar/blueweb": "@dev",
"vertexvaar/bluelog": "@dev",
"symfony/http-client": "*",
"vertexvaar/blueconfig": "@dev"
"vertexvaar/blueconfig": "@dev",
"vertexvaar/bluecms": "@dev"
},
"autoload": {
"psr-4": {
Expand Down
30 changes: 30 additions & 0 deletions packages/bluecms/composer.json
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"
}
}
}
40 changes: 40 additions & 0 deletions packages/bluecms/src/Controller/Backend.php
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');
}
}
24 changes: 24 additions & 0 deletions packages/bluecms/src/Controller/Frontend.php
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]);
}
}
20 changes: 20 additions & 0 deletions packages/bluecms/src/Entity/Page.php
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);
}
}
7 changes: 7 additions & 0 deletions packages/bluecms/svc/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
_defaults:
autowire: true
autoconfigure: true

VerteXVaaR\BlueCms\:
resource: '../src/*'
32 changes: 32 additions & 0 deletions packages/bluecms/view/backend/index.html.twig
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 %}
17 changes: 17 additions & 0 deletions packages/bluecms/view/backend/page/new.html.twig
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 %}
13 changes: 13 additions & 0 deletions packages/bluecms/view/frontend/show.html.twig
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 %}
21 changes: 21 additions & 0 deletions packages/bluecms/view/layout.html.twig
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>

0 comments on commit 32e32ef

Please sign in to comment.