Let there be placeholders
This commit is contained in:
parent
3ba0d60d78
commit
c905f1d7dd
11 changed files with 137 additions and 55 deletions
|
@ -1,17 +1,38 @@
|
|||
<?php
|
||||
class Bootstrap
|
||||
{
|
||||
public function attachUser()
|
||||
{
|
||||
$this->context->loggedIn = false;
|
||||
if (isset($_SESSION['user-id']))
|
||||
{
|
||||
$this->context->user = R::findOne('user', 'id = ?', [$_SESSION['user-id']]);
|
||||
if (!empty($this->context->user))
|
||||
{
|
||||
$this->context->loggedIn = true;
|
||||
}
|
||||
}
|
||||
if (empty($this->context->user))
|
||||
{
|
||||
#todo: construct anonymous user
|
||||
$this->context->user = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function workWrapper($workCallback)
|
||||
{
|
||||
$this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/';
|
||||
R::setup('sqlite:' . $this->config->main->dbPath);
|
||||
session_start();
|
||||
|
||||
$this->context->layoutName = isset($_GET['json'])
|
||||
? 'layout-json'
|
||||
: 'layout-normal';
|
||||
$this->context->transport = new StdClass;
|
||||
$this->context->transport->success = null;
|
||||
|
||||
$this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/';
|
||||
R::setup('sqlite:' . $this->config->main->dbPath);
|
||||
$this->attachUser();
|
||||
|
||||
if (empty($this->context->route))
|
||||
{
|
||||
$this->context->viewName = 'error-404';
|
||||
|
|
|
@ -1,28 +1,8 @@
|
|||
<?php
|
||||
abstract class AbstractController
|
||||
{
|
||||
protected function attachUser()
|
||||
{
|
||||
$this->context->loggedIn = false;
|
||||
if (isset($_SESSION['user-id']))
|
||||
{
|
||||
$this->context->user = R::findOne('user', 'id = ?', [$_SESSION['user-id']]);
|
||||
if (!empty($this->context->user))
|
||||
{
|
||||
$this->context->loggedIn = true;
|
||||
}
|
||||
}
|
||||
if (empty($this->context->user))
|
||||
{
|
||||
#todo: construct anonymous user
|
||||
$this->context->user = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function workWrapper($workCallback)
|
||||
{
|
||||
$this->attachUser();
|
||||
|
||||
try
|
||||
{
|
||||
$workCallback();
|
||||
|
|
|
@ -15,7 +15,7 @@ class AuthController extends AbstractController
|
|||
//check if already logged in
|
||||
if ($this->context->loggedIn)
|
||||
{
|
||||
\Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search'));
|
||||
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class AuthController extends AbstractController
|
|||
throw new SimpleException('You haven\'t confirmed your e-mail address yet');
|
||||
|
||||
$_SESSION['user-id'] = $dbUser->id;
|
||||
\Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search'));
|
||||
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
||||
$this->context->transport->success = true;
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class AuthController extends AbstractController
|
|||
$this->context->viewName = null;
|
||||
$this->context->viewName = null;
|
||||
unset($_SESSION['user-id']);
|
||||
\Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search'));
|
||||
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ class AuthController extends AbstractController
|
|||
//check if already logged in
|
||||
if ($this->context->loggedIn)
|
||||
{
|
||||
\Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search'));
|
||||
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ class AuthController extends AbstractController
|
|||
if (!$emailActivation and !$adminActivation)
|
||||
{
|
||||
$_SESSION['user-id'] = $dbUser->id;
|
||||
$this->attachUser();
|
||||
\Chibi\Registry::getBootstrap()->attachUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ class AuthController extends AbstractController
|
|||
//check if already logged in
|
||||
if ($this->context->loggedIn)
|
||||
{
|
||||
\Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search'));
|
||||
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ class AuthController extends AbstractController
|
|||
if (!$adminActivation)
|
||||
{
|
||||
$_SESSION['user-id'] = $dbUser->id;
|
||||
$this->attachUser();
|
||||
\Chibi\Registry::getBootstrap()->attachUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
11
src/Controllers/CommentController.php
Normal file
11
src/Controllers/CommentController.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
class CommentController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @route /comments
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
}
|
11
src/Controllers/IndexController.php
Normal file
11
src/Controllers/IndexController.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @route /
|
||||
* @route /index
|
||||
*/
|
||||
public static function indexAction()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -2,15 +2,28 @@
|
|||
class PostController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @route /
|
||||
* @route /index
|
||||
* @route /posts
|
||||
* @route /posts/{query}
|
||||
* @validate query .*
|
||||
*/
|
||||
public function searchAction()
|
||||
public function listAction($query = null)
|
||||
{
|
||||
$tp = new StdClass;
|
||||
$tp->posts = [];
|
||||
$tp->posts []= 1;
|
||||
$tp->posts []= 2;
|
||||
$this->context->transport = $tp;
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /post/upload
|
||||
*/
|
||||
public function uploadAction()
|
||||
{
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /post/{id}
|
||||
*/
|
||||
public function showAction($id)
|
||||
{
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
}
|
||||
|
|
11
src/Controllers/TagController.php
Normal file
11
src/Controllers/TagController.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
class TagController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @route /tags
|
||||
*/
|
||||
public static function listAction()
|
||||
{
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
}
|
20
src/Controllers/UserController.php
Normal file
20
src/Controllers/UserController.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @route /users
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /user/{name}
|
||||
* @validate name [^\/]+
|
||||
*/
|
||||
public function showAction($name)
|
||||
{
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
}
|
1
src/Views/index-index.phtml
Normal file
1
src/Views/index-index.phtml
Normal file
|
@ -0,0 +1 @@
|
|||
Todo: index
|
|
@ -6,24 +6,38 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<div>
|
||||
<?php if (empty($this->context->user)): ?>
|
||||
<a href="<?php echo \Chibi\UrlHelper::route('auth', 'login') ?>">
|
||||
login
|
||||
</a>
|
||||
or
|
||||
<a href="<?php echo \Chibi\UrlHelper::route('auth', 'register') ?>">
|
||||
register
|
||||
</a>
|
||||
<?php else: ?>
|
||||
logged in as <?php echo $this->context->user->name ?>
|
||||
|
||||
<a href="<?php echo \Chibi\UrlHelper::route('auth', 'logout') ?>">
|
||||
logout
|
||||
</a>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="<?php echo \Chibi\UrlHelper::route('index', 'index') ?>">Home</a></li>
|
||||
<li><a href="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>">Browse</a></li>
|
||||
<li><a href="<?php echo \Chibi\UrlHelper::route('comment', 'list') ?>">Comments</a></li>
|
||||
<li><a href="<?php echo \Chibi\UrlHelper::route('post', 'list', ['query' => 'favmin:1']) ?>">Favorites</a></li>
|
||||
<li><a href="<?php echo \Chibi\UrlHelper::route('user', 'show', ['name' => $this->context->user->name]) ?>">Account</a></li>
|
||||
<li><a href="<?php echo \Chibi\UrlHelper::route('post', 'upload') ?>">Upload</a></li>
|
||||
<li>
|
||||
<form action="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>" method="get">
|
||||
<input type="search" name="query" placeholder="search…">
|
||||
<input type="submit" name="submit" value="Go">
|
||||
</form>
|
||||
</li>
|
||||
<li>
|
||||
<?php if (empty($this->context->user)): ?>
|
||||
<a href="<?php echo \Chibi\UrlHelper::route('auth', 'login') ?>">Login</a>
|
||||
or
|
||||
<a href="<?php echo \Chibi\UrlHelper::route('auth', 'register') ?>">register</a>
|
||||
<?php else: ?>
|
||||
<?php echo $this->context->user->name ?>
|
||||
|
||||
<a href="<?php echo \Chibi\UrlHelper::route('auth', 'logout') ?>">
|
||||
Logout
|
||||
</a>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<?php echo $this->renderView() ?>
|
||||
<section>
|
||||
<?php echo $this->renderView() ?>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue