@@ -1 +1,3 @@ | |||
vendor/ | |||
private/test.db | |||
cache/ |
@@ -1,9 +1,16 @@ | |||
{ | |||
"require": { | |||
"slim/slim": "4.*", | |||
"slim/psr7": "^1.5" | |||
}, | |||
"config": { | |||
"platform-check": false | |||
"require": { | |||
"slim/slim": "4.*", | |||
"slim/psr7": "^1.5", | |||
"twig/twig": "^3.0", | |||
"php-di/php-di": "^6.3" | |||
}, | |||
"config": { | |||
"platform-check": false | |||
}, | |||
"autoload": { | |||
"psr-4": { | |||
"Blog\\": "src/" | |||
} | |||
} | |||
} |
@@ -4,7 +4,7 @@ | |||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | |||
"This file is @generated automatically" | |||
], | |||
"content-hash": "285ddc9ddeefce0b996c355da865d991", | |||
"content-hash": "4630a6452ef26ee67e9fd1d2651d237e", | |||
"packages": [ | |||
{ | |||
"name": "fig/http-message-util", | |||
@@ -113,28 +113,261 @@ | |||
"time": "2018-02-13T20:26:39+00:00" | |||
}, | |||
{ | |||
"name": "psr/container", | |||
"version": "2.0.2", | |||
"name": "opis/closure", | |||
"version": "3.6.2", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/php-fig/container.git", | |||
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" | |||
"url": "https://github.com/opis/closure.git", | |||
"reference": "06e2ebd25f2869e54a306dda991f7db58066f7f6" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", | |||
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", | |||
"url": "https://api.github.com/repos/opis/closure/zipball/06e2ebd25f2869e54a306dda991f7db58066f7f6", | |||
"reference": "06e2ebd25f2869e54a306dda991f7db58066f7f6", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"php": ">=7.4.0" | |||
"php": "^5.4 || ^7.0 || ^8.0" | |||
}, | |||
"require-dev": { | |||
"jeremeamia/superclosure": "^2.0", | |||
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" | |||
}, | |||
"type": "library", | |||
"extra": { | |||
"branch-alias": { | |||
"dev-master": "2.0.x-dev" | |||
"dev-master": "3.6.x-dev" | |||
} | |||
}, | |||
"autoload": { | |||
"psr-4": { | |||
"Opis\\Closure\\": "src/" | |||
}, | |||
"files": [ | |||
"functions.php" | |||
] | |||
}, | |||
"notification-url": "https://packagist.org/downloads/", | |||
"license": [ | |||
"MIT" | |||
], | |||
"authors": [ | |||
{ | |||
"name": "Marius Sarca", | |||
"email": "marius.sarca@gmail.com" | |||
}, | |||
{ | |||
"name": "Sorin Sarca", | |||
"email": "sarca_sorin@hotmail.com" | |||
} | |||
], | |||
"description": "A library that can be used to serialize closures (anonymous functions) and arbitrary objects.", | |||
"homepage": "https://opis.io/closure", | |||
"keywords": [ | |||
"anonymous functions", | |||
"closure", | |||
"function", | |||
"serializable", | |||
"serialization", | |||
"serialize" | |||
], | |||
"support": { | |||
"issues": "https://github.com/opis/closure/issues", | |||
"source": "https://github.com/opis/closure/tree/3.6.2" | |||
}, | |||
"time": "2021-04-09T13:42:10+00:00" | |||
}, | |||
{ | |||
"name": "php-di/invoker", | |||
"version": "2.3.3", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/PHP-DI/Invoker.git", | |||
"reference": "cd6d9f267d1a3474bdddf1be1da079f01b942786" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/cd6d9f267d1a3474bdddf1be1da079f01b942786", | |||
"reference": "cd6d9f267d1a3474bdddf1be1da079f01b942786", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"php": ">=7.3", | |||
"psr/container": "^1.0|^2.0" | |||
}, | |||
"require-dev": { | |||
"athletic/athletic": "~0.1.8", | |||
"mnapoli/hard-mode": "~0.3.0", | |||
"phpunit/phpunit": "^9.0" | |||
}, | |||
"type": "library", | |||
"autoload": { | |||
"psr-4": { | |||
"Invoker\\": "src/" | |||
} | |||
}, | |||
"notification-url": "https://packagist.org/downloads/", | |||
"license": [ | |||
"MIT" | |||
], | |||
"description": "Generic and extensible callable invoker", | |||
"homepage": "https://github.com/PHP-DI/Invoker", | |||
"keywords": [ | |||
"callable", | |||
"dependency", | |||
"dependency-injection", | |||
"injection", | |||
"invoke", | |||
"invoker" | |||
], | |||
"support": { | |||
"issues": "https://github.com/PHP-DI/Invoker/issues", | |||
"source": "https://github.com/PHP-DI/Invoker/tree/2.3.3" | |||
}, | |||
"funding": [ | |||
{ | |||
"url": "https://github.com/mnapoli", | |||
"type": "github" | |||
} | |||
], | |||
"time": "2021-12-13T09:22:56+00:00" | |||
}, | |||
{ | |||
"name": "php-di/php-di", | |||
"version": "6.3.5", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/PHP-DI/PHP-DI.git", | |||
"reference": "b8126d066ce144765300ee0ab040c1ed6c9ef588" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/b8126d066ce144765300ee0ab040c1ed6c9ef588", | |||
"reference": "b8126d066ce144765300ee0ab040c1ed6c9ef588", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"opis/closure": "^3.5.5", | |||
"php": ">=7.2.0", | |||
"php-di/invoker": "^2.0", | |||
"php-di/phpdoc-reader": "^2.0.1", | |||
"psr/container": "^1.0" | |||
}, | |||
"provide": { | |||
"psr/container-implementation": "^1.0" | |||
}, | |||
"require-dev": { | |||
"doctrine/annotations": "~1.2", | |||
"friendsofphp/php-cs-fixer": "^2.4", | |||
"mnapoli/phpunit-easymock": "^1.2", | |||
"ocramius/proxy-manager": "^2.0.2", | |||
"phpstan/phpstan": "^0.12", | |||
"phpunit/phpunit": "^8.5|^9.0" | |||
}, | |||
"suggest": { | |||
"doctrine/annotations": "Install it if you want to use annotations (version ~1.2)", | |||
"ocramius/proxy-manager": "Install it if you want to use lazy injection (version ~2.0)" | |||
}, | |||
"type": "library", | |||
"autoload": { | |||
"psr-4": { | |||
"DI\\": "src/" | |||
}, | |||
"files": [ | |||
"src/functions.php" | |||
] | |||
}, | |||
"notification-url": "https://packagist.org/downloads/", | |||
"license": [ | |||
"MIT" | |||
], | |||
"description": "The dependency injection container for humans", | |||
"homepage": "https://php-di.org/", | |||
"keywords": [ | |||
"PSR-11", | |||
"container", | |||
"container-interop", | |||
"dependency injection", | |||
"di", | |||
"ioc", | |||
"psr11" | |||
], | |||
"support": { | |||
"issues": "https://github.com/PHP-DI/PHP-DI/issues", | |||
"source": "https://github.com/PHP-DI/PHP-DI/tree/6.3.5" | |||
}, | |||
"funding": [ | |||
{ | |||
"url": "https://github.com/mnapoli", | |||
"type": "github" | |||
}, | |||
{ | |||
"url": "https://tidelift.com/funding/github/packagist/php-di/php-di", | |||
"type": "tidelift" | |||
} | |||
], | |||
"time": "2021-09-02T09:49:58+00:00" | |||
}, | |||
{ | |||
"name": "php-di/phpdoc-reader", | |||
"version": "2.2.1", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/PHP-DI/PhpDocReader.git", | |||
"reference": "66daff34cbd2627740ffec9469ffbac9f8c8185c" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/PHP-DI/PhpDocReader/zipball/66daff34cbd2627740ffec9469ffbac9f8c8185c", | |||
"reference": "66daff34cbd2627740ffec9469ffbac9f8c8185c", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"php": ">=7.2.0" | |||
}, | |||
"require-dev": { | |||
"mnapoli/hard-mode": "~0.3.0", | |||
"phpunit/phpunit": "^8.5|^9.0" | |||
}, | |||
"type": "library", | |||
"autoload": { | |||
"psr-4": { | |||
"PhpDocReader\\": "src/PhpDocReader" | |||
} | |||
}, | |||
"notification-url": "https://packagist.org/downloads/", | |||
"license": [ | |||
"MIT" | |||
], | |||
"description": "PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)", | |||
"keywords": [ | |||
"phpdoc", | |||
"reflection" | |||
], | |||
"support": { | |||
"issues": "https://github.com/PHP-DI/PhpDocReader/issues", | |||
"source": "https://github.com/PHP-DI/PhpDocReader/tree/2.2.1" | |||
}, | |||
"time": "2020-10-12T12:39:22+00:00" | |||
}, | |||
{ | |||
"name": "psr/container", | |||
"version": "1.1.2", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/php-fig/container.git", | |||
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", | |||
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"php": ">=7.4.0" | |||
}, | |||
"type": "library", | |||
"autoload": { | |||
"psr-4": { | |||
"Psr\\Container\\": "src/" | |||
@@ -161,9 +394,9 @@ | |||
], | |||
"support": { | |||
"issues": "https://github.com/php-fig/container/issues", | |||
"source": "https://github.com/php-fig/container/tree/2.0.2" | |||
"source": "https://github.com/php-fig/container/tree/1.1.2" | |||
}, | |||
"time": "2021-11-05T16:47:00+00:00" | |||
"time": "2021-11-05T16:50:12+00:00" | |||
}, | |||
{ | |||
"name": "psr/http-factory", | |||
@@ -677,17 +910,182 @@ | |||
"time": "2021-10-05T03:00:00+00:00" | |||
}, | |||
{ | |||
"name": "symfony/polyfill-ctype", | |||
"version": "v1.24.0", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/symfony/polyfill-ctype.git", | |||
"reference": "30885182c981ab175d4d034db0f6f469898070ab" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab", | |||
"reference": "30885182c981ab175d4d034db0f6f469898070ab", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"php": ">=7.1" | |||
}, | |||
"provide": { | |||
"ext-ctype": "*" | |||
}, | |||
"suggest": { | |||
"ext-ctype": "For best performance" | |||
}, | |||
"type": "library", | |||
"extra": { | |||
"branch-alias": { | |||
"dev-main": "1.23-dev" | |||
}, | |||
"thanks": { | |||
"name": "symfony/polyfill", | |||
"url": "https://github.com/symfony/polyfill" | |||
} | |||
}, | |||
"autoload": { | |||
"psr-4": { | |||
"Symfony\\Polyfill\\Ctype\\": "" | |||
}, | |||
"files": [ | |||
"bootstrap.php" | |||
] | |||
}, | |||
"notification-url": "https://packagist.org/downloads/", | |||
"license": [ | |||
"MIT" | |||
], | |||
"authors": [ | |||
{ | |||
"name": "Gert de Pagter", | |||
"email": "BackEndTea@gmail.com" | |||
}, | |||
{ | |||
"name": "Symfony Community", | |||
"homepage": "https://symfony.com/contributors" | |||
} | |||
], | |||
"description": "Symfony polyfill for ctype functions", | |||
"homepage": "https://symfony.com", | |||
"keywords": [ | |||
"compatibility", | |||
"ctype", | |||
"polyfill", | |||
"portable" | |||
], | |||
"support": { | |||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0" | |||
}, | |||
"funding": [ | |||
{ | |||
"url": "https://symfony.com/sponsor", | |||
"type": "custom" | |||
}, | |||
{ | |||
"url": "https://github.com/fabpot", | |||
"type": "github" | |||
}, | |||
{ | |||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony", | |||
"type": "tidelift" | |||
} | |||
], | |||
"time": "2021-10-20T20:35:02+00:00" | |||
}, | |||
{ | |||
"name": "symfony/polyfill-mbstring", | |||
"version": "v1.24.0", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/symfony/polyfill-mbstring.git", | |||
"reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825", | |||
"reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"php": ">=7.1" | |||
}, | |||
"provide": { | |||
"ext-mbstring": "*" | |||
}, | |||
"suggest": { | |||
"ext-mbstring": "For best performance" | |||
}, | |||
"type": "library", | |||
"extra": { | |||
"branch-alias": { | |||
"dev-main": "1.23-dev" | |||
}, | |||
"thanks": { | |||
"name": "symfony/polyfill", | |||
"url": "https://github.com/symfony/polyfill" | |||
} | |||
}, | |||
"autoload": { | |||
"psr-4": { | |||
"Symfony\\Polyfill\\Mbstring\\": "" | |||
}, | |||
"files": [ | |||
"bootstrap.php" | |||
] | |||
}, | |||
"notification-url": "https://packagist.org/downloads/", | |||
"license": [ | |||
"MIT" | |||
], | |||
"authors": [ | |||
{ | |||
"name": "Nicolas Grekas", | |||
"email": "p@tchwork.com" | |||
}, | |||
{ | |||
"name": "Symfony Community", | |||
"homepage": "https://symfony.com/contributors" | |||
} | |||
], | |||
"description": "Symfony polyfill for the Mbstring extension", | |||
"homepage": "https://symfony.com", | |||
"keywords": [ | |||
"compatibility", | |||
"mbstring", | |||
"polyfill", | |||
"portable", | |||
"shim" | |||
], | |||
"support": { | |||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.24.0" | |||
}, | |||
"funding": [ | |||
{ | |||
"url": "https://symfony.com/sponsor", | |||
"type": "custom" | |||
}, | |||
{ | |||
"url": "https://github.com/fabpot", | |||
"type": "github" | |||
}, | |||
{ | |||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony", | |||
"type": "tidelift" | |||
} | |||
], | |||
"time": "2021-11-30T18:21:41+00:00" | |||
}, | |||
{ | |||
"name": "symfony/polyfill-php80", | |||
"version": "v1.23.1", | |||
"version": "v1.24.0", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/symfony/polyfill-php80.git", | |||
"reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" | |||
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", | |||
"reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", | |||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9", | |||
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
@@ -741,7 +1139,7 @@ | |||
"shim" | |||
], | |||
"support": { | |||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1" | |||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.24.0" | |||
}, | |||
"funding": [ | |||
{ | |||
@@ -757,7 +1155,83 @@ | |||
"type": "tidelift" | |||
} | |||
], | |||
"time": "2021-07-28T13:41:28+00:00" | |||
"time": "2021-09-13T13:58:33+00:00" | |||
}, | |||
{ | |||
"name": "twig/twig", | |||
"version": "v3.3.7", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/twigphp/Twig.git", | |||
"reference": "8f168c6ffa3ce76d1786b3cd52275424a3fc675b" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/8f168c6ffa3ce76d1786b3cd52275424a3fc675b", | |||
"reference": "8f168c6ffa3ce76d1786b3cd52275424a3fc675b", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"php": ">=7.2.5", | |||
"symfony/polyfill-ctype": "^1.8", | |||
"symfony/polyfill-mbstring": "^1.3" | |||
}, | |||
"require-dev": { | |||
"psr/container": "^1.0", | |||
"symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" | |||
}, | |||
"type": "library", | |||
"extra": { | |||
"branch-alias": { | |||
"dev-master": "3.3-dev" | |||
} | |||
}, | |||
"autoload": { | |||
"psr-4": { | |||
"Twig\\": "src/" | |||
} | |||
}, | |||
"notification-url": "https://packagist.org/downloads/", | |||
"license": [ | |||
"BSD-3-Clause" | |||
], | |||
"authors": [ | |||
{ | |||
"name": "Fabien Potencier", | |||
"email": "fabien@symfony.com", | |||
"homepage": "http://fabien.potencier.org", | |||
"role": "Lead Developer" | |||
}, | |||
{ | |||
"name": "Twig Team", | |||
"role": "Contributors" | |||
}, | |||
{ | |||
"name": "Armin Ronacher", | |||
"email": "armin.ronacher@active-4.com", | |||
"role": "Project Founder" | |||
} | |||
], | |||
"description": "Twig, the flexible, fast, and secure template language for PHP", | |||
"homepage": "https://twig.symfony.com", | |||
"keywords": [ | |||
"templating" | |||
], | |||
"support": { | |||
"issues": "https://github.com/twigphp/Twig/issues", | |||
"source": "https://github.com/twigphp/Twig/tree/v3.3.7" | |||
}, | |||
"funding": [ | |||
{ | |||
"url": "https://github.com/fabpot", | |||
"type": "github" | |||
}, | |||
{ | |||
"url": "https://tidelift.com/funding/github/packagist/twig/twig", | |||
"type": "tidelift" | |||
} | |||
], | |||
"time": "2022-01-03T21:15:37+00:00" | |||
} | |||
], | |||
"packages-dev": [], | |||
@@ -768,5 +1242,5 @@ | |||
"prefer-lowest": false, | |||
"platform": [], | |||
"platform-dev": [], | |||
"plugin-api-version": "2.1.0" | |||
"plugin-api-version": "2.2.0" | |||
} |
@@ -0,0 +1 @@ | |||
place for private files like dbase |
@@ -1,24 +1,61 @@ | |||
<?php | |||
namespace Blog; | |||
session_start(); | |||
use DI\Container; | |||
use Psr\Http\Message\ResponseInterface as Response; | |||
use Psr\Http\Message\ServerRequestInterface as Request; | |||
use Slim\Factory\AppFactory; | |||
use Blog\DB\User; | |||
use Blog\Model\Blogs; | |||
use Blog\View\Twig; | |||
use Blog\DB\DB; | |||
use Blog\Model\Menu; | |||
use Blog\Model\Blog; | |||
require __DIR__ . '/../vendor/autoload.php'; | |||
$container = new Container(); | |||
AppFactory::setContainer($container); | |||
$app = AppFactory::create(); | |||
function addNavbar($response) | |||
{ | |||
$response->getBody()->write("<html><head></head><body>"); | |||
if (isset($_SESSION['username'])) { | |||
$response->getBody()->write('<div><a href="/">Index</a> | <a href="/blog/create">Create Blog</a> | <a href="/logout">Logout</a></div>'); | |||
} else { | |||
$response->getBody()->write('<div><a href="/">Index</a> | <a href="/login">Login</a></div>'); | |||
$container->set('twig', function () { | |||
$twig = new Twig('../templates'); | |||
return $twig; | |||
}); | |||
$container->set( | |||
'db', | |||
function () { | |||
$db = new DB(); | |||
return $db; | |||
} | |||
return; | |||
); | |||
function addNavbar($twig) | |||
{ | |||
$menu = new Menu('primary'); | |||
$twig->addBlockVariable('navbar', $menu->getLinks()); | |||
} | |||
function addNavbar2($twig) | |||
{ | |||
$menu = new Menu('secondary'); | |||
$twig->addBlockVariable('navbar', $menu->getLinks()); | |||
} | |||
function addFooter($response) | |||
@@ -28,32 +65,79 @@ function addFooter($response) | |||
return; | |||
} | |||
$app->get('/', function (Request $request, Response $response, array $args) { | |||
addNavbar($response); | |||
$blogs = new Blogs(); | |||
$blogs = $blogs->getBlogs(); | |||
$response->getBody()->write('<hr/><h1>Onze blog</h1>'); | |||
$response->getBody()->write('<ul>'); | |||
$response->getBody()->write('<li><a href="/blog/artikel-1">Blogartikel 1</a></li>'); | |||
$response->getBody()->write('<li><a href="/blog/artikel-2">Blogartikel 2</a></li>'); | |||
$response->getBody()->write('<li><a href="/blog/artikel-3">Blogartikel 3</a></li>'); | |||
$response->getBody()->write('<li><a href="/blog/artikel-4">Blogartikel 4</a></li>'); | |||
$response->getBody()->write('</ul>'); | |||
$response->getBody()->write('<hr/>'); | |||
addFooter($response); | |||
$vars = [ | |||
"content" => $blogs | |||
]; | |||
$twig = $this->get('twig'); | |||
addNavbar($twig); | |||
addNavbar2($twig); | |||
$a = $twig->render('index.html.twig', $vars); | |||
$response->getBody()->write($a); | |||
return $response; | |||
}); | |||
$app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response $response, array $args) { | |||
if (isset($_SESSION['username'])) { | |||
if ($request->getMethod() == 'GET') { | |||
addNavbar($response); | |||
if (isset($_SESSION['error'])) { | |||
$response->getBody()->write($_SESSION['error']); | |||
$response->getBody()->write('<hr/>'); | |||
unset($_SESSION['error']); | |||
} | |||
// Opdracht : Toon reeds ingevoerde gegevens in geval van foutmelding | |||
$response->getBody()->write('<form action="/blog/create" method="POST">'); | |||
$response->getBody()->write('<label for="slug">slug:</label>'); | |||
$response->getBody()->write('<input type="text" name="slug"/><br/>'); | |||
$response->getBody()->write('<label for="title">Titel:</label>'); | |||
$response->getBody()->write('<input type="text" name="title"/><br/>'); | |||
$response->getBody()->write('<label for="content">Inhoud:</label>'); | |||
$response->getBody()->write('<textarea type="textarea" name="content"></textarea><br/>'); | |||
$response->getBody()->write('<input type="submit"/>'); | |||
addFooter($response); | |||
} else { | |||
$data = $request->getParsedBody(); | |||
$blog = new Blog(); | |||
$res = $blog->createBlog($data); | |||
if ($res) { | |||
return $response->withHeader('Location', '/')->withStatus(302); | |||
} else { | |||
$err = $blog->lastErrorMsg(); | |||
$_SESSION['error'] = $err; | |||
return $response->withHeader('Location', '/blog/create')->withStatus(302); | |||
} | |||
} | |||
} else { | |||
addNavbar($response); | |||
$response->getBody()->write(('Please login')); | |||
addFooter($response); | |||
} | |||
return $response; | |||
}); | |||
$app->get('/blog/{slug}', function (Request $request, Response $response, array $args) { | |||
$blogs = new Blogs(); | |||
$blogs = $blogs->getBlog($args['slug']); | |||
$vars = [ | |||
"content" => $blogs | |||
]; | |||
addNavbar($response); | |||
$title = $args['slug']; | |||
$response->getBody()->write("<h1>$title</h1>"); | |||
$twig = $this->get('twig'); | |||
addNavbar($twig); | |||
$a = $twig->render('blog.html.twig', $vars); | |||
$response->getBody()->write($a); | |||
addFooter($response); | |||
return $response; | |||
}); | |||
@@ -78,7 +162,11 @@ $app->map(['GET', 'POST'], '/login', function (Request $request, Response $respo | |||
addFooter($response); | |||
} else { | |||
$postdata = $request->getParsedBody(); | |||
if ($postdata['username'] == 'gebruiker' && $postdata['password'] == "abcd") { | |||
$user = new User(); | |||
$logged_in = $user->checkUserPass($postdata['username'], $postdata['password']); | |||
if ($logged_in) { | |||
//if ($postdata['username'] == 'gebruiker' && $postdata['password'] == "abcd") { | |||
$_SESSION["username"] = $postdata['username']; | |||
addNavbar($response); | |||
$response->getBody()->write('Logged in'); | |||
@@ -96,16 +184,5 @@ $app->post('/postcomment', function (Request $request, Response $response, array | |||
return $response; | |||
}); | |||
$app->post('/blog/create', function (Request $request, Response $response, array $args) { | |||
$response->getBody()->write("Blog create"); | |||
$response->getBody()->write('<form action="/blog/{slug}" method="POST">'); | |||
$response->getBody()->write('<label for="title">Title</label>'); | |||
$response->getBody()->write('<input type="text" name="title"/></br>'); | |||
$response->getBody()->write('<label for="article">Content</label>'); | |||
$response->getBody()->write('<input type="text" name="article"/></br>'); | |||
$response->getBody()->write('<input type="submit"/>'); | |||
$response->getBody()->write('</form>'); | |||
return $response; | |||
}); | |||
$app->run(); |
@@ -0,0 +1,36 @@ | |||
<?php | |||
namespace Blog\DB; | |||
use Blog\Model\Blog as BlogModel; | |||
class Blog extends DB | |||
{ | |||
public function createBlog(BlogModel $data) | |||
{ | |||
$this->enableExceptions(false); | |||
$stmt = $this->prepare("INSERT INTO blogs (slug, title, content) VALUES (:slug, :title, :content)"); | |||
$stmt->bindValue(':slug', $data['slug'], SQLITE3_TEXT); | |||
$stmt->bindValue(':title', $data['title'], SQLITE3_TEXT); | |||
$stmt->bindValue(':content', $data['content'], SQLITE3_TEXT); | |||
$res = $stmt->execute(); | |||
return $res; | |||
} | |||
public function getBlog($slug) | |||
{ | |||
$sql = "SELECT * FROM blogs WHERE slug = :slug ;"; | |||
$stmt = $this->prepare($sql); | |||
$stmt->bindValue(':slug', $slug, SQLITE3_TEXT); | |||
$res = $stmt->execute(); | |||
return $res; | |||
} | |||
public function getBlogs() | |||
{ | |||
$sql = "SELECT * FROM blogs"; | |||
$stmt = $this->prepare($sql); | |||
$res = $stmt->execute(); | |||
return $res; | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
<?php | |||
namespace Blog\DB; | |||
use SQLite3; | |||
class DB extends SQLite3 | |||
{ | |||
function __construct() | |||
{ | |||
$this->open('../private/test.db'); | |||
} | |||
} |
@@ -0,0 +1,16 @@ | |||
<?php | |||
namespace Blog\DB; | |||
class Menu extends DB | |||
{ | |||
// Fetch all links for a given menu type | |||
public function getMenu($type) | |||
{ | |||
$sql = "SELECT * FROM menu WHERE type = :type ;"; | |||
$stmt = $this->prepare($sql); | |||
$stmt->bindValue(":type", $type); | |||
$res = $stmt->execute(); | |||
return $res; | |||
} | |||
} |
@@ -0,0 +1,22 @@ | |||
<?php | |||
namespace Blog\DB; | |||
use Blog\DB\DB; | |||
class User extends DB | |||
{ | |||
public function checkUserPass($user, $pass) | |||
{ | |||
// TODO : SQL injection attack! | |||
$sql = "SELECT count(*) as count FROM users WHERE username = '" . $user . "' AND password = '" . $pass . "';"; | |||
$ret = $this->query($sql); | |||
$rows = $ret->fetchArray(SQLITE3_ASSOC); | |||
$rowcount = $rows['count']; | |||
if ($rowcount == 1) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
<?php | |||
namespace Blog\View; | |||
use Twig\Loader\FilesystemLoader; | |||
use Twig\Environment; | |||
class Twig | |||
{ | |||
protected $twig; | |||
protected $variables; | |||
public function __construct($tmpl_folder) | |||
{ | |||
$loader = new FilesystemLoader($tmpl_folder); | |||
$this->twig = new Environment($loader, []); | |||
$this->variables = ['navbar' => [], 'messages' => ['msgs' => []], 'footer' => []]; | |||
} | |||
protected function load($tmpl) | |||
{ | |||
return $this->twig->load($tmpl); | |||
} | |||
public function addMessage($msg) | |||
{ | |||
$current = $this->variables['messages']['msgs']; | |||
$current[] = $msg; | |||
$this->variables['messages']['msgs'] = $current; | |||
} | |||
// add block variables to the global variable bag | |||
public function addBlockVariable($block, $data) | |||
{ | |||
$current = $this->variables[$block]; | |||
$new = array_merge($current, $data); | |||
$this->variables[$block] = $new; | |||
} | |||
public function render($tmpl, $vars) | |||
{ | |||
$template = $this->load($tmpl); | |||
$variables = array_merge($this->variables, $vars); | |||
return $template->render($variables); | |||
} | |||
} |
@@ -0,0 +1,93 @@ | |||
<?php | |||
namespace Blog\Model; | |||
use Blog\DB\Blog as BlogDB; | |||
use Blog\Model\Comment; | |||
class Blog | |||
{ | |||
protected $author; | |||
protected $title; | |||
protected $subtitle; | |||
protected $date; | |||
protected $content; | |||
protected $comments; | |||
protected $id; | |||
protected $slug; | |||
public function setAuthor($value) | |||
{ | |||
$this->author = $value; | |||
} | |||
public function setDate($value) | |||
{ | |||
$this->date = $value; | |||
} | |||
public function getDate() | |||
{ | |||
return $this->date; | |||
} | |||
public function getAuthor() | |||
{ | |||
return $this->author; | |||
} | |||
public function setContent($value) | |||
{ | |||
$this->content = $value; | |||
} | |||
public function setID($value) | |||
{ | |||
$this->id = $value; | |||
} | |||
public function setSlug($value) | |||
{ | |||
$this->slug = $value; | |||
} | |||
public function setTitle($value) | |||
{ | |||
$this->title = $value; | |||
} | |||
public function getContent() | |||
{ | |||
return $this->content; | |||
} | |||
public function getID() | |||
{ | |||
return $this->id; | |||
} | |||
public function getSlug() | |||
{ | |||
return $this->slug; | |||
} | |||
public function getTitle() | |||
{ | |||
return $this->title; | |||
} | |||
public function getComments() | |||
{ | |||
$comments = new Comment(); | |||
$this->comments = $comments->getComments($this->id); | |||
return $this->comments; | |||
} | |||
public function save() | |||
{ | |||
$db = new BlogDB(); | |||
$data = ["slug" => $this->slug, "title" => $this->title, "content" => $this->content]; | |||
//$db->createBlog($data); | |||
$db->createBlog($this); | |||
} | |||
} |
@@ -0,0 +1,49 @@ | |||
<?php | |||
namespace Blog\Model; | |||
use Blog\DB\Blog as BlogDB; | |||
use Blog\Model\Blog; | |||
class Blogs | |||
{ | |||
protected $blogs = []; | |||
public function getBlog($slug) | |||
{ | |||
$db = new BlogDB(); | |||
$res = $db->getBlog($slug); | |||
$result = $res->fetchArray(SQLITE3_ASSOC); | |||
$blog = new Blog(); | |||
$blog->setSlug($result['slug']); | |||
$blog->setID($result['id']); | |||
$blog->setTitle($result['title']); | |||
$blog->setContent($result['content']); | |||
$this->blogs[] = $blog; | |||
return $this; | |||
} | |||
// TODO/ filter system | |||
// $filter is assoc array vb ['id' => 'dbase id', 'category'=>['PHP', 'Slim']] | |||
// of : ['id' => [1,2,3]] | |||
public function getBlogs() | |||
{ | |||
$db = new BlogDB(); | |||
$res = $db->getBlogs(); | |||
while ($result = $res->fetchArray(SQLITE3_ASSOC)) { | |||
$blog = new Blog(); | |||
$blog->setSlug($result['slug']); | |||
$blog->setID($result['id']); | |||
$blog->setTitle($result['title']); | |||
$blog->setContent($result['content']); | |||
$this->blogs[] = $blog; | |||
} | |||
return $this; | |||
} | |||
public function getBlogsList() | |||
{ | |||
return $this->blogs; | |||
} | |||
} |
@@ -0,0 +1,18 @@ | |||
<?php | |||
namespace Blog\Model; | |||
class Comment | |||
{ | |||
protected $user; | |||
protected $date; | |||
protected $blogID; | |||
protected $comment; | |||
public function getComments($blogID) | |||
{ | |||
// vraag de DB om alle comments voro blogID | |||
return []; | |||
} | |||
} |
@@ -0,0 +1,67 @@ | |||
<?php | |||
namespace Blog\Model; | |||
class Link | |||
{ | |||
protected $id; | |||
protected $name; | |||
protected $url; | |||
protected $type; | |||
protected $parent; | |||
public function setID($value) | |||
{ | |||
$this->id = $value; | |||
return; | |||
} | |||
public function getOD() | |||
{ | |||
return $this->id; | |||
} | |||
public function setName($value) | |||
{ | |||
$this->name = $value; | |||
return; | |||
} | |||
public function getName() | |||
{ | |||
return $this->name; | |||
} | |||
public function setUrl($value) | |||
{ | |||
$this->url = $value; | |||
return; | |||
} | |||
public function getUrl() | |||
{ | |||
return $this->url; | |||
} | |||
public function setType($value) | |||
{ | |||
$this->type = $value; | |||
return; | |||
} | |||
public function getType() | |||
{ | |||
return $this->type; | |||
} | |||
public function setParent($value) | |||
{ | |||
$this->parent = $value; | |||
return; | |||
} | |||
public function getParent() | |||
{ | |||
return $this->parent; | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
<?php | |||
namespace Blog\Model; | |||
use \Blog\Model\Link; | |||
use \Blog\DB\Menu as DB_Menu; | |||
class Menu | |||
{ | |||
protected $links = []; | |||
public function __construct($type) | |||
{ | |||
$this->_loadMenu($type); | |||
} | |||
protected function _loadMenu($type) | |||
{ | |||
$db = new DB_Menu(); | |||
$res = $db->getMenu($type); | |||
while ($result = $res->fetchArray(SQLITE3_ASSOC)) { | |||
$link = new Link(); | |||
$link->setID($result['id']); | |||
$link->setName($result['name']); | |||
$link->setUrl($result['url']); | |||
$link->setType($result['type']); | |||
$link->setParent($result['parent']); | |||
$this->links[] = $link; | |||
} | |||
} | |||
public function getLinks() | |||
{ | |||
return $this->links; | |||
} | |||
} |
@@ -0,0 +1,10 @@ | |||
<html> | |||
<body> | |||
<div id="navbar"> | |||
{% block navbar %} {% include "navbar.html.twig" %} {% endblock %} | |||
</div> | |||
<div id="messages">{% include "messages.html.twig" %}</div> | |||
<diV id="main"> {% block main %}{% endblock %} </diV> | |||
<div id="footer">{% block footer %}{% endblock %}</div> | |||
</body> | |||
</html> |
@@ -0,0 +1,13 @@ | |||
{% extends "base.html.twig" %} {% block main %} | |||
<ul> | |||
{% for blog in content.getBlogsList %} | |||
<h1>{{ blog.title }}</h1> | |||
{{ | |||
blog.content | |||
}} | |||
{% endfor %} | |||
</ul> | |||
{% endblock %} |
@@ -0,0 +1,10 @@ | |||
{% extends "base.html.twig" %} {% block main %} | |||
<ul> | |||
{% for blog in content.getBlogsList%} | |||
<li> | |||
<a href="/blog/{{ blog.slug }}">{{ blog.title }}</a> | |||
</li> | |||
{% endfor %} | |||
</ul> | |||
{% endblock %} |
@@ -0,0 +1,5 @@ | |||
<div> | |||
{% for msg in messages.msgs %} | |||
{{ msg.type }} - {{ msg.text }} </br> | |||
{% endfor %} | |||
</div> |
@@ -0,0 +1,9 @@ | |||
<div> | |||
<ul> | |||
{% for url in navbar %} | |||
<li> | |||
<a href="{{ url.url }}">{{ url.name }} </a> | |||
</li> | |||
{% endfor %} | |||
</ul> | |||
</div> |