From eb9a855467c4283f587d25b619d24ee88fa496d2 Mon Sep 17 00:00:00 2001 From: lukas Date: Sun, 24 May 2020 16:16:45 +0200 Subject: [PATCH] added like feature tag beginnings --- css/index.css | 22 +++++++++++++++++-- index.html | 46 ++++++++++++++++++++++++++++++++++++--- js/index.js | 55 +++++++++++++++++++++++++++++++++++++++++++++-- php/videoload.php | 30 ++++++++++++++++++++------ 4 files changed, 140 insertions(+), 13 deletions(-) diff --git a/css/index.css b/css/index.css index 66b790b..1c6fca1 100755 --- a/css/index.css +++ b/css/index.css @@ -1,9 +1,27 @@ .myvideo { - width: 80%; - margin-left: 10%; + width: 100%; float: left; } +.videoleftbanner{ + float: left; + width: 100%; + height: 100%; + background-color: #e5e5ff; + border-radius: 40px; +} +.likefield{ + margin-top: 15px; + margin-left: 15px; + margin-right: 15px; + height: 30px; + background-color: #9e5353; + border-radius: 10px; + text-align: center; + color: white; + +} + .previewcontainer { margin-left: 10%; width: 80%; diff --git a/index.html b/index.html index d199cb2..4983bb0 100755 --- a/index.html +++ b/index.html @@ -7,15 +7,55 @@ - + + + + + + + + + + + + + +

lukis pornhub

-
Close
-
+
+
+
+
Likes: 10
+
+
+
+
+
+
+
Close
+
+
+
+
+
+ + +
+
+ + + +
+
+ + +
+
diff --git a/js/index.js b/js/index.js index 6c3ea87..c0a52a7 100755 --- a/js/index.js +++ b/js/index.js @@ -1,6 +1,7 @@ let videos; let loadindex = 0; let scrollposition = 0; +let loadedvideoid = -1; $(document).ready(function () { $.post('php/videoload.php', 'action=getMovies', function (data) { @@ -13,6 +14,8 @@ $(document).ready(function () { }, 'json'); $(".closebutton").click(function () { + $("#likebtn").off(); + $("#tagbutton").off(); $(".videopagewrapper").hide(); $(".previewcontainer").show(); // scroll back to last scroll position @@ -23,7 +26,7 @@ $(document).ready(function () { $(window).scroll(function () { if ($(window).scrollTop() >= (($(document).height() - $(window).height() - 60))) { - if ($(".videowrapper").html() == "") { + if ($(".videowrapper").html() === "") { loadPreviewBlock(6); } } @@ -51,7 +54,8 @@ function loadPreview(src) { preview.click(function () { console.log("preview clicked"); scrollposition = $(window).scrollTop(); - loadVideo($(this).attr("movie_id")); + loadedvideoid = $(this).attr("movie_id"); + loadVideo(loadedvideoid); }); $(".previewcontainer").append(preview); }, 'text'); @@ -73,6 +77,53 @@ function loadVideo(movieid) { ], poster: data.thumbnail }; + + $(".likefield").html("Likes: " + data.likes); + + $.post('php/videoload.php', 'action=getTags&movieid=' + loadedvideoid, function (data) { + for (const tag in data.tags) { + $(".videoleftbanner").append(`
${tag}
`); + } + + console.log(data); + }, "json"); + + $("#likebtn").click(function () { + console.log("likebtn clicked"); + $.post('php/videoload.php', 'action=addLike&movieid=' + loadedvideoid, function (data) { + console.log(data); + }, "json"); + }); + + $("#tagbutton").click(function () { + console.log("tagbrn clicked"); + Swal.mixin({ + input: 'text', + confirmButtonText: 'Next →', + showCancelButton: true, + progressSteps: ['1', '2', '3'] + }).queue([ + { + title: 'Question 1', + text: 'Chaining swal2 modals is easy' + }, + 'Question 2', + 'Question 3' + ]).then((result) => { + if (result.value) { + const answers = JSON.stringify(result.value) + Swal.fire({ + title: 'All done!', + html: ` + Your answers: +
${answers}
+ `, + confirmButtonText: 'Lovely!' + }) + } + }) + }); + $(".videopagewrapper").show(); $(".previewcontainer").hide(); }, "json"); diff --git a/php/videoload.php b/php/videoload.php index c6c73f6..c50920d 100755 --- a/php/videoload.php +++ b/php/videoload.php @@ -18,7 +18,7 @@ if (isset($_POST['action'])) { echo(json_encode($rows)); break; case "loadVideo": - $query = "SELECT movie_url,thumbnail FROM videos WHERE movie_id='" . $_POST['movieid'] . "'"; + $query = "SELECT movie_url,thumbnail,likes FROM videos WHERE movie_id='" . $_POST['movieid'] . "'"; $result = $conn->query($query); $row = $result->fetch_assoc(); @@ -26,6 +26,7 @@ if (isset($_POST['action'])) { $arr = array(); $arr["thumbnail"] = $row["thumbnail"]; $arr["movie_url"] = $row["movie_url"]; + $arr["likes"] = $row["likes"]; echo(json_encode($arr)); break; @@ -39,7 +40,6 @@ if (isset($_POST['action'])) { if ($result->num_rows == 1) { $row = $result->fetch_assoc(); - echo '{"data":"' . $row["Size"] . 'MB"}'; } @@ -55,14 +55,32 @@ if (isset($_POST['action'])) { break; case "getTags": - $query = "SELECT * FROM video_tags INNER JOIN tags t on video_tags.tag_id = t.tag_id WHERE video_id='" . $_POST['movieid'] . "'"; - #$query = "SELECT thumbnail FROM videos WHERE movie_id='" . $_POST['movieid'] . "'"; + $movieid = $_POST['movieid']; + + $query = "SELECT tag_name FROM video_tags + INNER JOIN tags t on video_tags.tag_id = t.tag_id + WHERE video_id='$movieid'"; $result = $conn->query($query); - $row = $result->fetch_assoc(); - echo($row["thumbnail"]); + $rows = array(); + $rows['tags'] = array(); + while ($r = mysqli_fetch_assoc($result)) { + array_push($rows['tags'], $r['tag_name']); + } + echo(json_encode($rows)); + break; + case "addLike": + $movieid = $_POST['movieid']; + + $query = "update videos set likes = likes + 1 where movie_id = '$movieid'"; + + if ($conn->query($query) === TRUE) { + echo('{"result":"success"}'); + } else { + echo('{"result":"' . $conn->error . '"}'); + } break; } } else {