home » zplus/freepost.git
ID: ed531f9351b6be0979885633a41a2bb9b48a8044
61 lines — 1K — View raw


<?php

/* This script is used to reply to a user comment */

require_once 'session.php';
require_once 'database.php';
require_once 'date.php';
require_once 'twig.php';

$db = new Database();
$db->connect();

// Must be logged in
if (!Session::is_valid())
{
    header ('Location: ./');
    exit ();
}


// POST     ====================================================================


// Submit the new comment
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
    if (!isset ($_POST['text']))
    {
        header ('Location: ./');
        exit ();
    }
    
    $parent_comment = $db->get_comment ($_POST['parent_comment']);
    
    $hash_id = $db->new_reply ($_POST['text'], $parent_comment['hashId'], Session::get_userid ());
    
    // Can't post?! What happened?!
    if (is_null ($hash_id))
        header ('Location: ./');
    else
        header ('Location: ./post/' . $hash_id['post'] . '#comment-' . $hash_id['comment']);
    
    exit ();
}


// GET     =====================================================================


// Must have a comment id (to reply to)
if (!isset ($_GET['comment']))
{
    header ('Location: ./');
    exit ();
}

$comment = $db->get_comment ($_GET['comment']);

// Render template
echo $twig->render (
    'reply.twig',
    array ('comment' => $comment));