freepost codebase git repo

[[ 🗃 ^Avlxv freepost ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Commits]

Clone

HTTPS: git clone https://vervis.peers.community/repos/Avlxv

SSH: git clone USERNAME@vervis.peers.community:Avlxv

Branches

Tags

master ::

submit.php

<?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 ();
    }
    
    // Normalize Link
    $link = trim ($_POST['link']);
    
    if (strlen ($link) > 0)
    {
        $link_components = parse_url ($link);
        
        if (!isset ($link_components['scheme']))
            $link = 'http://' . $link;
    }
    
    // Add the new post
    $post_hash_id = $db->new_post ($title, $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'));

[See repo JSON]