ID: 6f905c0673a379f7a086fb8a198619a3d232dbc9
47 lines
—
925B —
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'));
|