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 ::

user.php

<?php

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

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

// Form submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
    if (!isset ($_POST['update']))
    {
        header ('Location: ./');
        exit ();
    }
    
    // Open database connection
    $db = new Database();
    $db->connect();
    
    // Update database with new user information
    $data = array(
        'about' => (isset ($_POST['about']) ? $_POST['about'] : ''),
        'email' => (isset ($_POST['email']) ? $_POST['email'] : ''));
    
    $db->edit_user ($data['about'], $data['email'], Session::get_userid ());
    
    // Update $_SESSION
    Session::set_property ('about', $data['about']);
    Session::set_property ('email', $data['email']);
    
    header ('Location: ./user');
    exit ();
}


// Show public profile
if (isset ($_GET['username']))
{
    $user = $db->get_user ($_GET['username']);
    
    // User doesn't exist
    if (is_null ($user) || empty ($user))
    {
        header ('Location: ../login');
        exit ();
    }
    
    echo $twig->render (
        'user.twig',
        array (
            'title'      => $user['username'],
            'profile'    => 'public',
            'other_user' => $user));
} else {
    // Show private page
    echo $twig->render (
        'user.twig',
        array (
            'title'   => Session::get_username (),
            'profile' => 'private'));
}
[See repo JSON]