Skip to content

Commit

Permalink
Add in uploader & channel support
Browse files Browse the repository at this point in the history
  • Loading branch information
HotPizzaYT authored Jul 26, 2021
1 parent 567c777 commit 14a8bcd
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 11 deletions.
35 changes: 34 additions & 1 deletion addComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@
// echo "<br>Could not submit your comment. The code in our system simply doesn't work at the moment! Just look at the data above.<br /><a href='view.php?id=" . $_POST["id"] . "'>Go back to the video</a>";
file_put_contents("ids/" . $_POST["id"]. ".json", $commentFix);
} else {
session_start();
if(isset($_POST["content"]) && isset($_POST["id"]) && !isset($_POST["author"]) && isset($_SESSION["username"])){
// session_start();
$id = $_POST["id"];
$author = $_SESSION["username"];
$content = $_POST["content"];

$json = file_get_contents("ids/" . $id . ".json");
$jsonD = json_decode($json, true);
$cdata = $jsonD["comments"];
$cid = count($jsonD["comments"]) + 1;

$comArr = ["comments" =>["poster"=>$author, "content"=>$content, "likes"=>0, "dislikes"=>0, "cid"=>$cid]];
// var_dump($comArr);


// Need to push the ["comments"] to the other comments
$commentFixed = $comArr["comments"];

array_push($jsonD["comments"], $commentFixed);
// These DO work!

// var_dump($jsonD["comments"]);
$commentFix = json_encode($jsonD, true);

// That's SNAXOR!


header("Location: view.php?id=" . $_POST["id"]);
// echo "<br>Could not submit your comment. The code in our system simply doesn't work at the moment! Just look at the data above.<br /><a href='view.php?id=" . $_POST["id"] . "'>Go back to the video</a>";
file_put_contents("ids/" . $_POST["id"]. ".json", $commentFix);
} else {
echo "Error";
}
}
?>
?>
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ function search() {
<br />
<h3>Want to upload your own video?</h3>
<a href="upload.php">Go to this link to upload your video!</a>
<h3>Want to have a profile?</h3>
<a href="accounts/index.php">Go here to login, or manage your own account</a>
<br>
<div style="background-color: #f0f0f0; width: 50%; border-radius: 16px;">
<h1>News</h1>
Expand Down
46 changes: 40 additions & 6 deletions upload.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?php
session_start();
?>

<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -54,6 +58,16 @@ function search() {
Select a video to upload:
<input type="file" name="video" id="video">
<br>
<p>Uploader (Optional)</p>

<input type="text" name="uploader" value="<?php
if(isset($_SESSION["username"]) && isset($_SESSION["email"])){
// You can't disable this or it won't go through!
// Good thing though is that it'll still add to user acc.
echo $_SESSION["username"] . "\" disabled=\"true";
} else {
echo "Anonymous";
} ?>" />
<p>Title (Required)</p>
<input type="text" required name="title" >
<p>Description (Required)</p>
Expand Down Expand Up @@ -89,13 +103,13 @@ function generateVideoID($length = 16){
// Set this to true to bypass.
$isConfirmedVideo = false;
if(isset($_FILES['video']['tmp_name']) && !empty(FILEINFO_MIME_TYPE)) {
// $finfo = finfo_open(FILEINFO_MIME_TYPE);
// $mime = finfo_file($finfo, $_FILES['video']['tmp_name']);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['video']['tmp_name']);
$extension = explode(".", $_FILES['video']['name']);
$end = count($extension) - 1;
$ext = $extension[$end];
// echo $ext;
// $filetype = explode("/", $mime);
$filetype = explode("/", $mime);

// Insert all supported video types.

Expand All @@ -121,14 +135,34 @@ function generateVideoID($length = 16){
// $comments = array();
// Create a blank array with no comments.
$commentData = array();
$videoData = array("title"=>$_POST["title"], "desc"=>$_POST["desc"], "location"=>$_POST["location"], "src"=>$path, "likes"=>0, "dislikes"=>0, "views"=>0, "comments"=>$commentData);
if(isset($_POST["uploader"]) && $_POST["uploader"] !== ""){
$uploader = $_POST["uploader"];
} else {
if(isset($_SESSION["username"])){
$uploader = $_SESSION["username"];
} else {
$uploader = "Anonymous";
}
}

$videoData = array("title"=>$_POST["title"], "desc"=>$_POST["desc"], "location"=>$_POST["location"], "src"=>$path, "uploader" => $uploader, "likes"=>0, "dislikes"=>0, "views"=>0, "comments"=>$commentData);

$idlength = rand(8, 16);

$videoId = generateVideoID($idlength);
$vidDstring = json_encode($videoData);
file_put_contents("ids/". $videoId . ".json", $vidDstring);

if(isset($_SESSION["username"]) && isset($_SESSION["email"])){
// Add video to profile.
$vidarr = ["videos"=>[$videoId]];
$accTxt = file_get_contents("accounts/data/" . $_SESSION["username"] . ".json");
$accJson = json_decode($accTxt, true);
// Add video to array of videos.
array_push($accJson["videos"], $videoId);
// Save to file.
$accFinal = json_encode($accJson);
file_put_contents("accounts/data/" . $_SESSION["username"] . ".json", $accFinal);
}

} else {
echo "Your video has not been uploaded. REASON: ";
Expand Down Expand Up @@ -163,4 +197,4 @@ function generateVideoID($length = 16){
}
?>
</body>
</html>
</html>
16 changes: 12 additions & 4 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function loadTime(){
</center>
</div>
<?php
session_start();

$url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i';
if(isset($_GET["id"])){
Expand Down Expand Up @@ -216,11 +217,18 @@ function loadTime(){



if(file_exists("accounts/data/" . $jsonD["uploader"] . ".json")){
// Yes!
$uploader = "<a href='channel.php?id=" . htmlspecialchars($jsonD["uploader"]) . "'>" . htmlspecialchars($jsonD["uploader"]) . "</a>";
} else {
$uploader = htmlspecialchars($jsonD["uploader"]);
}


$htmlcontent = "<h1>" . htmlspecialchars($vt) . "</h1><div style='text-align: center;'><video style='width: 50%; height: 50%; text-align: center;' src='" . $src . "' controls='' uk-video=''>Whoops! Your browser doesn't support video files.</video></div><br /><br /><br /><div style='float: right; text-align: right;'>Likes: " . $likes . ", Dislikes: " . $dislikes . "<br />" . $likeBar . "<br />"

. $views . " views<br /><button onclick='" . $lfun . "'>Like</button> - <button onclick='" . $dlfun . "'>Dislike</button></div><b>Location:</b> " . $loc . "<br /><b>Description:</b> <br />" . $vd;
echo $htmlcontent;

. $views . " views<br /><button onclick='" . $lfun . "'>Like</button> - <button onclick='" . $dlfun . "'>Dislike</button></div><b>Uploader:</b> " . $uploader . "<br /><b>Location:</b> " . $loc . "<br /><b>Description:</b> <br />" . $vd;
echo $htmlcontent;
if($commentsSet){
$commentAmount = count($comments);
$commentSection = "<h1>Comments (" . $commentAmount . ")</h1><hr>";
Expand Down Expand Up @@ -255,7 +263,7 @@ function loadTime(){
<h1>Add a comment</h1>
<form action="addComment.php" method="post" enctype="multipart/form-data">
<p>Your name (required)</p>
<input type="text" required name="author" id="author">
<input type="text" required value="<?php if(isset($_SESSION["username"])){ echo $_SESSION["username"] . "\" disabled title=\"You are logged in!"; } else { echo "Anonymous"; } ?>" name="author" id="author">
<input type="hidden" value="<?php echo $_GET["id"]; ?>" name="id">
<br>
<p>Text (Required)</p>
Expand Down

0 comments on commit 14a8bcd

Please sign in to comment.