ID: 45fba671599fe892818231baf6109d95c234a75a
47 lines
—
926B —
View raw
| <?php
require_once 'session.php';
require_once 'database.php';
require_once 'twig.php';
// Must be logged in
if (!Session::is_valid ())
{
header ('Location: ./login');
exit ();
}
$db = new Database();
$db->connect();
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
// Make sure we have a title
if (!isset ($_POST['title']))
{
header ('Location: ./');
exit ();
}
// Trim title
$title = trim ($_POST['title']);
// Title empty
if (0 == strlen ($title))
{
header ('Location: ./submit');
exit ();
}
// Title is ok, add the new post
$post_hash_id = $db->new_post ($title, $_POST['link'], $_POST['text'], Session::get_userid());
// Redirect to the new post page
header ('Location: ./post/' . $post_hash_id);
exit();
}
// Render template
echo $twig->render (
'submit.twig',
array ('title' => 'Submit'));
|