2020-05-16 18:18:32 +00:00
|
|
|
<?php
|
2020-05-23 21:47:15 +00:00
|
|
|
require 'Database.php';
|
|
|
|
|
|
|
|
$conn = Database::getInstance()->getConnection();
|
2020-05-16 18:18:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['action'])) {
|
2020-05-23 21:47:15 +00:00
|
|
|
$action = $_POST['action'];
|
|
|
|
switch ($action) {
|
|
|
|
case "getMovies":
|
2020-05-29 15:19:19 +00:00
|
|
|
$query = "SELECT movie_id,movie_name FROM videos ORDER BY likes DESC, create_date ASC, movie_name ASC";
|
2020-06-02 14:15:12 +00:00
|
|
|
if (isset($_POST['tag'])) {
|
|
|
|
$tag = $_POST['tag'];
|
2020-06-02 20:52:28 +00:00
|
|
|
if ($_POST['tag'] != "all") {
|
2020-06-02 14:15:12 +00:00
|
|
|
$query = "SELECT movie_id,movie_name FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id
|
|
|
|
WHERE t.tag_name = '$tag'
|
|
|
|
ORDER BY likes DESC, create_date ASC, movie_name ASC";
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 15:19:19 +00:00
|
|
|
$result = $conn->query($query);
|
|
|
|
$rows = array();
|
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
|
|
|
array_push($rows, $r);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo(json_encode($rows));
|
|
|
|
break;
|
|
|
|
case "getRandomMovies":
|
2020-06-02 20:52:28 +00:00
|
|
|
$query = "SELECT movie_id,movie_name FROM videos ORDER BY RAND() LIMIT " . $_POST['number'];
|
2020-05-23 21:47:15 +00:00
|
|
|
$result = $conn->query($query);
|
|
|
|
$rows = array();
|
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
2020-05-24 09:49:37 +00:00
|
|
|
array_push($rows, $r);
|
2020-05-23 21:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo(json_encode($rows));
|
|
|
|
break;
|
|
|
|
case "loadVideo":
|
2020-06-02 20:52:28 +00:00
|
|
|
$query = "SELECT movie_name,movie_url,thumbnail,likes,quality,length FROM videos WHERE movie_id='" . $_POST['movieid'] . "'";
|
2020-05-23 21:47:15 +00:00
|
|
|
|
|
|
|
$result = $conn->query($query);
|
|
|
|
$row = $result->fetch_assoc();
|
|
|
|
|
|
|
|
$arr = array();
|
|
|
|
$arr["thumbnail"] = $row["thumbnail"];
|
2020-06-02 20:52:28 +00:00
|
|
|
$arr["movie_name"] = $row["movie_name"];
|
2020-05-23 21:47:15 +00:00
|
|
|
$arr["movie_url"] = $row["movie_url"];
|
2020-05-24 14:16:45 +00:00
|
|
|
$arr["likes"] = $row["likes"];
|
2020-06-02 14:15:12 +00:00
|
|
|
$arr["quality"] = $row["quality"];
|
|
|
|
$arr["length"] = $row["length"];
|
2020-05-23 21:47:15 +00:00
|
|
|
echo(json_encode($arr));
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "getDbSize":
|
|
|
|
$query = "SELECT table_schema AS \"Database\",
|
|
|
|
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS \"Size\"
|
|
|
|
FROM information_schema.TABLES
|
2020-05-24 09:49:37 +00:00
|
|
|
WHERE TABLE_SCHEMA='hub'
|
2020-05-23 21:47:15 +00:00
|
|
|
GROUP BY table_schema;";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
|
|
|
|
if ($result->num_rows == 1) {
|
|
|
|
$row = $result->fetch_assoc();
|
2020-05-24 09:49:37 +00:00
|
|
|
echo '{"data":"' . $row["Size"] . 'MB"}';
|
2020-05-23 21:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "readThumbnail":
|
|
|
|
$query = "SELECT thumbnail FROM videos WHERE movie_id='" . $_POST['movieid'] . "'";
|
|
|
|
|
|
|
|
$result = $conn->query($query);
|
|
|
|
$row = $result->fetch_assoc();
|
|
|
|
|
|
|
|
echo($row["thumbnail"]);
|
|
|
|
|
2020-05-24 09:49:37 +00:00
|
|
|
break;
|
|
|
|
case "getTags":
|
2020-05-24 14:16:45 +00:00
|
|
|
$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'";
|
2020-05-24 09:49:37 +00:00
|
|
|
|
|
|
|
$result = $conn->query($query);
|
|
|
|
|
2020-05-24 14:16:45 +00:00
|
|
|
$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'";
|
2020-05-24 09:49:37 +00:00
|
|
|
|
2020-05-24 14:16:45 +00:00
|
|
|
if ($conn->query($query) === TRUE) {
|
|
|
|
echo('{"result":"success"}');
|
|
|
|
} else {
|
|
|
|
echo('{"result":"' . $conn->error . '"}');
|
|
|
|
}
|
2020-05-23 21:47:15 +00:00
|
|
|
break;
|
2020-06-02 20:52:28 +00:00
|
|
|
case "getStartData":
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
$arr = array();
|
|
|
|
$arr['total'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['tagged'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id
|
|
|
|
WHERE t.tag_name='hd'";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['hd'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id
|
|
|
|
WHERE t.tag_name='fullhd'";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['fullhd'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id
|
|
|
|
WHERE t.tag_name='lowquality'";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['sd'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM tags";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['tags'] = $r['nr'];
|
|
|
|
|
|
|
|
echo(json_encode($arr));
|
|
|
|
break;
|
2020-05-23 21:47:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo('{"data":"error"}');
|
2020-05-16 18:18:32 +00:00
|
|
|
}
|
2020-05-23 21:47:15 +00:00
|
|
|
return;
|
|
|
|
|