rough implementations of Moment and Essay creation and viewing completed.
This commit is contained in:
+68
-55
@@ -2,6 +2,8 @@
|
||||
include 'functions/init.php';
|
||||
|
||||
error_log('RECEIVED: ' . pretty_dump($_POST));
|
||||
error_log('ALSO: ' . pretty_dump($_FILES));
|
||||
|
||||
if (isset($_POST['ajaxId'])) {
|
||||
switch ($_POST['ajaxId']) {
|
||||
case 'login':
|
||||
@@ -25,12 +27,18 @@ if (isset($_POST['ajaxId'])) {
|
||||
case 'newSpaceHTML':
|
||||
handleNewSpaceHTML();
|
||||
break;
|
||||
case 'editPostHTML':
|
||||
handleEditPostHTML();
|
||||
break;
|
||||
case 'deletePost':
|
||||
handleDeletePost();
|
||||
break;
|
||||
case 'deleteSpace':
|
||||
handleDeleteSpace();
|
||||
break;
|
||||
case 'viewEssay':
|
||||
handleViewEssay();
|
||||
break;
|
||||
}
|
||||
} else if (isset($_POST['formID'])) {
|
||||
switch ($_POST['formID']) {
|
||||
@@ -42,6 +50,9 @@ if (isset($_POST['ajaxId'])) {
|
||||
case 'newPost':
|
||||
handleNewPost();
|
||||
break;
|
||||
case 'editPost':
|
||||
handleEditPost();
|
||||
break;
|
||||
case 'newSpace':
|
||||
handleNewSpace();
|
||||
break;
|
||||
@@ -53,6 +64,18 @@ if (isset($_POST['ajaxId'])) {
|
||||
header('Location: ' . $_POST['redirect']);
|
||||
}
|
||||
|
||||
function handleViewEssay()
|
||||
{
|
||||
if (!isset($_POST['id']))
|
||||
return;
|
||||
|
||||
$essay = Post::retrieveFromDB($_POST['id']);
|
||||
if (!is_a($essay, 'Essay'))
|
||||
return;
|
||||
|
||||
return json_encode(['html' => $essay->getHTML()]);
|
||||
}
|
||||
|
||||
function handleDeleteSpace()
|
||||
{
|
||||
if (!isset($_POST['id'])) {
|
||||
@@ -84,20 +107,28 @@ function handleNewSpace()
|
||||
|
||||
function handleNewPost()
|
||||
{
|
||||
if (!isset($_POST['postType']) || !isset($_POST['space']))
|
||||
if (!isset($_POST['postType']) || !isset($_POST['space']) || !isset($_SESSION['user']))
|
||||
return;
|
||||
|
||||
// TODO: Better input validation for SQL Inj. and XSS
|
||||
switch ($_POST['postType']) {
|
||||
case 'Thought':
|
||||
if (!isset($_POST['thought']))
|
||||
return;
|
||||
$id = randomId(1) * -1;
|
||||
new Thought(Space::retrieveFromDB($_POST['space']), $id, unserialize($_SESSION['user']), 3, 2, urldecode($_POST['thought']));
|
||||
new Thought($_POST['space'], $id, unserialize($_SESSION['user']), 3, 2, urldecode($_POST['thought']));
|
||||
break;
|
||||
case 'Moment':
|
||||
if (!isset($_FILES['image']) || !isset($_POST['caption']))
|
||||
return;
|
||||
$id = randomId(1) * -1;
|
||||
new Moment($_POST['space'], $id, unserialize($_SESSION['user']), 2, 2, $_FILES['image'], $_POST['caption']);
|
||||
break;
|
||||
case 'Essay':
|
||||
new Essay(Space::retrieveFromDB($_POST['space']), null, unserialize($_SESSION['user']), 3, 2, $_POST['title'], $_POST['markdown'], $_POST['excerpt']);
|
||||
if (!isset($_POST['title']) || !isset($_POST['markdown']) || !isset($_POST['excerpt']))
|
||||
return;
|
||||
$id = randomId(1) * -1;
|
||||
new Essay($_POST['space'], $id, unserialize($_SESSION['user']), 3, 2, $_POST['title'], $_POST['markdown'], $_POST['excerpt']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -204,64 +235,46 @@ function getSpaceIcon($space)
|
||||
}
|
||||
}
|
||||
|
||||
function handleNewPostHTML()
|
||||
function handleEditPost()
|
||||
{
|
||||
$user = unserialize($_SESSION['user']);
|
||||
if (!isset($_POST['id']) || !isset($_POST['postType']) || !isset($_POST['space']))
|
||||
return;
|
||||
|
||||
// TODO: Need to plumb this into the DB via AJAX.
|
||||
// TODO: Need to store the current space in SESSION and use that to auto-select a Space
|
||||
// TODO: List the user's spaces or let them search for a space or quick select a favorited space
|
||||
$html = '
|
||||
<div class="med_width std_border center padding modalContent">
|
||||
<h3 id="newPostLabel">New Thought</h3>
|
||||
<form method="post" action="director.php">
|
||||
<input type="hidden" name="formID" value="newPost">
|
||||
<input type="hidden" name="redirect" value="" id="redirect">
|
||||
<input type="hidden" name="postType" value="Thought" id="postType">
|
||||
<input type="hidden" name="space" value="' . $_GET['id'] . '">
|
||||
|
||||
<div id="newThought" class="column">
|
||||
<input type="text" name="thought" placeholder="Jot a Thought." autofocus id="thought">
|
||||
</div>
|
||||
|
||||
<div id="newMoment" class="column" style="display: none;">
|
||||
<input type="text" name="caption" placeholder="Caption goes here." autofocus id="caption">
|
||||
</div>
|
||||
|
||||
<div id="newEssay" class="column" style="display: none;">
|
||||
<input type="text" name="title" placeholder="Title" autofocus id="title">
|
||||
<textarea name="markdown" placeholder="#Heading" id="markdown"></textarea>
|
||||
<input type="text" name="excerpt" placeholder="A 2-3 sentence summary." id="excerpt">
|
||||
</div>
|
||||
|
||||
<div class="column" id="postSpaces">
|
||||
';
|
||||
|
||||
$spaces = $user->getAllSpaces();
|
||||
foreach ($spaces as $s) {
|
||||
$html .= '
|
||||
<label class="form_checkbox_container">' . $s->getName() . ' <i class="nf ' . getSpaceIcon($s) . ' left_margin"></i>
|
||||
<input type="radio" name="space" value="' . $s->getId() . '" id="space-' . $s->getId() . '">
|
||||
<span class="checkmark"></span>
|
||||
</label>
|
||||
';
|
||||
switch ($_POST['postType']) {
|
||||
case 1:
|
||||
if (!isset($_POST['title']) || !isset($_POST['markdown']) || !isset($_POST['excerpt']) || !isset($_POST['space']))
|
||||
return;
|
||||
Essay::edit($_POST['id'], $_POST['title'], $_POST['markdown'], $_POST['excerpt'], $_POST['space']);
|
||||
break;
|
||||
case 2:
|
||||
if (!isset($_POST['caption']))
|
||||
return;
|
||||
Moment::edit($_POST['id'], $_POST['caption'], $_POST['space']);
|
||||
break;
|
||||
case 3:
|
||||
if (!isset($_POST['thought']))
|
||||
return;
|
||||
Thought::edit($_POST['id'], $_POST['thought'], $_POST['space']);
|
||||
break;
|
||||
}
|
||||
|
||||
$html .= '
|
||||
</div>
|
||||
if (isset($_POST['redirect']))
|
||||
header('Location: ' . $_POST['redirect']);
|
||||
else
|
||||
header('Location: .');
|
||||
}
|
||||
|
||||
<input class="button" type="submit" value="Share" id="share">
|
||||
</form>
|
||||
<div class="line std_border"></div>
|
||||
<div id="newModalNav" class="row space_between">
|
||||
<span id="newNavThought" class="link">Thought</span>
|
||||
<span id="newNavMoment" class="link">Moment</span>
|
||||
<span id="newNavEssay" class="link">Essay</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
function handleEditPostHTML()
|
||||
{
|
||||
if (!isset($_POST['id']))
|
||||
return;
|
||||
|
||||
echo json_encode(['html' => $html]);
|
||||
echo json_encode(['html' => Post::getEditHTML($_POST['id'])]);
|
||||
}
|
||||
|
||||
function handleNewPostHTML()
|
||||
{
|
||||
echo json_encode(['html' => Post::getComposeHTML()]);
|
||||
}
|
||||
|
||||
function handle_login()
|
||||
|
||||
Reference in New Issue
Block a user