commit c4a666e3b60463391394d979c753b5fbc7c15f9e Author: Luke Ogburn Date: Sat Mar 30 22:43:34 2019 -0400 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05dae6b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +conn.php +googleApi/ diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..e69de29 diff --git a/404.shtml b/404.shtml new file mode 100644 index 0000000..dd10b78 --- /dev/null +++ b/404.shtml @@ -0,0 +1,27 @@ + + + + + + IB Forum + + + + + + + + + + +
+
+

Can't find that page.

+

I had one job. And I failed.

+
+
+ + + \ No newline at end of file diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..de2a99a --- /dev/null +++ b/admin/index.php @@ -0,0 +1,39 @@ + + + + + + + +
+
+

ADMIN ACCOUNTS

+

prepare("SELECT * FROM users WHERE special='owner'"); + $stmt->execute(); + $row = $stmt->fetchAll(); + foreach($row as $person){ + echo "".$person["name"]."
"; + } + $stmt = $conn->prepare("SELECT * FROM users WHERE special='admin'"); + $stmt->execute(); + $row = $stmt->fetchAll(); + foreach($row as $person){ + echo "".$person["name"]."
"; + } + ?>

+
+
+

WANT TO BE AN ADMIN?

+

Contact Luke Ogburn (@name?>) to get more information.

+
+
+ + \ No newline at end of file diff --git a/admin/portal/aboutUser.php b/admin/portal/aboutUser.php new file mode 100644 index 0000000..3be8da8 --- /dev/null +++ b/admin/portal/aboutUser.php @@ -0,0 +1,75 @@ +prepare("SELECT * FROM forums WHERE poster_id = :usr"); + $stmt->bindparam(":usr", $user->id); + $stmt->execute(); + $posts = $stmt->rowCount(); + + //Getting the number of comments + $stmt = $conn->prepare("SELECT * FROM comments WHERE poster_id = :usr"); + $stmt->bindparam(":usr", $user->id); + $stmt->execute(); + $comments = $stmt->rowCount(); + + //Getting the number of reported posts made by user + $stmt = $conn->prepare("SELECT * FROM forums WHERE poster_id = :usr AND reports IS NOT NULL"); + $stmt->bindparam(":usr", $user->id); + $stmt->execute(); + $reportedPosts = $stmt->rowCount(); + + //Getting the number of reported comments made by user + $stmt = $conn->prepare("SELECT * FROM comments WHERE poster_id = :usr AND reports IS NOT NULL"); + $stmt->bindparam(":usr", $user->id); + $stmt->execute(); + $reportedComments = $stmt->rowCount(); +?> + + + + + +
+
+

name?>

+ name; + $id = $user->id; + $login = makeDate($user->last_login); + if($posts == 0){ + $reportedPostsPercent = 0; + }else{ + $reportedPostsPercent = round($reportedPosts/$posts); + } + if($comments == 0){ + $reportedCommentsPercent = 0; + }else{ + $reportedCommentsPercent = round($reportedComments/$comments); + } + + echo " +

Last login: $login

+

Posts made: $posts

+

Reported posts made: $reportedPosts

+

Percent of posts reported: $reportedPostsPercent%

+

Comments made: $comments

+

Reported comments made: $reportedComments

+

Percent of comments reported: $reportedCommentsPercent%

+

User's page

+ "; + ?> +
+ + \ No newline at end of file diff --git a/admin/portal/admin.css b/admin/portal/admin.css new file mode 100644 index 0000000..b048ad3 --- /dev/null +++ b/admin/portal/admin.css @@ -0,0 +1,5 @@ +#userBanMsg{ + font-style: italic; + width: 70%; + margin: 1.5em auto; +} \ No newline at end of file diff --git a/admin/portal/banUser.php b/admin/portal/banUser.php new file mode 100644 index 0000000..787b701 --- /dev/null +++ b/admin/portal/banUser.php @@ -0,0 +1,57 @@ +name) != ""){ + if(verifyUser("admin", $_POST["person"])){ + msg("You cannot ban that user"); + unset($_POST); + header("Location: /admin/portal/banUser.php"); + exit();//needed for some reason, else the code below runs + } + $person = $_POST["person"]; + $reason = $_POST["reason"]; + unset($_POST); + conn(); + $stmt = $conn->prepare("UPDATE users SET special='banned', ban_reason=:rsn WHERE id=:id"); + $stmt->bindParam(":rsn", $reason); + $stmt->bindParam(":id", $person); + $stmt->execute(); + if($stmt){ + $user = getUserInfo($person)->name; + msg("$user has been banned"); + header("Location: /admin/portal/banUser.php"); + } + }else if(isset($_POST["person"]) && strval(getUserInfo($_POST["person"])->name) == ""){ + unset($_POST); + msg("User doesn't exist"); + header("Location: /admin/portal/banUser.php"); + } +?> + + + + + +
+
+

BAN USER

+

Banning a user will make them unable to access the website. Only do this if there is good reason to do so (e.g. cheating or bullying). This can only be undone by Luke Ogburn.

+
+

User's ID (NOT their username):

+
+

Reason for banning user (for them to read):

+ + +
+
+
+
+ + \ No newline at end of file diff --git a/admin/portal/editClasses.php b/admin/portal/editClasses.php new file mode 100644 index 0000000..c09692b --- /dev/null +++ b/admin/portal/editClasses.php @@ -0,0 +1,51 @@ + + + + + + +
+
+

DELETE A CLASS:

+ ".ucwords(str_replace('_', ' ', $class))."

"; + } + ?> +
+
+

ADD A CLASS:

+
+ + +
+
+ + \ No newline at end of file diff --git a/admin/portal/errorReports.php b/admin/portal/errorReports.php new file mode 100644 index 0000000..71a8a09 --- /dev/null +++ b/admin/portal/errorReports.php @@ -0,0 +1,45 @@ + + + + + + prepare("DELETE FROM issue_tracker WHERE id = :id"); + $del->bindParam(":id", $_GET["del"]); + $del->execute(); + if($del){ + msg("Good job :)"); + header("Location: /admin/portal/errorReports.php"); + } + } + + include $_SERVER['DOCUMENT_ROOT']."/res/top"; + $stmt = $conn->prepare("SELECT * FROM issue_tracker ORDER BY date DESC"); + $stmt->execute(); + $stmt = $stmt->fetchAll(); + ?> +
+
+

REPORTED ISSUES

+ ".$report['comment']."
"; + echo "Reported by: ".$report["reporter"]." (".getUserInfo($report["reporter"])->name.") ".makeDate($report["date"])."

"; + } + if($stmt == NULL){ + echo "No issues have been reported :D
"; + } + ?> +
+
+
+ \ No newline at end of file diff --git a/admin/portal/index.php b/admin/portal/index.php new file mode 100644 index 0000000..cb8dc8f --- /dev/null +++ b/admin/portal/index.php @@ -0,0 +1,48 @@ + + + + + + +
+
+

NOTIFICATIONS

+ prepare("SELECT * FROM forums WHERE reports IS NOT NULL"); + $stmt->execute(); + $res = $stmt->fetchAll(); + foreach($res as $post){ + $times = substr_count($post["reports"], ","); + $times = $times==1?"1 time":"$times times"; + echo "

Post ".$post["post_id"]." has been reported $times

"; + } + if(count($res)==0){ + echo "

Nothing has been reported.

"; + } + ?> +
+
+

ADMIN ACTIONS

+

Ban a user

+

Unban a user

+ Error reports

"; + echo "

Manage admins

"; + echo "

Site visitors

"; + echo "

Edit classes

"; + } + ?> +
+
+ + \ No newline at end of file diff --git a/admin/portal/manage.php b/admin/portal/manage.php new file mode 100644 index 0000000..d21e23c --- /dev/null +++ b/admin/portal/manage.php @@ -0,0 +1,88 @@ +name) != ""){ + $person = $_POST["person"]; + unset($_POST); + conn(); + $stmt = $conn->prepare("UPDATE users SET special='admin' WHERE id=:id"); + $stmt->bindParam(":id", $person); + $stmt->execute(); + if($stmt){ + $user = getUserInfo($person)->name; + msg("$user added as admin"); + header("Location: /admin/portal/manage.php"); + } + }else if(isset($_POST["person"]) && strval(getUserInfo($_POST["person"])->name) == ""){ + unset($_POST); + msg("User doesn't exist"); + header("Location: /admin/portal/manage.php"); + } + + //Deleting admins + if(isset($_GET["delUser"])){ + conn(); + $person = $_GET["delUser"]; + $stmt = $conn->prepare("SELECT special FROM users WHERE id=:id"); + $stmt->bindParam(":id", $person); + $stmt->execute(); + $res = $stmt->fetch(PDO::FETCH_ASSOC); + if($res["special"]=="admin"){ + $person = $_GET["delUser"]; + $stmt = $conn->prepare("UPDATE users SET special=null WHERE id=:id"); + $stmt->bindParam(":id", $person); + $stmt->execute(); + if($stmt){ + $person = getUserInfo($person)->name; + msg("$person's admin rights have been revoked"); + header("Location: /admin/portal/manage.php"); + }else{ + msg("Error revoking $person's admin rights"); + reportError("Error revoking admin rights from $person in /admin/portal/manage.php"); + header("Location: /admin/portal/manage.php"); + } + }else{ + msg("That person is not an admin"); + header("Location: /admin/portal/manage.php"); + } + } +?> + + + + + +
+
+

ADD ADMIN

+
+ + +
+
+
+
+

REMOVE ADMIN

+

prepare("SELECT * FROM users WHERE special='admin'"); + $stmt->execute(); + $row = $stmt->fetchAll(); + if(sizeof($row)==0){ + echo "No admins."; + } + foreach($row as $person){ + echo "".$person["name"]."
"; + } + ?>

+
+
+ + \ No newline at end of file diff --git a/admin/portal/post.css b/admin/portal/post.css new file mode 100644 index 0000000..40f57f3 --- /dev/null +++ b/admin/portal/post.css @@ -0,0 +1,126 @@ +/* ------------- Global post ------------- */ +.container{ + width: 60%; + margin: 2% auto 0 auto; + color: #333; + background-color: white; + margin-bottom: 2em; + border-radius: 0.2em; + padding: 1em 2em; + line-height: 1.3em; +} +.container>*{ + border-radius: 0.3em; +} +/* General forum stuff */ +.forumLink{ + text-decoration: none; +} + + +/* ------------- Post ------------- */ +/* Title, username, time posted */ +.title>h2{ + margin: 0.5em 0; + line-height: 1.2em; +} +.info>*{ + font-size: 0.75em; + color: #aaa; + margin: 0; + display: inline-block; +} +.userlink:hover, .postType:hover{ + text-decoration: underline; +} +.postType{ + color: #888; + font-weight: bold; + margin: 0 0.5em 0 0.2em; +} +/* Text and image */ +.content>p{ + margin: 0; +} +.forum.card{ + margin-bottom: 1em; +} +.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 ~ .toggleView{ + display: none; +} + +/* Fixing tag-padding issue +.tags>p{ + padding: 0em 0.5em; +}*/ +/* Reporting and saving */ +.postBottom{ + display: block; + height: 1.5em; + font-size: 1em; + padding: 0 1em; + display: grid; + align-content: center; + grid-template-columns: 1fr 1fr; +} +.postReport, .postActions{ + margin: 0; + font-size: 0.8em; + color: #999; +} +.postReport{ + color: #922; + text-decoration: none; +} +.postActions>a{ + color: #888; + text-decoration: none; +} +.postActions>a:hover,.postReport:hover{ + text-decoration: underline; +} +.postSave{ + color: inherit; + text-decoration: none; + float: right; +} +.postSave>*{ + float: right; +} \ No newline at end of file diff --git a/admin/portal/reportedPost.php b/admin/portal/reportedPost.php new file mode 100644 index 0000000..71ec014 --- /dev/null +++ b/admin/portal/reportedPost.php @@ -0,0 +1,86 @@ +poster_id; + $title = $post->title; + $content = decodeUserLink($post->content); + $section = $post->section=="math"?"HL Math":ucwords($post->section); + $section = $post->section=="none"?"":ucwords($post->section); + $type = $post->type=="other"?"":strtolower($post->type); + $type = $section==""?ucwords($type):$type; + $section = $section==$type?"No topic":$section; + $date = $post->date; + $images = $post->image; + $poster = getUserInfo($poster_id)->name; + + //Clearing post of reports + if($_GET["clearPost"]){ + $stmt = $conn->prepare("UPDATE forums SET reports=null WHERE post_id=:id"); + $stmt->bindParam(":id", $_GET["post"]); + $stmt->execute(); + if($stmt){ + msg("Post cleared of all reports"); + header("Location: /forum/post/?post=".$_GET["post"]); + } + } +?> + + + + + + +
+

What should happen to the below post?

+

Should this post be >deleted or >cleared of reports?

+
+ +
+
+
+
+

+

Posted by

+
+
+

+
+
+

+ + + + "; + foreach(explode(",", substr($images, 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 ""; + // + }else if(in_array($exType, $imgFiles)){ + echo ""; + } + } + } + ?> +

+
+
+
+
+ + \ No newline at end of file diff --git a/admin/portal/siteVisitors.php b/admin/portal/siteVisitors.php new file mode 100644 index 0000000..5176d3d --- /dev/null +++ b/admin/portal/siteVisitors.php @@ -0,0 +1,32 @@ + + + + + + +
+
+

USERS:

+ prepare("SELECT name FROM users WHERE id <> '51155'"); + $stmt->execute(); + $res = $stmt->fetchAll(); + foreach($res as $person){ + $person = getUserInfoByName($person[0]); + $name = $person->name; + $id = $person->id; + echo "

$name

"; + } + ?> +
+ + \ No newline at end of file diff --git a/admin/portal/unbanUser.php b/admin/portal/unbanUser.php new file mode 100644 index 0000000..9121edc --- /dev/null +++ b/admin/portal/unbanUser.php @@ -0,0 +1,61 @@ +prepare("SELECT special FROM users WHERE id=:id"); + $stmt->bindParam(":id", $person); + $stmt->execute(); + $res = $stmt->fetch(PDO::FETCH_ASSOC); + if($res["special"]=="banned"){ + $person = $_GET["user"]; + $stmt = $conn->prepare("UPDATE users SET special=null, ban_reason=null WHERE id=:id"); + $stmt->bindParam(":id", $person); + $stmt->execute(); + if($stmt){ + $person = getUserInfo($person)->name; + msg("$person has been unbanned"); + header("Location: /admin/portal/unbanUser.php"); + }else{ + msg("Error unbanning $person"); + reportError("Error unbanning $person in /admin/portal/manage.php"); + header("Location: /admin/portal/unbanUser.php"); + } + }else{ + msg("$person was never banned"); + header("Location: /admin/portal/unbanUser.php"); + } + } +?> + + + + + +
+
+

UNBAN USER

+

prepare("SELECT * FROM users WHERE special='banned'"); + $stmt->execute(); + $row = $stmt->fetchAll(); + if(sizeof($row)==0){ + echo "No banned users :D"; + } + foreach($row as $person){ + echo "".$person["name"]."
"; + } + ?>

+
+
+ + \ No newline at end of file diff --git a/comments.css b/comments.css new file mode 100644 index 0000000..ee0c9d8 --- /dev/null +++ b/comments.css @@ -0,0 +1,130 @@ +/* ------------- Comments ------------- */ +#comments{ + padding-bottom: 1em; +} +#commentWriter{ + width: 90%; + margin: 0 auto; + min-height: 6em; + border: 1px solid #ddd; + border-radius: 0.3em; + background-color: #f8f8f8; + resize: none; + color: black; + position: relative; +} +/* Actual part to write the comment */ +#commentEditor{ + padding: 0.5em; + min-height: 3em; + margin-bottom: 2em; +} +#commentEditor:empty:before{ + content: attr(placeholder); + color: #555; +} +#commentEditor:focus{ + outline-width: 0; +} +/* Submit buttons etc. */ +#commentWriterButtons{ + position: absolute; + background-color: #f2f2f2; + width: 100%; + height: 2em; + bottom: 0; +} +#rulesReminder{ + margin: calc((2em - (1em - 0.8em)) / 2) 0.3em; + font-size: 0.8em; + color: gray; +} +#rulesReminder>a{ + color: gray; +} +#commentSubmitWrapper{ + position: absolute; + right: 0; + height: 100%; +} +#commentSubmitWrapper>p{ + display: inline; +} +#commentSubmitWrapper>button{ + height: 100%; + border: none; + padding: 0 1em; + background-color: #e5e5e5; +} +#commentSubmitWrapper>button:hover{ + cursor: pointer; + /* Shouldn't this be default? */ +} + +/* ------------- Submitted comments -------------*/ +.comment{ + width: 90%; + margin: 3em auto 0 auto; +} +.commentTop{ + margin: 0.5em 0; +} +.commentTop>p{ + display: inline; + width: 100%; +} +.commentTop>p>i{ + color: #444; + margin: 0 0.2em; +} +.commentName{ + color: black; + font-weight: bold; + text-decoration: none; +} +.commentName:hover{ + text-decoration: underline; +} +.commentTime{ + color: gray; + font-size: 0.8em; +} + +.commentMiddle{ + font-size: 0.99em; + overflow: hidden; +} + +.commentBottom{ + display: block; + height: 1em; +} +.commentReply{ + color: #00d09f; + text-decoration: none; + float: right; + margin-right: 1em; +} +.commentReport{ + font-size: 0.8em; +} +.commentReport, .commentReport>a{ + float: left; + margin: 0.5em 0 0 0; + text-decoration: none; + color: #999; +} +.commentReport:hover, .commentReport>a:hover{ + text-decoration: underline; +} +/*Highlighting if user go there by @mentions*/ +.current{ + background-color: white; + animation: mention; + animation-duration: 900ms; +} +@keyframes mention { + 10% {background-color: white;} + 50% {background-color: #fcff79;} + 100% {background-color: white;} +} \ No newline at end of file diff --git a/darkTheme.css b/darkTheme.css new file mode 100644 index 0000000..34339cb --- /dev/null +++ b/darkTheme.css @@ -0,0 +1,80 @@ +/* + The use of !important is out of sheer laziness. To fix, just create two css + documents, one for light theme and one for dark. Until then, this will have to + work. +*/ + +body{ + background-color: #090909 !important; + color: #ccc !important; +} +#leftMobile{ + background-color: #090909 !important; +} +.hamburger{ + filter: invert(25%) !important; +} +#topMobile{ + background-color: #090909 !important; +} +msg{ + background-color: #0d0d0d !important; + color: #bcbcbc !important; + border: 1px solid #242424 !important; +} + +#top, #topMobile, #userTopWrapper{ + background-color: #090909 !important; + box-shadow: none !important; + border-bottom: 1px solid #242424 !important; +} +input[type=text]{ + border: 0 !important; + border-bottom: 1px solid #ccc !important; + background-color: transparent; + color: #bcbcbc; +} +#searchBar, #searchBarMobile, textarea, #postEditor{ + background-color: #1a1919 !important; + border: 0 !important; + color: #bcbcbc; +} +#addPost:hover, #addPostMobile:hover{ + background-color: #1a1919 !important; +} + +#postEditor{ + border-radius: 0 !important; +} +.userTopSel{ + color: inherit !important; +} + +#commentWriter{ + border: 1px solid #626262 !important; + color: inherit !important; +} +#commentWriterButtons, #commentEditor{ + background-color: #0b0b0b !important; +} +#commentSubmitButton{ + background-color: #111 !important; +} + +.card{ + background-color: #0b0b0b !important; + color: #bcbcbc !important; + box-shadow: none !important; +} +.card:hover:not(.noShadow):not(.noHover){ + box-shadow: none !important; + border: 1px solid #626262 !important; +} +.card:not(.noShadow){ + border: 1px solid #242424 !important; + box-shadow: none !important; +} + +button[type="submit"]:not(#commentSubmitButton){ + background-color: #111; +} \ No newline at end of file diff --git a/deletedContent/51155/Lvk0Fb/7XJegk.jpg b/deletedContent/51155/Lvk0Fb/7XJegk.jpg new file mode 100644 index 0000000..ab823a0 Binary files /dev/null and b/deletedContent/51155/Lvk0Fb/7XJegk.jpg differ diff --git a/forum/foo.php b/forum/foo.php new file mode 100644 index 0000000..a13c9b9 --- /dev/null +++ b/forum/foo.php @@ -0,0 +1,51 @@ +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){ + msg("Error fooing posts :("); + header("Location: /forum"); + } + + } + msg("Success fooing posts :D"); + header("Location: /forum") +?> \ No newline at end of file diff --git a/forum/images/7Lb0k3.docx b/forum/images/7Lb0k3.docx new file mode 100644 index 0000000..c6c0f1f Binary files /dev/null and b/forum/images/7Lb0k3.docx differ diff --git a/forum/images/EeaU8c.docx b/forum/images/EeaU8c.docx new file mode 100644 index 0000000..ea1d546 Binary files /dev/null and b/forum/images/EeaU8c.docx differ diff --git a/forum/images/JkocQZ.docx b/forum/images/JkocQZ.docx new file mode 100644 index 0000000..6c5d4e3 Binary files /dev/null and b/forum/images/JkocQZ.docx differ diff --git a/forum/images/LvHBpe.docx b/forum/images/LvHBpe.docx new file mode 100644 index 0000000..5949d6b Binary files /dev/null and b/forum/images/LvHBpe.docx differ diff --git a/forum/images/OFCtQg.docx b/forum/images/OFCtQg.docx new file mode 100644 index 0000000..001b57c Binary files /dev/null and b/forum/images/OFCtQg.docx differ diff --git a/forum/images/R1GF5H.docx b/forum/images/R1GF5H.docx new file mode 100644 index 0000000..52ab2a3 Binary files /dev/null and b/forum/images/R1GF5H.docx differ diff --git a/forum/images/TOFPvl.docx b/forum/images/TOFPvl.docx new file mode 100644 index 0000000..83c7b36 Binary files /dev/null and b/forum/images/TOFPvl.docx differ diff --git a/forum/images/rQZFd.pdf b/forum/images/rQZFd.pdf new file mode 100644 index 0000000..e54aba6 Binary files /dev/null and b/forum/images/rQZFd.pdf differ diff --git a/forum/index.php b/forum/index.php new file mode 100644 index 0000000..5bb2647 --- /dev/null +++ b/forum/index.php @@ -0,0 +1,41 @@ + + + + + + +
+ +
+ 0?$_GET["page"]:1; + $start = $limit * ($page - 1); + $stmt = $conn->prepare("SELECT * FROM forums ORDER BY date DESC LIMIT $start,$limit"); + $stmt->execute(); + foreach($stmt->fetchAll() as $post){ + makePost($post); + } + + //checking if there would be results on the next page + $row = $start+$limit; + $stmt = $conn->prepare("SELECT * FROM forums ORDER BY date DESC LIMIT $row,1"); + $stmt->execute(); + $moreResults = $stmt->rowCount(); + ?> +
+
":"
"; + echo $moreResults?"":"
"; + ?> +
+
+ +
+ + \ No newline at end of file diff --git a/forum/post/index.php b/forum/post/index.php new file mode 100644 index 0000000..dac60b8 --- /dev/null +++ b/forum/post/index.php @@ -0,0 +1,216 @@ +prepare("SELECT * FROM comments WHERE id = :cid"); + $getcstmt->bindParam(":cid", $_GET["delc"]); + $getcstmt->execute(); + $comment = $getcstmt->fetch(PDO::FETCH_ASSOC); + //Putting comment into "deleted" datebase + $mcstmt = $conn->prepare("INSERT INTO deletedComments (post_id, poster_id, date, text, reports) VALUES (:post, :pstr, :date, :text, :rpts)"); + $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(); + //Removing the comment from the normal database + $cstmt = $conn->prepare("DELETE FROM comments WHERE id = :cid"); + $cstmt->bindParam(":cid", $_GET["delc"]); + $cstmt->execute(); + //Giving feedback and redirecting + if(!$mcstmt || !$cstmt){ + reportError("A comment couldn't be deleted in /forum/post/index.php"); + msg("Couldn't delete comment. It has been reported for you"); + }else{ + msg("Comment deleted"); + } + header("Location: /forum/post/?post=".$_GET["post"]); + } + //reporting comment + if(isset($_GET["repc"])){ + $stmt = $conn->prepare("SELECT * FROM comments WHERE id = :id"); + $id = $_GET["repc"]; + $stmt->bindParam(":id", $id); + $stmt->execute(); + $delc = $stmt->fetch(PDO::FETCH_OBJ); + $rep = $delc->reports; + if(strContains($rep, $current_user)){ + $prevRep = true; + }else{ + $prevRep = false; + $rep .= $current_user.","; + } + $stmt = $conn->prepare("UPDATE comments SET reports = :rep WHERE id = :id"); + $id = $_GET["repc"]; + $stmt->bindParam(":id", $id); + $stmt->bindParam(":rep", $rep); + $stmt->execute(); + if($stmt){ + msg($prevRep==true?"You already reported that comment.":"Comment reported"); + header("Location: /forum/post/?post=".$_GET["post"]); + }else{ + reportError("Error reporting comment in /forum/post/index.php - a"); + msg("Error reporting comment. This error has been reported."); + header("Location: /forum/post/?post=".$_GET["post"]); + } + } + + //Getting and storing the post info to echo later + $post = getPostInfo($_GET["post"]); + $poster_id = $post->poster_id; + $title = $post->title; + $content = hyperlink($post->content); + $content = decodeUserLink($post->content); + $section = $post->section=="none"?"":ucwords(str_replace("_", " ", $post->section)); + $type = $post->type=="other"?"":strtolower($post->type); + $type = $section==""?ucwords($type):$type; + $section = $section==$type?"No topic":$section; + $date = $post->date; + $images = $post->image; + $poster = getUserInfo($poster_id)->name; + + //Checking if the user has this post bookmarked for un/bookmarking + $stmt = $conn->prepare("SELECT * FROM bookmarks WHERE post_id = :pid AND user_id = :uid"); + $stmt->bindParam(":pid", $_GET["post"]); + $stmt->bindParam(":uid", $current_user); + $stmt->execute(); + $res = $stmt->fetch(PDO::FETCH_OBJ); + $bk = $res->user_id==$current_user?true:false; + + //Bookmarking the post + if(isset($_GET["bkmk"]) && $_GET["bkmk"] =="t" && !$bk){ + $stmt = $conn->prepare("INSERT INTO bookmarks (post_id, user_id) VALUES (:pid, :uid)"); + $stmt->bindParam(":pid", $_GET["post"]); + $stmt->bindParam(":uid", $current_user); + $stmt->execute(); + if($stmt){ + msg("Post saved. You can find it on your account page."); + header("Location: /forum/post/?post=".$_GET["post"]); + }else{ + reportError("Error while saving post in /forum/post/index.php - b"); + msg("Error! It has been reported automatically."); + header("Location: /forum/post/?post=".$_GET["post"]); + } + } + + //Unbookmarking the post + if(isset($_GET["bkmk"]) && $_GET["bkmk"] =="f"&&$bk){ + $stmt = $conn->prepare("DELETE FROM bookmarks WHERE post_id = :pid AND user_id = :uid"); + $stmt->bindParam(":pid", $_GET["post"]); + $stmt->bindParam(":uid", $current_user); + $stmt->execute(); + if($stmt){ + msg("Post unsaved."); + header("Location: /forum/post/?post=".$_GET["post"]); + }else{ + reportError("Error unsaving post in /forum/post/index.php - c"); + msg("Error! It has already been reported for you."); + header("Location: /forum/post/?post=".$_GET["post"]); + } + } + + //Checking if the user has this post bookmarked + $stmt = $conn->prepare("SELECT * FROM bookmarks WHERE post_id = :pid AND user_id = :uid"); + $stmt->bindParam(":pid", $_GET["post"]); + $stmt->bindParam(":uid", $current_user); + $stmt->execute(); + $res = $stmt->fetch(PDO::FETCH_OBJ); + $bk = $res->user_id==$current_user?true:false; + + //Reporting the post + if(isset($_GET["reportPost"])){ + $post = getPostInfo($_GET["post"]); + $current = $post->reports; + if(strpos($current, $current_user) === false){ + $new = $current.$current_user.","; + $stmt = $conn->prepare("UPDATE forums SET reports = :new WHERE post_id = :id"); + $stmt->bindParam(":new", $new); + $stmt->bindParam(":id", $post->post_id); + $stmt->execute(); + if($stmt){ + msg("Post reported."); + header("Location: /forum/post/?post=".$_GET["post"]); + }else{ + reportError("Error reporting post in /forum/post/index.php - d"); + msg("Error reporting post. This error has been reported."); + header("Location: /forum/post/?post=".$_GET["post"]); + } + }else{ + msg("You already reported this post."); + header("Location: /forum/post/?post=".$_GET["post"]); + } + } +?> + + + + + +
+
+
+
+

+

Posted by

+
+
+

+
+
+

+ + + + "; + foreach(explode(",", substr($images, 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 ""; + // + }else if(in_array($exType, $imgFiles)){ + echo ""; + } + } + } + ?> +

+
+
+
+
+ id == $current_user){ + $datediff = time() - strtotime($date); + $mins = round($datediff / (60)); + if($mins <= 5){ + $editable = " | edit"; + } + echo " +

delete$editable

"; + }else{ + echo "

report

"; + } + ?> + &bkmk=> +
+
+ + + + + \ No newline at end of file diff --git a/forum/post/post.css b/forum/post/post.css new file mode 100644 index 0000000..40f57f3 --- /dev/null +++ b/forum/post/post.css @@ -0,0 +1,126 @@ +/* ------------- Global post ------------- */ +.container{ + width: 60%; + margin: 2% auto 0 auto; + color: #333; + background-color: white; + margin-bottom: 2em; + border-radius: 0.2em; + padding: 1em 2em; + line-height: 1.3em; +} +.container>*{ + border-radius: 0.3em; +} +/* General forum stuff */ +.forumLink{ + text-decoration: none; +} + + +/* ------------- Post ------------- */ +/* Title, username, time posted */ +.title>h2{ + margin: 0.5em 0; + line-height: 1.2em; +} +.info>*{ + font-size: 0.75em; + color: #aaa; + margin: 0; + display: inline-block; +} +.userlink:hover, .postType:hover{ + text-decoration: underline; +} +.postType{ + color: #888; + font-weight: bold; + margin: 0 0.5em 0 0.2em; +} +/* Text and image */ +.content>p{ + margin: 0; +} +.forum.card{ + margin-bottom: 1em; +} +.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 ~ .toggleView{ + display: none; +} + +/* Fixing tag-padding issue +.tags>p{ + padding: 0em 0.5em; +}*/ +/* Reporting and saving */ +.postBottom{ + display: block; + height: 1.5em; + font-size: 1em; + padding: 0 1em; + display: grid; + align-content: center; + grid-template-columns: 1fr 1fr; +} +.postReport, .postActions{ + margin: 0; + font-size: 0.8em; + color: #999; +} +.postReport{ + color: #922; + text-decoration: none; +} +.postActions>a{ + color: #888; + text-decoration: none; +} +.postActions>a:hover,.postReport:hover{ + text-decoration: underline; +} +.postSave{ + color: inherit; + text-decoration: none; + float: right; +} +.postSave>*{ + float: right; +} \ No newline at end of file diff --git a/globalFuncs.php b/globalFuncs.php new file mode 100644 index 0000000..532319d --- /dev/null +++ b/globalFuncs.php @@ -0,0 +1,405 @@ + 10){ + reportError("Level $n error: $m in file \"$f\" on line $l"); + } + } + set_error_handler('errorHandler'); + + //msg handling (msg delivered in /res/top) + if(isset($_COOKIE["IB_MSG"])){ + $msg = $_COOKIE["IB_MSG"]; + setcookie("IB_MSG", $_COOKIE["IB_MSG"], $_SERVER['REQUEST_TIME']-3600, "/"); + }else{ + $msg = NULL; + } + + require "conn.php"; + //conn.php used to be part of this file, but I don't want to accidentally upload it to github + + //Verifying user with cookie + if(isset($_COOKIE["IB_SESSION"])){ + $cookie = $_COOKIE["IB_SESSION"]; + conn(); + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM login_tokens WHERE user_id = :id"); + $stmt->bindParam(":id", $_COOKIE["IB_ID"]); + $stmt->execute(); + $row = $stmt->fetchAll(); + $GLOBALS["verified"] = $verified = false; + for($i=0; $iprepare("SELECT * FROM users WHERE id = :id"); + $id = strval($id); //Just making sure + $stmt->bindParam(":id", $id); + $stmt->execute(); + $result = $stmt->fetch(PDO::FETCH_OBJ); + if($result==NULL){ + return false; + }else{ + return $result; + } + } + + function getUserInfoByName($name){ + conn(); + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM users WHERE name = :name"); + $stmt->bindParam(":name", $name); + $stmt->execute(); + $result = $stmt->fetch(PDO::FETCH_OBJ); + if($result==NULL){ + return false; + }else{ + return $result; + } + } + + //Making sure that the user isn't banned + if(getUserInfo($current_user)->special == "banned" && $GLOBALS["page"] != "banned"){ + header("Location: /user/banned.php"); + } + + function strContains($haystack, $needle){ + if(strpos($haystack, $needle)!==false){ + return true; + }else{ + return false; + } + } + + function verifyID($pid){ + conn(); + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM forums WHERE post_id = :pid"); + $stmt->bindParam(":pid", $pid); + $stmt->execute(); + $forums = $stmt->fetch(PDO::FETCH_OBJ)->post_id; + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM forums WHERE image = :pid"); + $stmt->bindParam(":pid", $pid); + $stmt->execute(); + $images = $stmt->fetch(PDO::FETCH_OBJ)->image; + return ($forums!=NULL||$images!=NULL)?false:true; + } + + function randID($length = 7) { + do{ + if(function_exists("random_bytes")){ + $bytes = random_bytes(ceil($length/2)); + }elseif(function_exists("openssl_random_pseudo_bytes")){ + $bytes = openssl_random_pseudo_bytes(ceil($length/2)); + }else{ + throw new Exception("No cryptographically secure random function available."); + } + $x = substr(bin2hex($bytes), 0, $length); + $id = gmp_strval(gmp_init($x, 36), 62); + } while(!verifyID($id)); + return $id; + } + + function makeDate($date){ + $date = strtotime($date); + $now = $_SERVER['REQUEST_TIME']; + $datediff = $now - $date; + $secs = round($datediff); + $mins = round($datediff / (60)); + $hours = round($datediff / (60 * 60)); + $days = round($datediff / (60 * 60 * 24)); + + if($secs<60){ + if($secs == 1){ + $date = $secs." second ago"; + }else{ + $date = $secs." seconds ago"; + } + }else if($mins<60){ + if($mins == 1){ + $date = $mins." minute ago"; + }else{ + $date = $mins." minutes ago"; + } + }else if($days<1){ + if($hours == 1){ + $date = $hours." hour ago"; + }else{ + $date = $hours." hours ago"; + } + }else if($days < 8){ + if($days == 1){ + $date = " yesterday"; + }else{ + $date = $days." days ago"; + } + }else{ + $date = date("M j", $date); + } + + return $date; + } + + function verifyUser($level, $id = NULL){ + if($id == NULL){ + $id = $GLOBALS["current_user"] ; + } + + $oldLevel = $level; + + switch($level){ + case "admin": + $level = 1; + break; + case "owner"; + $level = 2; + break; + default: + $level = 0; + break; + } + + conn(); + $stmt = $GLOBALS['conn']->prepare("SELECT special FROM users WHERE id = :id"); + $stmt->bindParam(":id", $id); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_OBJ); + $extra = $row->special; + + switch($extra){ + case "admin": + $userLevel = 1; + break; + case "owner": + $userLevel = 2; + break; + default: + $userLevel = 0; + } + + if($userLevel>=$level){ + echo "\n"; + return true; + }else{ + return false; + } + } + + function restrictAccess($level){ + if(!verifyUser($level)){ + $current_user = $GLOBALS["current_user"]; + msg("You don't have access to that file"); + $username = getUserInfo($current_user)->name; + $file = getcwd()."/".basename(__FILE__); + reportError("User $current_user ($username) tried to access $file"); + header("Location: /"); + } + } + + function alertDelete($id){ + conn(); + $stmt = $GLOBALS['conn']->prepare("DELETE FROM alerts WHERE id = :id"); + $stmt->bindValue(":id", $id); + $stmt->execute(); + if(!$stmt){ + reportError("Error in globalFuncs:alertDelete - stmt failed"); + msg("Error removing mention from sidebar. This has been reported for you."); + } + } + + function alertInsert($er, $ee, $id){ + if($er == NULL){ + $er = $GLOBALS["current_user"]; + } + conn(); + $stmt = $GLOBALS['conn']->prepare("SELECT id FROM comments ORDER BY id DESC LIMIT 1"); + $stmt->execute(); + $result = $stmt->fetch(PDO::FETCH_OBJ); + $maxID = intval($result->id); + $maxID++; + + $stmt = $GLOBALS['conn']->prepare("INSERT INTO alerts (id, mentioner, mentionee, post_id) VALUES (:mid, :er, :ee, :id)"); + $stmt->bindValue(":mid", $maxID); + $stmt->bindValue(":er", $er); + $stmt->bindValue(":ee", $ee); + $stmt->bindValue(":id", $id); + $stmt->execute(); + if(!$stmt){ + reportError("Issue in globalFuncs:alertInsert - stmt failed"); + msg("Error in the mention system - ".getUserInfo($ee)->name." could not be alerted to your mention."); + } + } + + function hyperSearch($text){ + preg_match_all("#((((-|_){0,}\w)+\.([a-zA-Z]+){2,})|((((http)|(https)):\/\/){1}((-|_){0,}\w)+\.([a-zA-Z]+){2,}))((\w+|-|_|\/|\.)+){0,}#", $text, $match); + if($match[0]==NULL){ + return false; + }else{ + return $match[0]; + } + } + + function hyperlink($text){ + $link = hyperSearch($text); + if($link != false){ + foreach($link as $link){ + $content = "".$link.""; + $text = str_replace($link, $content, $text); + } + } + return $text; + } + + function linkSearch($text){ + if(strContains($text, "@")){ + preg_match_all("#(?<=@)(.?)(?:[\w\-_])+#", $text, $match); + return $match[0]; + }else{ + return false; + } + } + + function encodeUserLink($info, $er = NULL, $id = NULL){ + // Searching for user links + $link = linkSearch($info); + if($link != false){ + $link = array_filter($link); + foreach($link as $thing){ + $user = getUserInfoByName(strval($thing)); + if($user!=false){ + $info = str_replace($thing, $user->id, $info); + //For the mention (alert) system + alertInsert($er, $user->id, $id); + }else if(getUserInfo($thing) != false){ + //For the mention (alert) system + alertInsert($er, $thing, $id); + } + } + } + return $info; + } + + function decodeUserLink($info){ + $link = linkSearch($info); + if($link != false){ + $link = array_filter($link); + foreach($link as $thing){ + $user = getUserInfo(strval($thing)); + if($user!=false){ + $content = "id.">".$user->name.""; + $info = str_replace($thing, $content, $info); + }else if(!$user && getUserInfoByName(strval($thing))!=false){ + $user = getUserInfoByName(strval($thing)); + $content = "id.">".$user->name.""; + $info = str_replace($thing, $content, $info); + } + } + } + return $info; + } + + function decodeUserNoLink($info){ + $link = linkSearch($info); + if($link != false){ + $link = array_filter($link); + foreach($link as $thing){ + $user = getUserInfo(strval($thing)); + if($user!=false){ + $content = $user->name; + $info = str_replace($thing, $content, $info); + }else if(!$user && getUserInfoByName(strval($thing))!=false){ + $user = getUserInfoByName(strval($thing)); + $content = $user->name; + $info = str_replace($thing, $content, $info); + } + } + } + return $info; + } + + function reportError($issue){ + $reporter = $_COOKIE["IB_ID"]; + $stmt = $GLOBALS['conn']->prepare("INSERT INTO issue_tracker (reporter, comment, auto) VALUES (:reporter, :issue, :auto)"); + $stmt->bindValue(":reporter", $reporter); + $stmt->bindValue(":issue", $issue); + $stmt->bindValue(":auto", true); + $result = $stmt->execute(); + } + + function msg($text){ + // msg is "delivered" in /res/top + setcookie("IB_MSG", $text, $_SERVER['REQUEST_TIME'] + 60, "/", NULL, true, true); + } + + function getPostInfo($post){ + conn(); + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM forums WHERE post_id = :id"); + $stmt->bindParam(":id", $post); + $stmt->execute(); + return $stmt->fetch(PDO::FETCH_OBJ); + } + + function makePost($post){ + if(gettype($post)=="object"){ + //converting object into array if needed, so it can be used here + $post = json_decode(json_encode($post), True); + } + //$img = $post["image"]==NULL?"":""; + //setting some defaults + $img = $clp = $imgClass = NULL; + + $file = substr($post["image"], 0, strpos($post["image"], ",")); + $exType = substr($file, strpos($file, '.')+1); + $docFiles = ["doc", "docx", "pdf"]; + $imgFiles = ["jpg", "jpeg", "png"]; + //image stuff + if(in_array($exType, $docFiles)){ + $clp = ""; + }else if(in_array($exType, $imgFiles)){ + $img = ""; + $imgClass = " image"; + } + + + $ellipsisT = strlen($post["title"])>75?"...":""; + $ellipsisC = strlen($post["content"])>400?"...":""; + $section = $post["section"]=="none"?"":ucwords($post["section"]); + $type = $post["type"]=="other"?"":strtolower($post["type"]); + $type = $section==""?ucwords($type):$type; + $section = $section==$type?"No topic":$section; + + echo "\n +
+
+
+

".$section." ".$type."

+

Posted ".makeDate($post["date"])." by ".getUserInfo($post["poster_id"])->name."

+
+
+

".substr($post["title"], 0, 75).$ellipsisT.$clp."

+
+
+

".decodeUserNoLink(substr(strip_tags($post["content"]), 0, 400)).$ellipsisC."

+
+
+
+ ".$img." +
+
+
"; + } +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..cf830af --- /dev/null +++ b/index.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/mobile.css b/mobile.css new file mode 100644 index 0000000..fa01629 --- /dev/null +++ b/mobile.css @@ -0,0 +1,202 @@ +/* ---------- Mobile CSS ---------- */ +/** + * + * The method used to move elements is to use a media query to hide the element, + * and another media query to show one. This is basically a toggle. + * +**/ +.mobileOnly{ + display: none; +} + +@media (max-width: 1000px){ + .mobileOnly{ + display: block !important; + width: 90vw; + margin: 1em auto !important; + } + #monoContainer{ + margin-top: 3em; + } + #container{ + margin-top: 5vw !important; + display: block; + width: 100%; + } + #container.keepRight{ + display: grid !important; + } + #container>#left{ + width: 90vw; + margin-left: auto; + margin-right: auto; + } + #right{ + display: none; + } + .keepRight>#right{ + display: block; + } + #results, #monoContainer{ + width: 85vw !important; + margin-left: auto; + margin-right: auto; + } + .card{ + margin-bottom: 1em; + } + + + #top{ + display: none; + } + #topMobile{ + display: grid; + grid-template-columns: 1fr 3fr 1fr; + width: 100%; + text-align: center; + height: 2.1em; + align-items:center; + padding: 2% 0; + margin: 0 auto; + background-color: white; + position: fixed; + top: 0; + z-index: 2; + box-shadow: 0 1px 2px #ddd; + text-align: center; + align-items: middle; + } + #topMobile>a{ + margin-left: auto; + margin-right: auto; + } + #logoMobile{ + height: 2em; + } + .hamburger{ + width: 2em; + filter: opacity(0.7); + } + .hamburger:hover{ + cursor: pointer; + } + /*Actual checkbox toggle*/ + #hamCheck{ + display: none; + } + #hamCheck:checked ~ p{ + color: red; + } + + #leftMobile{ + position: fixed; + top: 0; + left: -82vw; + z-index: 999; + padding-top: 5vh; + background-color: white; + width: 80vw; + height: 100vh; + align-items: middle; + text-align: center; + box-shadow: 1px 0 2px #ddd; + transition-duration: 100ms; + overflow-y: auto; + } + #hamCheck:checked ~ #leftMobile{ + left: 0; + } + #hamCheck:checked ~ #leftMobile>label>#hamburgerInLeft{ + display: block; + position: fixed; + left: calc(80vw - 2.6em); + top: 4vh; + filter: opacity(0.6); + transition: 200ms; + } + #leftMobile>#right>.card{ + box-shadow: none; + padding: 0.5em; + width: 70%; + margin: 0 auto; + } + #leftMobile>#right>.card:last-of-type{ + margin-bottom: 100px; + } + #accountMobile{ + border-radius: 50%; + width: 35%; + } + #searchMobile{ + width: calc(70% - 20px); + margin: 0 auto; + color: #444; + } + #searchBarMobile{ + width: 95%; + font-size: 1em; + background-color: #f4f4f4; + border: 0; + padding: 5px 10px; + border-radius: 0.3em; + } + #searchBarMobile::-webkit-input-placeholder { + color: #999 !important; + } + #searchBarMobile:-moz-placeholder { /* Firefox 18- */ + color: #999 !important; + } + #searchBarMobile::-moz-placeholder { /* Firefox 19+ */ + color: #999 !important; + } + #searchBarMobile:-ms-input-placeholder { + color: #999 !important; + } + #searchFormMobile{ + width: 100%; + } + /* Add post button */ + #addPostMobile{ + cursor: pointer; + margin: 1em auto; + border-radius: 0.3em; + width: 70%; + font-size: 1.2em; + } + #addPostMobile>a{ + color: #00d09f; + display: block; + text-decoration: none; + padding: 0.5em 1em; + } + #addPostMobile:hover{ + background-color: #f4f4f4; + } + + /* User page posts/saved thing */ + #userTopWrapper{ + box-shadow: 0 2px 3px #ddd !important; + top: 0.1em; + z-index: 3; + } + + /* For the /forum/post s */ + .container{ + margin: 5vh auto !important; + width: 90vw !important; + max-width: 100%; + padding: 0 !important; + } + #content>p>img{ + width: 100%; + } + #comments{ + padding-top: 1em; + } +} +@media (min-width: 1001px){ + .mobile{ + display: none; + } +} \ No newline at end of file diff --git a/post/common.css b/post/common.css new file mode 100644 index 0000000..5112b76 --- /dev/null +++ b/post/common.css @@ -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; + } +} \ No newline at end of file diff --git a/post/delete.php b/post/delete.php new file mode 100644 index 0000000..a64c0d1 --- /dev/null +++ b/post/delete.php @@ -0,0 +1,110 @@ +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"]); + } + } +?> \ No newline at end of file diff --git a/post/edit.php b/post/edit.php new file mode 100644 index 0000000..63b0352 --- /dev/null +++ b/post/edit.php @@ -0,0 +1,154 @@ +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))."\""; +?> + + + + + +
+
+ +
+
+ +
+
+
content?>
+ + +
+
+
+ + +
+ +
+
+ image != NULL){ + echo " + + "; + $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 ""; + // + }else if(in_array($exType, $imgFiles)){ + echo ""; + } + } + } + ?> + +
+
+

Subject

+ + "; + $num++; + } + ?> + > + + + + +

Post type

+ > + + + > + + + > + + + > + + + > + +
+
+ +
+

Rules:

+ + style="display:none;"> + +
+
+
+ + \ No newline at end of file diff --git a/post/index.php b/post/index.php new file mode 100644 index 0000000..f791428 --- /dev/null +++ b/post/index.php @@ -0,0 +1,74 @@ + + + + + + +
+
+ +
+
+ +
+
+
+ + +
+
+
+ + +
+ + +
+
+

Subject

+ + "; + $num++; + } + ?> + + +

Post type

+ + + + + +
+
+ +
+

Rules:

+ + +
+
+
+ + \ No newline at end of file diff --git a/post/submitEdit.php b/post/submitEdit.php new file mode 100644 index 0000000..3a1ff10 --- /dev/null +++ b/post/submitEdit.php @@ -0,0 +1,76 @@ +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; $iprepare("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"); + } +?> \ No newline at end of file diff --git a/post/submitPost.php b/post/submitPost.php new file mode 100644 index 0000000..12ffb1b --- /dev/null +++ b/post/submitPost.php @@ -0,0 +1,62 @@ +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"); + } +?> \ No newline at end of file diff --git a/report.css b/report.css new file mode 100644 index 0000000..bbdddeb --- /dev/null +++ b/report.css @@ -0,0 +1,57 @@ +html, body{ + height: calc(100% - 1em); + /* Allows the body content be centered vartically. + No idea why the "-1em" part matters, but it does and it works so don't touch it unless you're willing to see the bug through + */ +} +#updateCard{ + display: inline-block; + padding: 2em 4em; + margin: 0 auto 10% auto; + text-align: center; + width: 35%; +} +.question{ + font-size: 1.1em; + margin-top: 2em; + margin-bottom: 0.7em; +} +/* Something's wrong here */ +form>*{ + margin-left: auto; + margin-right: auto; +} +#instructions{ + width: 90%; + margin: 1em auto; +} +#another{ + color: #00d09f; + text-decoration: none; +} +#another:hover{ + text-decoration: underline; +} +button[type=submit]{ + font-size: 1em; + background-color: white; + color: #00d09f; + border: 1px solid #00d09f; + padding: 0.5em 1em; + margin-top: 2em; +} +h2{ + margin-top: 0; +} +textarea{ + outline-width: 0; + font-family: inherit; + font-size: 0.9em; + resize: none; + width: 90%; + border: 1px solid #bbb; + border-radius: 0.3em; + padding: 0.3em 0.5em; + color: #333; + font-size: 1em; +} \ No newline at end of file diff --git a/report.php b/report.php new file mode 100644 index 0000000..316ef2d --- /dev/null +++ b/report.php @@ -0,0 +1,45 @@ + + + + + + +
+
+ prepare("INSERT INTO issue_tracker (reporter, comment) VALUES (:reporter, :issue)"); + $stmt->bindParam(":issue", $issue); + $stmt->bindParam(":reporter", $reporter); + $result = $stmt->execute(); + + if($stmt){ + echo "

Thank You.
Your issue has been submitted and will be reviewed shortly.

Until it is resolved, please bear in mind that there is only one person who maintains this entire site, and he has the same amount of schoolwork as you do.
Thank you for being patient.


Need to submit another?"; + }else{ + echo "

There was an issue submitting your issue.

I'd tell you to report it, but that doesn't seem to be an option. Instead, please contact Luke Ogburn in person and tell him to fix this.

"; + } + }else{ + echo " +

Report Issue

+
+

Please explain the issue, and include anything you feel might be useful for me to know

+ + +
"; + } + ?> +
+
+ + \ No newline at end of file diff --git a/res/classes b/res/classes new file mode 100644 index 0000000..6c34da4 --- /dev/null +++ b/res/classes @@ -0,0 +1 @@ +biology,history,chemistry,english,world_language \ No newline at end of file diff --git a/res/commentSub.php b/res/commentSub.php new file mode 100644 index 0000000..da9e6c1 --- /dev/null +++ b/res/commentSub.php @@ -0,0 +1,16 @@ +prepare("INSERT INTO comments (post_id, poster_id, text) VALUES (:pid, :uid, :cmt)"); + $stmt->bindParam(":pid", $pid); + $stmt->bindParam(":uid", $uid); + $stmt->bindParam(":cmt", $cmt); + $result = $stmt->execute(); + + header("Location: /forum/post/?post=$pid#bottomOfComments"); +?> \ No newline at end of file diff --git a/res/comments b/res/comments new file mode 100644 index 0000000..b577094 --- /dev/null +++ b/res/comments @@ -0,0 +1,131 @@ +prepare("SELECT * FROM comments WHERE post_id = :pid ORDER BY date ASC"); + $stmt->bindParam(":pid", $_GET["post"]); + $stmt->execute(); + $row = $stmt->fetchAll(); + + if(isset($_GET["a"])){ + conn(); + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM alerts WHERE id = :id"); + $stmt->bindParam(":id", $_GET["a"]); + $stmt->execute(); + $res = $stmt->fetch(PDO::FETCH_OBJ); + if($res->mentionee == $current_user){ + alertDelete($_GET["a"]); + } + } +?> +
+
+
+ + prepare("SELECT * FROM comments WHERE id = :id"); + $rid = $_GET["report"]; + $stmt->bindParam(":id", $rid); + $stmt->execute(); + $comment = $stmt->fetch(PDO::FETCH_OBJ); + $commentID = intval($comment->id); + if($commentID!=""){ + $stmt = $conn->prepare("SELECT * FROM comments WHERE id = :id"); + $stmt->bindParam(":id", $commentID); + $stmt->execute(); + $return = $stmt->fetch(PDO::FETCH_OBJ); + $current = $return->reports; + if(strpos($current, $current_user) === false){ + $new = $current.$current_user.","; + $stmt = $conn->prepare("UPDATE comments SET reports = :new WHERE id = :id"); + $stmt->bindParam(":new", $new); + $stmt->bindParam(":id", $commentID); + $stmt->execute(); + if($stmt){ + msg("Comment reported."); + header("Refresh:0"); + }else{ + msg("Error reporting comment."); + header("Refresh:0"); + } + }else{ + msg("Your report has already been recorded."); + header("Refresh:0"); + } + } + } + + if(isset($_GET["reply"])){ + $name = getUserInfo($_GET["reply"])->name; + + $reply = "&reply=".$_GET["reply"]; + $repNotif = "

(Replying to $name)

"; + }else{ + $reply = $repNotif = ""; + } + ?> +
> +
+ +
+ +
+

Remember: we have rules!

+ +
+
+
+
+ + +
+ name; + $comment["text"] = decodeUserLink($comment["text"]); + $teacher = getUserInfo($comment["poster_id"])->teacher?"school":""; + if($comment["poster_id"] == $current_user){ + $repDel = "

delete

"; + }else{ + $repDel = "report"; + } + + if($_GET["a"]==$comment['id']){ + $a = "current"; + echo ""; + }else{ + $a = ""; + } + echo " +
+ +
+

".$uname."".$teacher." ".makeDate($comment['date'])."

+
+
".hyperlink($comment['text'])."
+
+ ".$repDel." + Reply +
+
"; + } + ?> + +
+
+
\ No newline at end of file diff --git a/res/head b/res/head new file mode 100644 index 0000000..9c176fe --- /dev/null +++ b/res/head @@ -0,0 +1,23 @@ + + + IB Forum + + + dark_theme){ + echo ""; + } + ?> + .css> + .css> + + + + snow){ + echo ""; + } + ?> + + + \ No newline at end of file diff --git a/res/i/clip.png b/res/i/clip.png new file mode 100644 index 0000000..e137f7d Binary files /dev/null and b/res/i/clip.png differ diff --git a/res/i/favicon.png b/res/i/favicon.png new file mode 100644 index 0000000..7721806 Binary files /dev/null and b/res/i/favicon.png differ diff --git a/res/i/ham.png b/res/i/ham.png new file mode 100644 index 0000000..4ade581 Binary files /dev/null and b/res/i/ham.png differ diff --git a/res/i/logo.png b/res/i/logo.png new file mode 100644 index 0000000..2360b7b Binary files /dev/null and b/res/i/logo.png differ diff --git a/res/i/user.png b/res/i/user.png new file mode 100644 index 0000000..2127a76 Binary files /dev/null and b/res/i/user.png differ diff --git a/res/montserrat.ttf b/res/montserrat.ttf new file mode 100644 index 0000000..a3cf5f5 Binary files /dev/null and b/res/montserrat.ttf differ diff --git a/res/notifs b/res/notifs new file mode 100644 index 0000000..b24d80f --- /dev/null +++ b/res/notifs @@ -0,0 +1,93 @@ +prepare("DELETE FROM notices WHERE id = :id"); + $stmt->bindParam(":id", $_GET["del"]); + $stmt->execute(); + header("Location: /forum"); + } + + if(isset($_POST["notif"])&&verifyUser("admin")){ + conn(); + $stmt = $conn->prepare("INSERT INTO notices (text) VALUES (:text)"); + $stmt->bindParam(":text", $_POST["notif"]); + $stmt->execute(); + unset($_POST["notif"]); + header("Location: /forum"); + } +?> +"; + + //Adding notifs + echo"\n
+

ADD NOTIFS

+
+ +
+
+

DELETE NOTIFS

+

You can delete any notif by clicking on it. Keep in mind that once you click it, it's gone forever. Don't delete something if you aren't sure it should be deleted!

+ Make sure notifs apply to everyone!

+
"; + } + ?> +
\ No newline at end of file diff --git a/res/randomZone b/res/randomZone new file mode 100644 index 0000000..d085b3c --- /dev/null +++ b/res/randomZone @@ -0,0 +1,64 @@ +
+

RANDOM ZONE

+

+ name), + "Left handed people tend to be more artistic.", + "I hope you're not going to leave this site... that literally kills me, you know.", + "Ctrl (or cmd on Mac) + Shift + T reopens your last closed tab.", + "Aliens probably don't go to school.", + "^-^", + "Edelman has a Keurig you can use.", + "Does Santa know when I procrastinate?", + "You're in a coma.
We're trying a new technique to get to you.
Please wake up.
We miss you.", + "The patent for toilet paper shows it going over, not under.", + "Luke Ogburn carries mints in his backpack. Just ask and he'll give you one!", + "Someone ate my pringes :(", + "What if time goes backwards, but we just don't notice because our memories rewind too.", + "You seem like a nice person.", + "The school's layout is based off of that of a prison's.", + "Text someone you like and tell them why you like them. They'll appreciate it.", + "Rice isn't that hard to cook.", + "I wonder if there are any secret passages in the school.", + "Pineapples have neither pines nor apples in them.", + "Fear is information, don't ignore it.", + "If you're hungry, then eat.", + "If you're thirsty, then drink", + "Give yourself time. Butterflies don't form in a day.", + "Ask yourself: What would make me happy today?", + "Beauty shouldn't be pain. Being comfortable will make you happy, which will make you beautiful.", + "The more people use this site, the better it becomes.", + "Onions don't cry when they chop humans.", + "Never trust a plastic hippo.", + "Tabs are just capital spaces.", + "The very existence of socks is proof that shoes don't work.", + "Humans are the only creatures who care about time. Maybe it doesn't matter as much as we think it does.", + "People like you.", + "Chicken is better than turkey and you can't change my mind.", + "You look great today.", + "People are happy when you're happy, because they like you and want you to succeed in life.", + "In dog years, humans regularly live to 800+ years old. They probably think we're immortal or something.", + "If tipping were illegal, wait staff would be paid more and wouldn't neet tips in the first place.", + "I, for one, think that you're a good person." + ]; + $randomArray = array_filter($randomArray); + echo $randomArray[mt_rand(0, sizeof($randomArray)-1)]; + ?> +

+
\ No newline at end of file diff --git a/res/roboto.ttf b/res/roboto.ttf new file mode 100644 index 0000000..2c97eea Binary files /dev/null and b/res/roboto.ttf differ diff --git a/res/rules b/res/rules new file mode 100644 index 0000000..9d294ff --- /dev/null +++ b/res/rules @@ -0,0 +1,7 @@ +
+ + \ No newline at end of file diff --git a/search/index.php b/search/index.php new file mode 100644 index 0000000..52682bc --- /dev/null +++ b/search/index.php @@ -0,0 +1,125 @@ + + + + + + +
+ 0?$_GET["page"]:1; + $GLOBALS["check"] = $limit * ($page - 1); + + function search($statement, $searchByClass){ + $limit = $GLOBALS["limit"] + 1; + $page = $GLOBALS["page"]; + $start = ($limit - 1) * ($page - 1); + //$limit is set one higher to check if there will be a next page, but is subtracted in the $start math because the math relies on the limit. + + if($searchByClass == false){ + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM forums WHERE (title LIKE CONCAT('%', :search, '%')) OR (content LIKE CONCAT('%', :search, '%')) ORDER BY date DESC LIMIT $start,$limit"); + }else{ + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM forums WHERE (title LIKE CONCAT('%', :search, '%') AND section = :section) OR (content LIKE CONCAT('%', :search, '%') AND section = :section) ORDER BY date DESC LIMIT $start,$limit"); + $stmt->bindParam(":section", $searchByClass); + } + $stmt->bindParam(":search", $statement); + $stmt->execute(); + return $stmt->fetchAll(); + } + + function searchClassOnly($searchByClass){ + $limit = $GLOBALS["limit"] + 1; + $page = $GLOBALS["page"]; + $start = ($limit - 1) * ($page - 1); + //The above was just copied from function search() + //If the user looks up something like "chemistry:", there will be no results so might as well give them ALL of the chemistry posts + $stmt = $GLOBALS['conn']->prepare("SELECT * FROM forums WHERE section = :section ORDER BY date DESC LIMIT $start,$limit"); + $stmt->bindParam(":section", $searchByClass); + $stmt->execute(); + return $stmt->fetchAll(); + } + + //Setting the array for storing posts' ID, used to make sure results only turn up once. Also initializing the counter for amount of posts + $resArray = array(); + $count = 0; + + //Getting class specification, returning false if none + preg_match_all("#([A-Za-z]+)(?=:)#", strtok($_GET["q"], " "), $matches); + $class = strtolower($matches[0][0]); + $classes = file_get_contents($_SERVER['DOCUMENT_ROOT']."/res/classes"); + $classes = array_filter(explode(",", $classes)); + if(in_array($class, $classes)){ + $searchByClass = $class; + }else{ + $searchByClass = false; + } + + //Getting more exact results by searching for strict phrase + foreach(search($search, $searchByClass) as $post){ + $resArray[] = $post["post_id"]; + } + + //Getting more general results by searching for each word indevidually + $noSpaces = preg_replace('/\s+/', ' ', $_GET["q"]." "); + //Adding the space to the GET[q] solves the issue where searching nothing in a class (e.g. "history:") didn't turn up results + $search = $searchByClass==false?$noSpaces:substr($noSpaces, strpos($noSpaces, ":")+1); + $search = explode(" ", strtolower($search)); + $exclude = explode("\n", file_get_contents("stopwords.txt")); + $search = array_diff($search, $exclude); + //gets rid of superflous stop words in search + foreach(array_filter($search) as $word){ + foreach(search($word." ", $searchByClass) as $post){ + $resArray[] = $post["post_id"]; + } + foreach(search(" ".$word, $searchByClass) as $post){ + $resArray[] = $post["post_id"]; + } + } + + if(count(array_filter($search)) == 0 && $searchByClass != false){ + foreach(searchClassOnly($searchByClass) as $post){ + $resArray[] = $post["post_id"]; + } + } + + $resArray = array_unique($resArray); + + foreach($resArray as $post){ + $count++; + } + + echo "

"; + if($count==1){ + echo "There was 1 result"; + }else if($count > $GLOBALS["limit"] || $GLOBALS["page"] > 1){ + echo "There were lots of results"; + }else{ + echo "There were $count results"; + } + echo "

"; + + foreach($resArray as $post){ + makePost(getPostInfo($post)); + } + + $resArray = array_slice($resArray, 0, $GLOBALS["limit"]); + + $page = $GLOBALS["page"]; + $query = urlencode($_GET["q"]); + echo "
"; + echo $page!=1?"":"
"; + echo $count>$GLOBALS["limit"]?"":"
"; + echo "
"; + ?> +
+ + \ No newline at end of file diff --git a/search/search.css b/search/search.css new file mode 100644 index 0000000..d32f8ee --- /dev/null +++ b/search/search.css @@ -0,0 +1,4 @@ +#results{ + width: 60%; + margin: 5% auto; +} \ No newline at end of file diff --git a/search/stopwords.txt b/search/stopwords.txt new file mode 100644 index 0000000..c38cebb --- /dev/null +++ b/search/stopwords.txt @@ -0,0 +1,174 @@ +a +about +above +after +again +against +all +am +an +and +any +are +aren't +as +at +be +because +been +before +being +below +between +both +but +by +can't +cannot +could +couldn't +did +didn't +do +does +doesn't +doing +don't +down +during +each +few +for +from +further +had +hadn't +has +hasn't +have +haven't +having +he +he'd +he'll +he's +her +here +here's +hers +herself +him +himself +his +how +how's +i +i'd +i'll +i'm +i've +if +in +into +is +isn't +it +it's +its +itself +let's +me +more +most +mustn't +my +myself +no +nor +not +of +off +on +once +only +or +other +ought +our +ours +ourselves +out +over +own +same +shan't +she +she'd +she'll +she's +should +shouldn't +so +some +such +than +that +that's +the +their +theirs +them +themselves +then +there +there's +these +they +they'd +they'll +they're +they've +this +those +through +to +too +under +until +up +very +was +wasn't +we +we'd +we'll +we're +we've +were +weren't +what +what's +when +when's +where +where's +which +while +who +who's +whom +why +why's +with +won't +would +wouldn't +you +you'd +you'll +you're +you've +your +yours +yourself +yourselves \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..bd67bb7 --- /dev/null +++ b/style.css @@ -0,0 +1,403 @@ +/* ------------- Site-wide Rules ------------- */ +@font-face{ + font-family: Roboto; + src: url('res/roboto.ttf'); +} +@font-face{ + font-family: Montserrat; + src: url('res/montserrat.ttf'); +} +body{ + margin: 0; + font-family: 'Roboto', sans-serif; + background-color: #f0f0f0; +} +html{ + font-size: 100%; +} +h1, h2, h3, h4, h5, h6{ + font-family: 'Montserrat', sans-serif; +} +h2{ + font-size: 1.4em; +} +input, button{ + outline-width: 0; +} +span[onclick]:hover{ + cursor: pointer; + text-decoration: underline; +} +a.color{ + color: #00bc8f; + text-decoration: none; +} +a.color:hover{ + text-decoration: underline; +} +.noSelect, .tags{ + -webkit-touch-callout: none; /* iOS Safari */ + -webkit-user-select: none; /* Safari */ + -khtml-user-select: none; /* Konqueror HTML */ + -moz-user-select: none; /* Firefox */ + -ms-user-select: none; /* Internet Explorer/Edge */ + user-select: none; /* Non-prefixed version, currently + supported by Chrome and Opera */ +} +.card{ + color: #333; + background-color: white; + margin-bottom: 2em; + border-radius: 0.2em; + padding: 1em; +} +.card.noMargin{ + margin-bottom: 0; +} +.card:not(.noShadow){ + box-shadow: 1px 1px 3px #ddd; +} +.card:hover:not(.noShadow):not(.noHover){ + box-shadow: 1px 2px 3px #bbb; +} + +.postReport{ + font-size: 0.8em; + float: left; +} +.postReport>a{ + text-decoration: none; + color: #888; +} +.postReport>a:hover{ + text-decoration: underline; +} + +.center{ + text-align: center; +} +.noStyle{ + color: inherit; + text-decoration: none; +} +.noStyle:hover{ + text-decoration: underline; +} +.smallWidth{ + width: 70%; + margin-left: auto; + margin-right: auto; +} +button[type="submit"]:not(#commentSubmitButton){ + 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; +} +button[type="submit"]:hover{ + cursor: pointer; +} + +/* ------------- Global forums ------------- */ +#container{ + width: 80%; + margin: 3% auto; + display: grid; + grid-template-columns: 3fr 1fr; + grid-column-gap: 3%; +} +#container>*{ + border-radius: 0.3em; +} +#monoContainer{ + width: 45%; + margin: 3% auto; + max-height: 80vh; +} +#monoContainer>*{ + border-radius: 0.3em; +} +p[onclick]:hover, span[onclick]:hover, button:hover{ + cursor: pointer; +} +.commentTop>p>.material-icons{ + font-size: 0.9em !important; +} +/* General forum stuff */ +.forumLink{ + text-decoration: none; +} +/* ------------- Posts ------------- */ +/* Title, username, time posted */ +.title>h2{ + margin: 0.3em 0 0.4em 0; +} +.preview>p{ + margin: 0.3em 0; +} +.info>*{ + font-size: 0.75em; + color: #888; + margin: 0; + display: inline-block; +} +.userlink:hover, .postType:hover{ + text-decoration: underline; +} +.postType{ + color: #666; + font-weight: bold; + margin: 0 0.5em 0 0.2em; +} +.forum{ + overflow: hidden; +} + + +/* Text, clip, image of post previews */ +.postPrevImg.clip{ + width: 0.67em; + margin-bottom: 0.08em; + margin-left: 0.3em; + display: inline; +} +.forum.image{ + display: grid; + grid-template-columns: 3fr 1fr; + grid-column-gap: 1em; +} +.postPrevImg{ + width: 100%; + min-height: 100%; + max-height: 100%; + object-fit: cover; +} + +/* Back/next buttons at bottom of forum page */ +#pages{ + font-size: 1.6em; + display: grid; + grid-gap: 3em; + grid-template-columns: 1fr 1fr; +} +#pages>div>a{ + color: #555; + text-decoration: none; +} +#prevPage{ + margin-left: auto; +} +#nextPage{ + margin-right: auto; +} + +msg{ + position: fixed; + left: 50%; + top: -100px; + transform: translateX(-50%); + z-index: 4; + display: flex; + justify-content: center; + align-items: center; + border: 1px solid #ccc; + border-radius: 0.7em; + padding: 0.5em 1em; + /* Leaving animation */ + animation: move; + animation-duration: 3s; +} +msg.neutral{ + background-color: white; + color: black; +} +@keyframes move { + 15% { + top: 20%; + } + 95%{ + top: 20%; + } + 100% { + top: -50px; + } +} + +/* @tagging people */ +.userRefLink{ + color: inherit; + text-decoration: none; +} +.userRefLink:hover{ + text-decoration: underline; +} + +/* Notifs */ +#right{ + text-align: center; + align-self: start; + line-height: 1.3em; +} +#notifAdminMsg{ + font-size: 0.9em; +} +#notifAdder{ + width: calc(100% - 0.6em); + margin-top: 1em; + font-size: 1em; + border-radius: 0.3em; + border: 1px solid #ccc; + padding: 0.3em; +} +.notifTitle{ + margin: 0; +} +.notif{ + margin-top: 0.5em; + margin-bottom: 0; +} +.deletable{ + color: inherit; + text-decoration: none; +} +.deletable:hover{ + color: red; + text-decoration: line-through; +} +/* Mentions (alerts) */ +.alert{ + color: inherit; + text-decoration: none; + display: block; + margin-bottom: 0.4em; +} +.alert:hover{ + text-decoration: underline; +} + +/* ------------- For the top bar ------------- */ +#topSpacer{ + height: 2em; + padding: 1% 0; +} +#top{ + text-align: center; + display: grid; + grid-template-columns: 1fr 8fr 1fr 1fr; + height: 2em; + align-items:center; + padding: 1% 5%; + width: 90%; + margin: 0 auto; + background-color: white; + position: fixed; + top: 0; + z-index: 8; + box-shadow: 0 1px 2px #ddd; +} +#top>*{ + margin: auto; +} +/* Left-side logo */ +#logoLink{ + display: flex; +} +#logo{ + height: 2em; + margin: 0 auto 0 0; +} + +/* Search bar */ +#search{ + margin: auto 0; +} +#searchBar{ + border-radius: 0.3em; + width: 80%; + height: 2em; + padding: 2px 10px 0px 10px; + font-size: 1em; + background-color: #f4f4f4; + border: 0; + outline-width: 0; + color: #444; + margin: auto 0; +} +#searchBar::-webkit-input-placeholder { + color: #999 !important; +} +#searchBar:-moz-placeholder { /* Firefox 18- */ + color: #999 !important; +} +#searchBar::-moz-placeholder { /* Firefox 19+ */ + color: #999 !important; +} +#searchBar:-ms-input-placeholder { + color: #999 !important; +} +/* Add post button */ +#addPost{ + cursor: pointer; + margin: 0 auto; + height: 100%; + border-radius: 0.3em; +} +#addPost>a{ + color: #00d09f; + display: block; + text-decoration: none; + padding: 0.5em 1em; +} +#addPost:hover{ + background-color: #f4f4f4; +} +/* Right-side account image */ +#accountWrapper{ + height: inherit; + margin: auto 0 auto auto; + border-radius: 50%; +} +#account{ + border-radius: 50%; + height: inherit; + margin: auto 0 auto auto; +} + +/*Tooltips*/ +.tooltip { + position: relative; +} +.tooltip .tooltiptext { + visibility: hidden; + width: 120px; + background-color: #555; + color: #fff; + text-align: center; + border-radius: 6px; + padding: 5px 0; + position: absolute; + z-index: 1; + bottom: 125%; + left: 50%; + margin-left: -60px; + opacity: 0; + transition: opacity 0.3s; +} +.tooltip .tooltiptext::after { + content: ""; + position: absolute; + top: 100%; + left: 50%; + margin-left: -5px; + border-width: 5px; + border-style: solid; + border-color: #555 transparent transparent transparent; +} +.tooltip:hover .tooltiptext { + visibility: visible; + opacity: 1; +} \ No newline at end of file diff --git a/test.php b/test.php new file mode 100644 index 0000000..9b20ed9 --- /dev/null +++ b/test.php @@ -0,0 +1,16 @@ + + + + + + <?php echo $url; ?> + + + + + \ No newline at end of file diff --git a/unset.css b/unset.css new file mode 100644 index 0000000..e69de29 diff --git a/user/banned.php b/user/banned.php new file mode 100644 index 0000000..e543260 --- /dev/null +++ b/user/banned.php @@ -0,0 +1,28 @@ +special!="banned"){ + $title = "

YOU HAVE NOT BEEN BANNED

"; + $message = "

Why are you even here?

"; + }else{ + $title = "

YOU HAVE BEEN BANNED

"; + $message = "

An admin has banned you and left the following message:

\n

".getUserInfo($current_user)->ban_reason."

"; + } +?> + + + + + +
+
+ + +
+
+ + \ No newline at end of file diff --git a/user/callback.php b/user/callback.php new file mode 100644 index 0000000..ce89d45 --- /dev/null +++ b/user/callback.php @@ -0,0 +1,76 @@ +fetchAccessTokenWithAuthCode($_GET['code']); + } else { + reportError('callback.php: $_GET["code"] was not set!'); + msg("Internal error. It has been reported."); + header("Location: /"); + } + + $oAuth = new Google_Service_Oauth2($client); + $user = $oAuth->userinfo->get(); + + //Adding cookie token thing + conn(); + $stmt = $conn->prepare("INSERT INTO login_tokens (token, user_id) VALUES (:ac, :id)"); + $id = substr($user->email, 0, strlen("@students.hcps.us")); + $access = password_hash($token["access_token"], PASSWORD_DEFAULT); + $stmt->bindParam(':ac', $access); + $stmt->bindParam(':id', $id); + $stmt->execute(); + + //Updating last login timestamp + $stmt = $conn->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE id = :id"); + $stmt->bindParam(':id', $id); + $stmt->execute(); + + setcookie("IB_SESSION", $token["access_token"], time() + (60*60*24*14), "/", NULL, true, true); + setcookie("IB_ID", substr($user->email, 0, strlen("@students.hcps.us")), time() + (60*60*24*14), "/", NULL, true, true); + + //Checking if user is in database + $dbID = getUserInfo($id)->id; //$id from above used + + if(substr($user->email, -7) != "hcps.us"){ + header("Location: https://ib.lukeogburn.com/user/reqHcps.php"); + }else if($id!=$dbID){ + //putting user in database if they aren't already + $stmt = $conn->prepare("INSERT INTO users (id, name, image_url, teacher) VALUES (:id, :nm, :im, :tc)"); + $stmt->bindParam(':id', $id); + $name = str_replace(" ", "_", $user["name"]); + $stmt->bindParam(':nm', $name); + $stmt->bindParam(':im', $user["picture"]); + $teacher = is_numeric($id)?NULL:true; + $stmt->bindParam(':tc', $teacher); + $stmt->execute(); + if(!$stmt){ + reportError("Error signing in (013)"); + msg("Error. Try again, maybe? This has been reported."); + header("Location: /"); + } + + msg("You have been logged in"); + header("Location: https://ib.lukeogburn.com/forum/"); + }else{ + //updating the user's profile picture just in case they changed it in Google + $stmt = $GLOBALS['conn']->prepare("UPDATE users SET image_url = :im WHERE id = :id"); + $stmt->bindParam(':im', $user->picture); + $stmt->bindParam(':id', $id); + $result = $stmt->execute(); + if(!$result){ + reportError("Error in callback - code 014"); + msg("Error. It has been reported. Try again, maybe?"); + header("Location: /"); + } + + msg("You have been logged in"); + header("Location: https://ib.lukeogburn.com/forum/"); + } +?> \ No newline at end of file diff --git a/user/config.php b/user/config.php new file mode 100644 index 0000000..e184e7a --- /dev/null +++ b/user/config.php @@ -0,0 +1,8 @@ +setAuthConfig($_SERVER['DOCUMENT_ROOT'].'/googleApi/creds.json'); + $client->addScope(Google_Service_Oauth2::PLUS_LOGIN); + $client->addScope(Google_Service_Oauth2::USERINFO_EMAIL); + $client->setRedirectUri("https://ib.lukeogburn.com/user/callback.php"); +?> \ No newline at end of file diff --git a/user/finishLogout.php b/user/finishLogout.php new file mode 100644 index 0000000..befd3e4 --- /dev/null +++ b/user/finishLogout.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/user/index.php b/user/index.php new file mode 100644 index 0000000..78a8646 --- /dev/null +++ b/user/index.php @@ -0,0 +1,211 @@ +id; + $name = $row->name; + $classes = $row->classes; + $grade = $row->grade; + $image = $row->image_url; + $teacher = $row->teacher; + + if($_COOKIE["IB_ID"]==$_GET['user']){ + $accountOwner = true; + }else{ + $accountOwner = false; + } + + if($id == NULL){ + msg("User doesn't exist."); + header('Location: https://ib.lukeogburn.com/forum/'); + } +?> + + + + + +
+ +
+ + + \n"; + } + if($accountOwner){ + if(verifyUser("admin")){ + $admin = "

Admin Portal

"; + } + echo "
+ +
"; + } + ?> + + + +
+
+ 0?$_GET["page"]:1; + $start = $limit * ($page - 1); + //setting amount of posts allowed on page + + if($_GET["type"]=="saved"){ + //Getting the saved posts + conn(); + $stop = $limit+1; + $stmt = $conn->prepare("SELECT * FROM bookmarks WHERE user_id = :uid ORDER BY unused_id DESC LIMIT $start,$stop"); + $stmt->bindParam(":uid", $_GET["user"]); + $stmt->execute(); + $row = $stmt->fetchAll(); + $count = $stmt->rowCount(); + $row = array_slice($row, 0, $limit); + foreach($row as $thing){ + $stmt = $conn->prepare("SELECT * FROM forums WHERE post_id = :pid"); + $stmt->bindParam(":pid", $thing["post_id"]); + $stmt->execute(); + $post = $stmt->fetchAll(); + makePost($post[0]); + } + if($count == 0){ + $referer = $accountOwner?"your":getUserInfo($_GET["user"])->name."'s"; + echo "

This is where ".$referer." saved posts would be

"; + } + }else{ + //Getting user's posts + conn(); + $stop = $limit+1; + $stmt = $conn->prepare("SELECT * FROM forums WHERE poster_id = :pid ORDER BY date DESC LIMIT $start,$stop"); + $stmt->bindParam(":pid", $_GET["user"]); + $stmt->execute(); + $row = $stmt->fetchAll(); + $count = $stmt->rowCount(); + $row = array_slice($row, 0, $limit); + foreach($row as $post){ + makePost($post); + } + + } + + //Getting how many posts the user has made + $stmt = $conn->prepare("SELECT COUNT(*) FROM forums WHERE poster_id = :id"); + $stmt->bindParam(":id", $_GET["user"]); + $stmt->execute(); + $numOfPosts = $postCount = $stmt->fetchColumn(0); + $numOfPosts = $numOfPosts==1?"$numOfPosts Post":"$numOfPosts Posts"; + + if($postCount == 0 && $_GET["type"]!="saved"){ + $referer = $accountOwner?"your":getUserInfo($_GET["user"])->name."'s"; + echo "

This is where ".$referer." posts would be

"; + } + + //Page arrows + echo "
"; + $user = $_GET["user"]; + $type = $_GET["type"]; + echo $page!=1?"":"
"; + echo $count>$limit?"":"
"; + echo "
"; + ?> +
+ \n"; + } + if($accountOwner){ + if(verifyUser("admin")){ + $admin = "

Admin Portal

"; + } + echo ""; + } + ?> +
+ + + \ No newline at end of file diff --git a/user/login.php b/user/login.php new file mode 100644 index 0000000..a0ac203 --- /dev/null +++ b/user/login.php @@ -0,0 +1,7 @@ +createAuthUrl(); + header("Location: ".$authUrl); + +?> \ No newline at end of file diff --git a/user/logout.php b/user/logout.php new file mode 100644 index 0000000..70a0710 --- /dev/null +++ b/user/logout.php @@ -0,0 +1,13 @@ +prepare("DELETE FROM login_tokens WHERE user_id = :tk"); + $stmt->bindParam(":tk", $_COOKIE["IB_ID"]); + $stmt->execute(); + + setcookie("IB_ID", $_COOKIE["IB_ID"], time()-3600, "/"); + setcookie("IB_SESSION", $_COOKIE["IB_SESSION"], time()-3600, "/"); + + header("Location: finishLogout.php"); + //Without this, PHP can't tell the cookie was deleted. It's dumb but it works. +?> \ No newline at end of file diff --git a/user/reqHcps.php b/user/reqHcps.php new file mode 100644 index 0000000..ecd0324 --- /dev/null +++ b/user/reqHcps.php @@ -0,0 +1,59 @@ +prepare("DELETE FROM login_tokens WHERE user_id = :tk"); + $stmt->bindParam(":tk", $_COOKIE["IB_ID"]); + $stmt->execute(); + + setcookie("IB_ID", $_COOKIE["IB_ID"], time()-3600, "/"); + setcookie("IB_SESSION", $_COOKIE["IB_SESSION"], time()-3600, "/"); +?> + + + + + + + +
+

You need to use your school account.

+
+ +
+
+
+

+ If you weren't given the option, you need to:
+

+
    +
  1. Go to google.com
  2. +
  3. Sign in with your HCPS account
  4. +
  5. Re-login here
  6. +
+
+

+
+ + \ No newline at end of file diff --git a/user/settings.php b/user/settings.php new file mode 100644 index 0000000..4d2bb15 --- /dev/null +++ b/user/settings.php @@ -0,0 +1,101 @@ +prepare("SELECT * FROM users WHERE id = :id"); + $id = $current_user; + $stmt->bindParam(":id", $id); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_OBJ); + $GLOBALS['grade'] = $row->grade; + $GLOBALS['userClasses'] = explode(",", $row->classes); + $GLOBALS['name'] = $row->name; + $GLOBALS['teacher'] = $row->teacher; + $GLOBALS['dark_theme'] = $row->dark_theme; + $GLOBALS['snow'] = $row->snow; + + function dt($val){ + if($val == $GLOBALS['dark_theme']){ + return "checked"; + } + } + function sw($val){ + if($val == $GLOBALS['snow']){ + return "checked"; + } + } +?> + + + + + +
+
+

Account Settings

+
+

Dark theme?

+ > + + > + + + +

Snow?

+ > + + > + + +

What is your name?

+ > + + + What grade level are you?

+ + + + + + + + + +

Which of these classes are you in?

"; + $classes = file_get_contents($_SERVER['DOCUMENT_ROOT']."/res/classes"); + $classes = array_filter(explode(",", $classes)); + $tag = 1; + foreach($classes as $class){ + echo "\n"; + $tag++; + } + } + ?> + + +
+
+
+
+ + \ No newline at end of file diff --git a/user/updateFunc.php b/user/updateFunc.php new file mode 100644 index 0000000..3f2b60f --- /dev/null +++ b/user/updateFunc.php @@ -0,0 +1,64 @@ +20){ + msg("You cannot have a name with more than 20 characters"); + header("Location: /user/updateInfo.php"); + exit(); + }else if(strContains($_POST["name"], " ")){ + msg("You cannot have a space in your username"); + header("Location: /user/updateInfo.php"); + exit(); + }else if(preg_match('#[^a-zA-Z0-9\-_]+#', $_POST["name"])){ + preg_match_all('#[^a-zA-Z0-9\-_]#', $_POST["name"], $match); + for($i=0; $iname != "" && getUserInfoByName($_POST["name"])->id != $id){ + msg("That name is already taken"); + header("Location: /user/updateInfo.php"); + exit(); + } + + //Actually putting the info in the database + conn(); + $stmt = $GLOBALS['conn']->prepare("UPDATE users SET name = :nm, grade = :gd, classes = :cs, dark_theme = :dt, snow = :sw WHERE id = :id"); + $stmt->bindParam(":nm", $_POST["name"]); + $stmt->bindParam(":gd", $_POST["grade"]); + $stmt->bindParam(":cs", $classes); + $stmt->bindParam(":dt", $_POST["dark_theme"]); + $stmt->bindParam(":sw", $_POST["snow"]); + $stmt->bindParam(":id", $id); + $stmt->execute(); + + if($stmt){ + msg("Information updated"); + }else{ + reportError("Error given at end of /user/updateFunc.php"); + msg("Error updating. It has been reported."); + } + header("Location: https://ib.lukeogburn.com/user/?user=".$id); +?> \ No newline at end of file diff --git a/user/updateInfo.css b/user/updateInfo.css new file mode 100644 index 0000000..13350b6 --- /dev/null +++ b/user/updateInfo.css @@ -0,0 +1,80 @@ +html, body{ + height: calc(100% - 1em); + /* Allows the body content be centered vartically. + No idea why the "-1em" part matters, but it does and it works so don't touch it unless you are willing to see the proccess through + */ +} +#midtainer{ + display: flex; + height: calc(100% - 2em - 4%); + /* 100% - top bar thing */ + align-items: center; + justify-content: center; +} +#updateCard{ + display: inline-block; + padding: 2em 4em; + margin: 5% auto; + text-align: center; +} +.question{ + font-size: 1.1em; + margin-top: 2em; + margin-bottom: 0.7em; +} +select{ + padding: 0.3em 2em; + align-items: center; + justify-content: center; + background-color: #eee; + border: none; + outline-width: 0; + font-size: 0.9em; +} +option{ + text-align: center; +} +form>label:not(.sideBySide){ + margin-left: auto; + margin-right: auto; +} +form>label:not(.sideBySide){ + display: block; +} +.sideBySide{ + display: inline; +} +.sideBySide:not(:last-of-type){ + margin-right: 1%; +} +input[type=checkbox], input[type=radio]{ + display: none; +} +.tagLabel{ + display: inline-block; +} +label:not(:last-of-type){ + margin-bottom: 0.3em; +} +input[type=checkbox]:checked+label, input[type=radio]:checked+label{ + color: #00d09f; +} +input[type=text]:not(#searchBar){ + border: none; + border-bottom: 1px solid black; + outline-width: 0; + text-align: center; + font-size: 1em; + margin-bottom: calc(1em + 1px); +} +button[type=submit]{ + font-size: 1em; + background-color: white; + color: #00d09f; + border: 1px solid #00d09f; + padding: 0.5em 1em; + margin-top: 2em; +} +label:hover, button:hover{ + cursor: pointer; +} \ No newline at end of file diff --git a/user/user.css b/user/user.css new file mode 100644 index 0000000..64afb9c --- /dev/null +++ b/user/user.css @@ -0,0 +1,76 @@ +#container{ + grid-template-columns: 2fr 1fr; +} +/* General forum stuff */ +.forumLink{ + text-decoration: none; +} +/* Choosing section to view */ +#userTopWrapper{ + height: 2em; + background-color: white; + box-shadow: 0 1px 3px #ddd; + display: flex; + justify-content: center; + align-items: center; + position: relative; + z-index: 5; +} +.userTopSel{ + color: black; + text-decoration: none; + margin: 0 1em 2px 1em; +} +.userTopSel[active]{ + margin-bottom: 0; + padding-bottom: 1px; + border-bottom: 2px solid #00d09f; + border-radius: 0.2em; +} +.userTopSel:hover:not([active]){ + margin-bottom: 0; + border-bottom: 2px solid #2ce4b9; + border-radius: 0.2em; +} +#top{ + box-shadow: none; /* Overriding the top bar's shadow */ +} +/*Didn't know where to put these so I put it here*/ +#userImg{ + border-radius: 50%; +} +#userActions>p>a{ + color: inherit; + text-decoration: none; +} +#userActions>p>a:not(:first-of-type){ + margin-top: 0.6em; +} +#userActions>p>a:hover{ + text-decoration: underline; +} + +/* User info */ +#right{ + background-color: rgba(0,0,0,0); + padding: 0; + margin: 0; + border: none; + box-shadow: none; +} +.infoDump>h2{ + text-overflow: ellipsis; +} +#userImg{ + width: 30%; + display: block; + margin: 0 auto; +} +.infoDump{ + display: block; +} +.infoDump>p{ + text-align: center; + margin: 0; + margin-top: 0.7em; +} \ No newline at end of file