initial commit

This commit is contained in:
Luke Ogburn
2019-03-30 22:43:34 -04:00
commit c4a666e3b6
78 changed files with 5332 additions and 0 deletions

178
post/common.css Normal file
View File

@@ -0,0 +1,178 @@
/* ------------- Global post ------------- */
.container{
width: 60%;
margin: 2% auto 0 auto;
color: #333;
padding: 1em 2em;
line-height: 1.3em;
}
.container>*{
border-radius: 0.3em;
}
/* ------------- Post ------------- */
/* Title, username, time posted */
.editor{
border: none;
border-bottom: 1px solid #ddd;
border-radius: 0.2em;
outline-width: 0;
resize: none;
font-family: 'Montserrat', sans-serif;
font-weight: bold;
}
.title{
width: calc(100% - 0.4em);
font-size: 1.5em;
font-weight: bold;
padding: 0.2em;
font-family: 'Montserrat', sans-serif;
}
#submitPost{
font-size: 1em;
color: #00d09f;
border: 1px solid #00d09f;
border-radius: 0.2em;
background-color: white;
padding: 0.5em 1em;
margin: 2em auto 0 auto;
display: block;
}
#submitPost:hover{
cursor: pointer;
}
.postType{
color: #888;
font-weight: bold;
margin: 0 0.5em 0 0.2em;
}
/* Text and image */
.content>p{
margin: 0;
}
.card{
padding: 2em 4em;
}
/* ------------- Post editor ------------- */
.title{
margin-bottom: 0.3em;
}
/* Actual part to write the post */
#postWriter{
background-color: white;
}
#postEditor{
padding: 0.5em;
width: calc(100% - 1em);
min-height: 3em;
}
#postEditor:empty:before{
content: attr(placeholder);
color: #777;
}
#postEditor:focus{
outline-width: 0;
}
#tagsAdder{
margin-top: 2em;
}
#postRadios{
text-align: center;
margin-top: 3em;
}
/*Images adder*/
input[type=file]{
display: none;
}
label[for=postImg]{
margin: 1em 0;
padding: 1.5em 0;
display: block;
text-align: center;
border: 2px dashed #bbb;
border-radius: 0.3em;
color: #444;
}
.postTitle{
margin-top: 2em;
font-size: 1.2em;
}
label:hover{
cursor: pointer;
}
input[type=radio]{
display: none;
}
input[type=radio]:checked + label{
color: #00d09f;
}
label.typeLabel:not(:last-of-type), label.tagLabel:not(:last-of-type){
margin-right: 2em;
}
/*Previously had images*/
.postImage{
margin-top: 1em;
width: 100%;
border-radius: 0.3em;
}
.postDocPreview{
margin-top: 1em;
width: 100%;
border-radius: 0.2em;
border: 1px solid #999;
height: 50vh;
}
#show:hover, #hide:hover{
cursor: pointer;
}
#hideImgs{
display: none;
}
#hideImgs ~ #hide{
display: block;
}
#hideImgs ~ #show{
display: none;
}
#hideImgs:checked ~ #hide{
display: none;
}
#hideImgs:checked ~ #show{
display: block;
}
#hideImgs ~ label{
margin-top: 2em;
color: #00d09f;
text-align: center;
font-size: 0.9em;
margin-bottom: 0;
}
#hideImgs:checked ~ img{
display: none;
}
@media (max-width: 1000px){
.container{
width: 90vw;
padding: 0;
margin-top: 2em;
}
#post{
padding: 1em 2em;
}
label{
margin-right: 0 !important;
margin-bottom: 5px;
text-align: center;
display: block;
list-style-type: none;
}
}

110
post/delete.php Normal file
View File

@@ -0,0 +1,110 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
//Making sure that the user is allowed to delete the post
if(getPostInfo($_GET["post"])->poster_id != $current_user && !verifyUser("admin")){
msg("You are not the owner of that post.");
header("Location: /forum/post?post=".$_GET["post"]);
exit(); //needed for some reason
}else{
conn();
//Moving images/documents
$getfstmt = $conn->prepare("SELECT image FROM forums WHERE post_id = :pid");
$getfstmt->bindParam(":pid", $_GET["post"]);
$getfstmt->execute();
$images = $getfstmt->fetch(PDO::FETCH_ASSOC);
if(count($images)>0 && $images["image"] != NULL){
$images = explode(",", substr($images["image"], 0, -1));
$poster = getPostInfo($_GET["post"])->poster_id;
$dir = $_SERVER['DOCUMENT_ROOT']."/deletedContent/$poster/";
if(!is_dir($dir)){
mkdir($dir);
}
mkdir($dir.$_GET["post"]);
foreach($images as $file){
$oldName = $_SERVER['DOCUMENT_ROOT']."/forum/images/".$file;
$newName = $dir.$_GET["post"]."/".$file;
rename($oldName, $newName);
if(!file_exists($newName)){
msg("Unable to delete post");
header("Location: /forum/post/?post=".$_GET["post"]);
exit(); //needed for some reason
}
}
}
//Putting post into "deleted" database
$post = getPostInfo($_GET["post"])->post_id;
$pstr = getPostInfo($_GET["post"])->poster_id;
$sctn = getPostInfo($_GET["post"])->section;
$type = getPostInfo($_GET["post"])->type;
$date = getPostInfo($_GET["post"])->date;
$tags = getPostInfo($_GET["post"])->tags;
$titl = getPostInfo($_GET["post"])->title;
$cont = getPostInfo($_GET["post"])->content;
$imag = getPostInfo($_GET["post"])->image;
$rprt = getPostInfo($_GET["post"])->reports;
$mfstmt = $conn->prepare("INSERT INTO deletedForums (post_id, poster_id, section, type, date, tags, title, content, image, reports) VALUES (:post, :pstr, :sctn, :type, :date, :tags, :titl, :cont, :imag, :rprt)");
$mfstmt->bindParam(":post", $post);
$mfstmt->bindParam(":pstr", $pstr);
$mfstmt->bindParam(":sctn", $sctn);
$mfstmt->bindParam(":type", $type);
$mfstmt->bindParam(":date", $date);
$mfstmt->bindParam(":tags", $tags);
$mfstmt->bindParam(":titl", $titl);
$mfstmt->bindParam(":cont", $cont);
$mfstmt->bindParam(":imag", $imag);
$mfstmt->bindParam(":rprt", $rprt);
$mfstmt->execute();
//post pstr date text rpts
$getcstmt = $conn->prepare("SELECT * FROM comments WHERE post_id = :pid");
$getcstmt->bindParam(":pid", $_GET["post"]);
$getcstmt->execute();
$comments = $getcstmt->fetchAll();
$mcstmt = $conn->prepare("INSERT INTO deletedComments (post_id, poster_id, date, text, reports) VALUES (:post, :pstr, :date, :text, :rpts)");
foreach($comments as $comment){
$mcstmt->bindParam(":post", $comment["post_id"]);
$mcstmt->bindParam(":pstr", $comment["poster_id"]);
$mcstmt->bindParam(":date", $comment["date"]);
$mcstmt->bindParam(":text", $comment["text"]);
$mcstmt->bindParam(":rpts", $comment["reports"]);
$mcstmt->execute();
}
if(count($comments) == 0){
$mcstmt = true;
}
//Making sure the post was moved correctly
if(!$mfstmt || !$mcstmt){
msg("Post could not be deleted.");
header("Location: /forum/post/?post=".$_GET["post"]);
exit(); //just in case
}
//Deleting content from the original databases
$fstmt = $conn->prepare("DELETE FROM forums WHERE post_id = :pid");
$fstmt->bindParam(":pid", $_GET["post"]);
$fstmt->execute();
$cstmt = $conn->prepare("DELETE FROM comments WHERE post_id = :pid");
$cstmt->bindParam(":pid", $_GET["post"]);
$cstmt->execute();
$bstmt = $conn->prepare("DELETE FROM bookmarks WHERE post_id = :pid");
$bstmt->bindParam(":pid", $_GET["post"]);
$bstmt->execute();
//Feedback msg and redirection
if($fstmt && $cstmt && $bstmt){
msg("Post deleted.");
header("Location: /forum");
}else{
reportError("Error deleting post");
msg("There was an error deleting your post. It has been reported.");
header("Location: /forum/post?post=".$_GET["post"]);
}
}
?>

154
post/edit.php Normal file
View File

@@ -0,0 +1,154 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
$post = getPostInfo($_GET["post"]);
$GLOBALS["post"] = $post;
if($post->poster_id!=$current_user){
msg("What if someone did that to you?");
header("Location: /forum/post/?post=".$_GET["post"]);
}
$datediff = time() - strtotime($post->date);
$mins = round($datediff / (60));
if($mins > 5){
msg("You can't edit that post.");
header("Location: /forum/post/?post=".$_GET["post"]);
}
function checked($type, $value){
return $GLOBALS["post"]->$type==$value?"checked":"";
}
$imgArray = $post->image==NULL?"":"\"".str_replace(",", "\", \"",substr($post->image,0,-1))."\"";
?>
<!DOCTYPE html>
<html>
<?php
$css = "common";
include $_SERVER['DOCUMENT_ROOT']."/res/head";
?>
<body>
<?php include $_SERVER['DOCUMENT_ROOT']."/res/top"; ?>
<form method=POST action=submitEdit.php enctype=multipart/form-data>
<div class="container">
<div id=post class="card noHover">
<div class="forum">
<input type=text class="editor title" name=title placeholder="Title goes here" value="<?=$post->title?>" autocomplete=off>
<div class=content>
<div id=postWriter>
<div contentEditable=true id="postEditor" name="contentPlaceholder" placeholder="Words go here" class=editor onkeyup=loadContent()><?=$post->content?></div>
<textarea id="contentSubmitter" style="display:none" name=content></textarea>
<script>
function loadContent(){
document.getElementById("contentSubmitter").value = document.getElementById("postEditor").innerHTML;
}
</script>
</div>
</div>
<div id=imageDiv>
<input id=postImg class=edit type=file name=images[] onchange=fileUploadCounter() multiple>
<label id=forImg for=postImg>Add Photos/Files<br><small>(PNG, JPG, JPEG, DOC, DOCX, PDF)</small></label>
</div>
<script>
document.addEventListener("DOMContentLoaded", function(event){
var i = 0;
if(i==0){
text = "<?=$post->content?>";
document.getElementById("postEditor").innerHTML = text;
document.getElementById("contentSubmitter").value = text;
i = 21; //making it only run once
}
});
var fileUploadCounter = function(){
var files = document.getElementById("postImg").files.length;
if(files != 0) {
document.getElementById("forImg").innerHTML = files + " files selected";
}
};
</script>
</div>
<div class=content>
<?php
if($post->image != NULL){
echo "<input type=checkbox id=hideImgs>
<label for=hideImgs id=hide class=noSelect>HIDE ATTACHMENTS</label>
<label for=hideImgs id=show class=noSelect>SHOW ATTACHMENTS</label>";
$i=1;
foreach(explode(",", substr($post->image, 0, -1)) as $file){
//substr gets rid of the last comma, explode makes the array
$exType = substr($file, strpos($file, '.')+1);
$docFiles = ["doc", "docx", "pdf"];
$imgFiles = ["jpg", "jpeg", "png"];
//image stuff
if(in_array($exType, $docFiles)){
echo "<iframe class='postDocPreview toggleView' src=https://docs.google.com/gview?url=http://ib.lukeogburn.com/forum/images/$file&embedded=true></iframe>";
//<embed src="file_name.pdf" width="800px" height="2100px" />
}else if(in_array($exType, $imgFiles)){
echo "<img class='postImage toggleView' src=/forum/images/$file>";
}
}
}
?>
<!-- changing the order of posts
<input id=orderedImgs type=text name=orderedImgs style=display:none>
<script>
var imgArray = [<?=$imgArray?>];
var number = function(img){
if(imgArray.indexOf(img) > -1){
//remove it from the array if it exists
imgArray.splice(imgArray.indexOf(img), 1);
}
imgArray.push(img);
imgID = "num"+imgArray[0].replace(/\./g, "");
for(var i = 0; i < imgArray.length; i++){
document.getElementById("num"+imgArray[i].replace(/\./g, "")).innerHTML = i+1;
}
document.getElementById("orderedImgs").value = imgArray.join("-").replace(/\./g, "");
}
</script>-->
</div>
<div id=postRadios>
<p class=postTitle>Subject</p>
<?php
$classes = file_get_contents($_SERVER['DOCUMENT_ROOT']."/res/classes");
$classes = array_filter(explode(",", $classes));
$num = 1;
foreach($classes as $class){
echo "<input name=section value=$class type=radio id=class$num ".checked('section',$class).">
<label class=tagLabel for=class$num>".ucwords(str_replace('_', ' ', $class))."</label>";
$num++;
}
?>
<input name=section value=none type=radio id=none <?=checked("section","none")?>>
<label class=tagLabel for="none">None</label>
<!--------------------------------------------------------------->
<p class=postTitle>Post type</p>
<input name=type value=notes type=radio id=type1 <?=checked("type","notes")?>>
<label class=typeLabel for="type1">Notes</label>
<input name=type value=question type=radio id=type2 <?=checked("type","question")?>>
<label class=typeLabel for="type2">Quesion</label>
<input name=type value=humor type=radio id=type3 <?=checked("type","humor")?>>
<label class=typeLabel for="type3">Humor</label>
<input name=type value=resource type=radio id=type4 <?=checked("type","resource")?>>
<label class=typeLabel for="type4">Resource</label>
<input name=type value=other type=radio id=type5 <?=checked("type","other")?>>
<label class=typeLabel for="type5">Other</label>
</div>
</div>
<div id=rules class="forum card noHover">
<h3>Rules:</h3>
<?php require $_SERVER['DOCUMENT_ROOT']."/res/rules"; ?>
<input type=text name=pid value=<?=$_GET["post"]?> style="display:none;">
<button type=submit id=submitPost>I understand the rules - Save!</button>
</div>
</div>
</form>
</body>
</html>

74
post/index.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
?>
<!DOCTYPE html>
<html>
<?php
$css = "common";
include $_SERVER['DOCUMENT_ROOT']."/res/head";
?>
<body>
<?php include $_SERVER['DOCUMENT_ROOT']."/res/top"; ?>
<form method=POST action=submitPost.php enctype=multipart/form-data>
<div class="container">
<div id=post class="card noHover">
<div class="forum">
<input type=text class="editor title" name=title placeholder="Title goes here" autocomplete=off required>
<div class=content>
<div id=postWriter>
<div contentEditable=true id="postEditor" name="contentPlaceholder" placeholder="Words go here" class=editor onkeyup=loadContent()></div>
<textarea id="contentSubmitter" style="display:none" name=content></textarea>
<script>
function loadContent(){
document.getElementById("contentSubmitter").value = document.getElementById("postEditor").innerHTML;
}
</script>
</div>
</div>
<div id=imageDiv>
<input id=postImg class=edit type=file name=images[] onchange=fileUploadCounter() accept=".png,.jpg,.jpeg,.doc,.docx,.pdf" multiple>
<label id=forImg for=postImg>Add Photos/Files<br> <small>(PNG, JPG, JPEG, DOC, DOCX, PDF)</small></label>
</div>
<script>
var fileUploadCounter = function(){
var files = document.getElementById("postImg").files.length;
if(files != 0) {
document.getElementById("forImg").innerHTML = files + " files selected";
}
};
</script>
</div>
<div id=postRadios>
<p class=postTitle>Subject</p>
<?php
$classes = file_get_contents($_SERVER['DOCUMENT_ROOT']."/res/classes");
$classes = array_filter(explode(",", $classes));
$num = 1;
foreach($classes as $class){
echo "<input name=section value=$class type=radio id=class$num>
<label class=tagLabel for=class$num>".ucwords(str_replace("_", " ", $class))."</label>";
$num++;
}
?>
<input name=section value=none type=radio id=none checked><label class=tagLabel for=none>None</label>
<p class=postTitle>Post type</p>
<input name=type value=notes type=radio id=type1><label class=typeLabel for="type1">Notes</label>
<input name=type value=question type=radio id=type2><label class=typeLabel for="type2">Quesion</label>
<input name=type value=humor type=radio id=type3><label class=typeLabel for="type3">Humor</label>
<input name=type value=resource type=radio id=type4><label class=typeLabel for="type4">Resource</label>
<input name=type value=other type=radio id=type5 checked><label class=typeLabel for="type5">Other</label>
</div>
</div>
<div id=rules class="forum card noHover">
<h3>Rules:</h3>
<?php require $_SERVER['DOCUMENT_ROOT']."/res/rules"; ?>
<button type=submit id=submitPost>I understand the rules - Submit!</button>
</div>
</div>
</form>
</body>
</html>

76
post/submitEdit.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
/**
* Please note that files uploaded are placed in /forum/images (even non-image
* files) because this function used to only be for images. It has since been
* updated to allow for doc files too.
*
**/
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
conn();
$pid = $_POST["pid"];
$sbj = $_POST["section"];
$typ = $_POST["type"];
$ttl = $_POST["title"];
$ctt = encodeUserLink($_POST["content"]);
$file = $_FILES["images"];
$oldImg = $conn->prepare("SELECT image FROM forums WHERE post_id = :pid");
$oldImg->bindParam(":pid", $pid);
$oldImg->execute();
$oldImg = $oldImg->fetch(PDO::FETCH_ASSOC);
//$oimg = $_POST["orderedImgs"]==""?NULL:$_POST["orderedImgs"];
//if($oimg != NULL){
//$oimg = str_replace("-", ",", $oimg).",";
//$oimg = str_replace("jpg", ".jpg", $oimg);
//$oimg = str_replace("jpeg", ".jpeg", $oimg);
//$oimg = str_replace("png", ".png", $oimg);
//}
if($file["name"][0]!=NULL){
for($i=0; $i<sizeof($file["name"]); $i++){
$ext = explode('.', $file["name"][$i]);
$ext = strtolower($ext[sizeof($ext)-1]);
$allowedExt = array('jpg', 'jpeg', 'png', 'doc', 'docx', 'pdf');
if(in_array($ext, $allowedExt)){
if(!$file["error"][$i]){
$imgDest = randID().".".$ext;
$img .= $imgDest.",";
$dest = $_SERVER['DOCUMENT_ROOT']."/forum/images/".$imgDest;
move_uploaded_file($file["tmp_name"][$i], $dest);
}else{
echo "Error uploading file";
exit();
}
}else{
msg("Bad file type.");
header("Location: /post/edit.php?post=$pid");
exit(); //this is needed for some reason
}
}
}else{
$img = NULL;
}
$oimg = implode(",", $oldImg).$img;
echo $oImg;
//exit();
$stmt = $conn->prepare("UPDATE forums SET section = :scn, type = :typ, title = :ttl, content = :ctt, image = :img WHERE post_id = :pid");
$stmt->bindParam(":scn", $sbj);
$stmt->bindParam(":typ", $typ);
$stmt->bindParam(":ttl", $ttl);
$stmt->bindParam(":ctt", $ctt);
$stmt->bindParam(":img", $oimg);
$stmt->bindParam(":pid", $pid);
$stmt->execute();
if($stmt){
msg("Edits saved.");
header("Location: /forum/post/?post=$pid");
}else{
reportError("Error submitting post edit");
msg("Something's broken. It has been reported.");
header("Location: /forum/post/?post=$pid");
}
?>

62
post/submitPost.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
/**
* Please note that files uploaded are placed in /forum/images (even non-image
* files) because this function used to only be for images. It has since been
* updated to allow for doc files too.
*
**/
require $_SERVER['DOCUMENT_ROOT']."/globalFuncs.php";
conn();
$pid = randID();
$uid = $current_user;
$sbj = $_POST["section"];
$typ = $_POST["type"];
$ttl = $_POST["title"];
$ctt = hyperLink($_POST["content"], $uid, $pid);
$ctt = encodeUserLink($ctt, $uid, $pid);
$file = $_FILES["images"];
if($file["name"][0]!=NULL){
for($i=0; $i<sizeof($file["name"]); $i++){
$ext = explode('.', $file["name"][$i]);
$ext = strtolower($ext[sizeof($ext)-1]);
$allowedExt = array('jpg', 'jpeg', 'png', 'doc', 'docx', 'pdf');
if(in_array($ext, $allowedExt)){
if(!$file["error"][$i]){
$imgDest = randID().".".$ext;
$img .= $imgDest.",";
$dest = $_SERVER['DOCUMENT_ROOT']."/forum/images/".$imgDest;
move_uploaded_file($file["tmp_name"][$i], $dest);
}else{
echo "Error uploading file";
exit();
}
}else{
msg("Bad file type.");
header("Location: /post");
exit(); //this is needed for some reason
}
}
}else{
$img = NULL;
}
$stmt = $conn->prepare("INSERT INTO forums (post_id, poster_id, section, type, title, content, image) VALUES (:pid, :uid, :sbj, :typ, :ttl, :ctt, :img)");
$stmt->bindParam(":pid", $pid);
$stmt->bindParam(":uid", $uid);
$stmt->bindParam(":sbj", $sbj);
$stmt->bindParam(":typ", $typ);
$stmt->bindParam(":ttl", $ttl);
$stmt->bindParam(":ctt", $ctt);
$stmt->bindParam(":img", $img);
$stmt->execute();
if($stmt){
header("Location: /forum/post/?post=$pid");
}else{
msg("Couldn't submit post. This has been reported for you.");
header("Location: /forum");
}
?>