Files
2025-06-10 10:46:22 -06:00

203 lines
6.4 KiB
PHP

<?php
require_once 'functions/init.php';
// UI Components
/* foreach (glob('components/spaces/*.php') as $file) */
/* require_once $file; */
require_once 'components/core/head.php';
if (isset($_GET['view'])) {
switch ($_GET['view']) {
case 'essay':
if (isset($_GET['id'])) {
// TODO: Need another check here to verify the user is in the Essay's space.
$essay = Post::retrieveFromDB($_GET['id']);
if ($essay)
echo displayEssay($essay);
else
echo errorScreen('Essay does not exist!', 'The Essay ID provided does not exist in the database.');
} else
echo displaySpace(2025);
break;
case 'show':
// TODO: After implementing the notification modal, notify the user on success/fail auth events.
if (isset($_GET['id'])) {
if (isset($_SESSION['user'])) {
$availableSpaces = unserialize($_SESSION['user'])->getSpaces();
foreach ($availableSpaces as $s) {
$space = $s->getSpace();
if ($space->getId() == $_GET['id']) {
echo displaySpace($_GET['id']);
break;
} else if ($space->getVisibility() == 1) {
echo displaySpace($_GET['id']);
break;
} else
echo 'TODO: Notification Modal -> User not a member';
}
} else {
if ($space->getVisibility() == 1)
echo displaySpace($_GET['id']);
else
echo 'TODO: Notification Modal -> Space is not Open';
}
} else
echo displaySpaceList();
break;
case 'list':
if (isset($_SESSION['user']))
echo displaySpaceList();
else
echo displaySpace(2025);
break;
default:
echo displaySpaceList();
break;
}
} else {
echo displaySpace(2025);
}
if (isset($_SESSION['user']))
echo actionBar();
if (isset($_GET['id']))
echo backButton();
require_once 'components/core/foot.php';
function backButton()
{
$html = '
<div class="link" id="backButton">
<i class="nf nf-fa-arrow_left"></i>
</div>
';
return $html;
}
function actionBar()
{
$user = unserialize($_SESSION['user']);
$html = '
<div class="std_border med_width padding glass" id="actionBar">
<div class="row space_between" id="primaryActions">
<div class="column center link med_width" id="actionSpace"><i class="nf nf-md-layers_outline"></i><p class="link">Space</p></div>
<div class="column center link med_width" id="actionPost"><i class="nf nf-md-text"></i><p class="link">Post</p></div>
</div>
<div class="row space_between" id="postActions" style="display: none;">
<div class="column center link med_width" id="postBack"><i class="nf nf-cod-arrow_circle_left"></i><p class="link">Back</p></div>
<div class="column center link med_width" id="postNew"><i class="nf nf-md-chat_plus"></i><p class="link">New</p></div>
</div>
<div class="row space_between" id="spaceActions" style="display: none;">
<div class="column center link med_width" id="spaceBack"><i class="nf nf-cod-arrow_circle_left"></i><p class="link">Back</p></div>
<div class="column center link med_width" id="spaceHome" href="spaces.php?view=show&id=' . $user->getId() . '"><i class="nf nf-fa-home"></i><p class="link">Home</p></div>
<div class="column center link med_width" id="spaceNew"><i class="nf nf-md-layers_plus"></i><p class="link">New</p></div>
</div>
</div>
';
return $html;
}
function errorScreen(String $heading, String $msg)
{
$html = '
<div class="column std_border med_width padding center top_margin">
<h1>' . $heading . '</h1>
<p>' . $msg . '</p>
</div>
';
return $html;
}
function displayEssay(Essay $e)
{
/* if (isset($_SESSION['user'])) */
/* if ($e->allowUser(unserialize($_SESSION['user'])) || $e->getSpace()->getVisibility() != 1) */
/* return errorScreen('Access Denied!', 'You do not have access to the Space that this Essay is in.'); */
$parsedown = new Parsedown();
$parsedown->setSafeMode(true);
$html = '
<div class="std_width std_border padding center top_margin" style="height: 75vh; overflow-y: auto;">
' . $parsedown->parse($e->getMarkdown()) . '
</div>
';
return $html;
}
function displaySpaceList()
{
if (!isset($_SESSION['user']))
return displaySpace();
$user = unserialize($_SESSION['user']);
$html = '
<div class="std_width std_border padding center top_margin" style="height: 75vh; overflow-y: auto;">
<div class="column space_between full_width">
<h1>Spaces</h4>
</div>
<div class="line"></div>
';
$spaces = $user->getSpaces();
foreach ($spaces as $s)
$html .= $s->getSpace()->getCardHTML();
$html .= '
</div>
';
return $html;
}
function displaySpace($id = 2025)
{
$spaces = unserialize($_SESSION['user'])->getSpaces();
foreach ($spaces as $s) {
$space = $s->getSpace();
if ($space->getId() == $id) {
break;
}
}
if (!$space)
return;
if ($space) {
$html = '
<div class="std_width std_border padding center top_margin" style="height: 75vh; overflow-y: auto;">
<div class="column space_between full_width">
<h1>' . $space->getName() . '</h4>
<p>' . $space->getDescription() . '</p>
</div>
<div class="line"></div>
';
$subspaces = $space->getSubSpaces();
foreach ($subspaces as $ss) {
$html .= $ss->getCardHTML();
}
// TODO: Need to investigate this bug in Posts
$posts = $space->getPosts();
foreach ($posts as $post)
foreach ($post as $p)
$html .= $p->getCardHTML();
$html .= '
</div>
';
return $html;
}
}