@ -0,0 +1,4 @@ | |||
APP_DEBUG=false | |||
DIRECTUS_API_URL= | |||
DIRECTUS_API_TOKEN= |
@ -0,0 +1,14 @@ | |||
composer.phar | |||
/vendor/ | |||
/storage/cache/* | |||
!/storage/cache/.gitkeep | |||
/public/* | |||
!/public/.htaccess | |||
!/public/index.php | |||
node_modules | |||
.env | |||
*.log | |||
rysnc_exclude |
@ -0,0 +1,75 @@ | |||
<?php | |||
namespace App\Controllers; | |||
use SuperGear\Directus\Controllers\ControllerAbstract; | |||
use SuperGear\Repositories\Manager; | |||
/** | |||
* controller for page items from directus | |||
* | |||
* | |||
* | |||
* @author Björn Hase | |||
* @license http://opensource.org/licenses/MIT The MIT License | |||
* @link https://gitlab.tentakelfabrik.de/super-gear/directus GitHub Repository | |||
* | |||
*/ | |||
class PageController extends ControllerAbstract | |||
{ | |||
/** slug for home */ | |||
const HOME_SLUG = 'home'; | |||
/** default view */ | |||
protected $defaultView = 'page/default'; | |||
/** | |||
* get home page from slug | |||
* | |||
* | |||
*/ | |||
public function indexAction() | |||
{ | |||
$repository = Manager::get('Page'); | |||
$page = $repository->findOneBySlug(self::HOME_SLUG); | |||
if ($this->notFound($page)) { | |||
$this->app->redirect('404'); | |||
} | |||
$this->render($page); | |||
} | |||
/** | |||
* get single page from slug | |||
* | |||
* | |||
* @param string $slug | |||
*/ | |||
public function getAction($slug) | |||
{ | |||
$repository = Manager::get('Page'); | |||
$page = $repository->findOneBySlug($slug); | |||
if ($this->notFound($page)) { | |||
$this->app->redirect('404'); | |||
} | |||
$this->render($page); | |||
} | |||
/** | |||
* if page not found | |||
* | |||
*/ | |||
public function notFoundAction() | |||
{ | |||
$page = [ | |||
'data' => [ | |||
'view' => 'page/404' | |||
] | |||
]; | |||
$this->render($page); | |||
} | |||
} |
@ -0,0 +1,48 @@ | |||
<?php | |||
namespace App\Repositories; | |||
use SuperGear\Directus\Repositories\RepositoryAbstract; | |||
/** | |||
* request page items from directus | |||
* | |||
* @author Björn Hase | |||
* @license http://opensource.org/licenses/MIT The MIT License | |||
* @link https://gitlab.tentakelfabrik.de/super-gear/directus GitHub Repository | |||
*/ | |||
class PageRepository extends RepositoryAbstract | |||
{ | |||
/** name of the collection */ | |||
protected $name = 'page'; | |||
/** | |||
* find single page with a slug, | |||
* page must be published | |||
* | |||
* @param string $slug | |||
* @return array | |||
*/ | |||
public function findOneBySlug($slug) | |||
{ | |||
return $this->itemCollection->findOne($this->name, [ | |||
'filter[slug][eq]' => $slug, | |||
'filter[status][eq]' => 'published' | |||
]); | |||
} | |||
/** | |||
* find single page with a slug, | |||
* page must be published | |||
* | |||
* @param string $slug | |||
* @return array | |||
*/ | |||
public function findByView($view) | |||
{ | |||
return $this->itemCollection->find($this->name, [ | |||
'filter[view][eq]' => $view, | |||
'filter[status][eq]' => 'published' | |||
]); | |||
} | |||
} |
@ -0,0 +1,31 @@ | |||
<?php | |||
// adding functions | |||
require_once(__DIR__.'/../src/SuperGear/Functions.php'); | |||
// adding env | |||
$env = Dotenv\Dotenv::create(__DIR__.'/../'); | |||
$env->load(); | |||
// display all errors if debug is true | |||
if (getenv('DEBUG') === true) { | |||
error_reporting(E_ALL); | |||
ini_set('display_errors', 1); | |||
} | |||
// create app | |||
$app = Flight::app(); | |||
// setting view path | |||
$app->set('flight.views.path', __DIR__.'/../resources/views'); | |||
// adding blade for templates | |||
Flight::register('view', 'Jenssegers\Blade\Blade', [ $app->get('flight.views.path'), __DIR__.'/../resources/cache']); | |||
Flight::map('render', function($view, $data) { | |||
echo Flight::view()->make($view, $data); | |||
}); | |||
// setting path | |||
$app->set('basePath', __DIR__.'/../'); | |||
$app->set('publicPath', __DIR__.'/../public'); | |||
$app->set('storagePath', __DIR__.'/../storage'); |
@ -0,0 +1,19 @@ | |||
{ | |||
"name": "super-gear/directus-boilerplate", | |||
"version": "1.0.0", | |||
"type": "boilerplate", | |||
"license": "MIT", | |||
"authors": [ | |||
{ "name": "Björn Hase", "email": "me@tentakelfabrik.de" } | |||
], | |||
"require": { | |||
"php": "^7.0", | |||
"vlucas/phpdotenv": "^3.3", | |||
"jenssegers/blade": "^1.2" | |||
}, | |||
"autoload": { | |||
"psr-4": { | |||
"App\\": "app/" | |||
} | |||
} | |||
} |
@ -0,0 +1,11 @@ | |||
<?php | |||
require __DIR__.'/../vendor/autoload.php'; | |||
require __DIR__.'/../app/bootstrap.php'; | |||
// add routes | |||
$app->route('GET /', array(new App\Controllers\PageController, 'indexAction')); | |||
$app->route('GET /@slug', array(new App\Controllers\PageController, 'getAction')); | |||
$app->route('GET /404', array(new App\Controllers\PageController, 'notFoundAction')); | |||
$app->start(); |
@ -0,0 +1,37 @@ | |||
@inject('pageRepository', 'App\Repositories\PagenRepository') | |||
<!doctype html> | |||
<html lang="de-DE" class="no-js"> | |||
<head> | |||
<meta charset="utf-8"> | |||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | |||
<title>Super Gear - Directus Boilerplate | {{ $page['data']['title'] }}</title> | |||
<meta name="viewport" content="width=device-width, initial-scale=1"> | |||
<link href="{{ (isset($_SERVER['HTTPS']) ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] }}" rel="canonical"> | |||
<link href="/css/styles.css" rel="stylesheet" type="text/css"> | |||
</head> | |||
<body> | |||
<header id="header" class="site-header"> | |||
<nav class="group group--horizontal navbar__inner"> | |||
<ul class="group__section"> | |||
@foreach ($homeSection['data'] as $index => $data) | |||
<li class="group__item @if ($index === 0) .current @endif"> | |||
<a href="/#{{ $data['slug'] }}"> | |||
<i class="icon icon-{{ $data['icon'] }}"></i> {{ $data['title'] }} | |||
</a> | |||
</li> | |||
@endforeach | |||
</ul> | |||
</nav> | |||
</header> | |||
@section('content') | |||
@show | |||
@include('partials.footer') | |||
<script src="/js/index.js"></script> | |||
</body> | |||
</html> |
@ -0,0 +1,3 @@ | |||
@extends('layout') | |||
404 |
@ -0,0 +1,16 @@ | |||
@extends('layout') | |||
@inject('markdownHelper', 'SuperGear\Helpers\MarkdownHelper') | |||
@section('content') | |||
<main> | |||
<header class="page__header"> | |||
<h1 class="page__title"> | |||
{{ $page['data']['title'] }} | |||
</h1> | |||
</header> | |||
<div class="content"> | |||
{!! $markdownHelper->text($page['data']['content']) !!} | |||
</div> | |||
</main> | |||
@endsection |
@ -0,0 +1,47 @@ | |||
@inject('pageRepository', 'App\Repositories\PageRepository') | |||
@php | |||
$pages = $pageRepository->findByView('page/page'); | |||
@endphp | |||
<footer id="footer" class="site-footer"> | |||
<div class="site-footer__links"> | |||
<div class="container"> | |||
<div class="grid"> | |||
<div class="col-md-3"> | |||
<div class="group"> | |||
<ul class="group__section"> | |||
@foreach ($pages['data'] as $data) | |||
<li class="group__item"> | |||
<a href="/{{ $data['slug'] }}">{{ $data['title'] }}</a> | |||
</li> | |||
@endforeach | |||
</ul> | |||
</div> | |||
</div> | |||
<div class="col-md-9"> | |||
<div class="group group--social-media"> | |||
<ul class="group__section"> | |||
<li class="group__item"> | |||
<a href="https://twitter.com/WarpCoreCafe" target="_blank"> | |||
<i class="icon icon-twitter"></i> | |||
</a> | |||
</li> | |||
</ul> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
<div class="site-footer__note"> | |||
<div class="container"> | |||
<div class="grid"> | |||
<div class="col-12"> | |||
<p class="text-center"> | |||
Diese Seite wird durch <a href="https://directus.io/" target="_blank">Directus</a> und dem Directus PHP Client der <a href="https://tentakelfabrik.de" target="_blank">Tentakelfabrik</a> angezeigt | |||
</p> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</footer> |