Commit 4655b566 authored by carboncrafters's avatar carboncrafters

api and sql changes

parent c3515aed
......@@ -16,12 +16,12 @@ function test_input($data) {
return $data;
}
header("Content-Type:application/json; charset=UTF-8");
if(!empty($_GET["type"])){
if ($_GET["type"]=="video") {
if(!empty($_GET["request"]) && $_GET["request"]=="views"){
if(isset($_GET["get"])){
switch ($_GET["get"]) {
case "views":
if (!empty($_GET["id"])) {
$id = test_input($_GET["id"]);
$sql = "SELECT * FROM videos WHERE id='$id'";
$sql = "SELECT views, deleted FROM ids WHERE id='$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
......@@ -40,6 +40,7 @@ if ($result->num_rows > 0) {
$return["description"]="The content referenced with this id was deleted from our servers! Sorry about that :/";
echo json_encode($return);
header("HTTP/1.0 410 Gone");
}
} else {
......@@ -51,8 +52,209 @@ if ($result->num_rows > 0) {
}
$conn->close();
}
break;
case 'title':
if (!empty($_GET["id"])) {
$id = test_input($_GET["id"]);
$sql = "SELECT `name`, deleted FROM ids WHERE id='$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$title = $row["name"];
$deleted = $row["deleted"];
}
if ($deleted=="0") {
$return["title"] = $title;
echo json_encode($return);
}else{
$return["error"]="true";
$return["type"]="410";
$return["description"]="The content referenced with this id was deleted from our servers! Sorry about that :/";
echo json_encode($return);
header("HTTP/1.0 410 Gone");
}
} else {
$return["error"]="true";
$return["type"]="404";
$return["description"]="The content referenced with this id can not be found in our database! Sorry about that :/";
echo json_encode($return);
header("HTTP/1.0 404 Not Found");
}
}else if($_GET["image"]){
$conn->close();
}
break;
case 'basic':
if (!empty($_GET["id"])) {
$id = test_input($_GET["id"]);
$sql = "SELECT id, `name`, `date`, views, descr, user, deleted FROM ids WHERE id='$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$title = $row["name"];
$deleted = $row["deleted"];
}
if ($deleted=="0") {
$return["id"] = $row["id"];
$return["title"] = $title;
$return["upload_date"] = $row["date"];
$return["views"] = $row["views"];
$return["description"] = $row["descr"];
$return["uid"] = $row["user"];
echo json_encode($return);
}else{
$return["error"]="true";
$return["type"]="410";
$return["description"]="The content referenced with this id was deleted from our servers! Sorry about that :/";
echo json_encode($return);
header("HTTP/1.0 410 Gone");
}
} else {
$return["error"]="true";
$return["type"]="404";
$return["description"]="The content referenced with this id can not be found in our database! Sorry about that :/";
echo json_encode($return);
header("HTTP/1.0 404 Not Found");
}
$conn->close();
}
break;
case 'menu':
if(isset($_GET["language"])){
switch ($_GET["language"]) {
case 'hu':
$return["upl"] = "Feltöltés";
$return["img"] = "Képek";
$return["vid"] = "Videók";
$return["randompw"] = "Random jelszó generáló";
$return["infinite"] = "Végtelen file";
$return["search"] = "Privát keresés";
$return["login"] = "Bejelentkezés";
$return["reg"] = "Regisztráció";
$return["about"] = "Rólunk";
$return["lng"] = "Nyelv";;
echo json_encode($return);
break;
default:
$return["upl"] = "Upload";
$return["img"] = "Images";
$return["vid"] = "Videos";
$return["randompw"] = "Random password generator";
$return["infinite"] = "Infinite file";
$return["search"] = "Privacy search";
$return["login"] = "Login";
$return["reg"] = "Register";
$return["about"] = "about";
$return["lng"] = "Language";
echo json_encode($return);
break;
}}else{
$return["upl"] = "Upload";
$return["img"] = "Images";
$return["vid"] = "Videos";
$return["randompw"] = "Random password generator";
$return["infinite"] = "Infinite file";
$return["search"] = "Privacy search";
$return["login"] = "Login";
$return["reg"] = "Register";
$return["about"] = "about";
$return["lng"] = "Language";
echo json_encode($return);
}
break;
default:
$return["error"]="true";
$return["type"]="421";
$return["description"]="The uri you requested is not a valid api request! Please try an other way and or look up the documentation at https://emalm.com/info/api";
echo json_encode($return);
header("HTTP/1.0 421 Misdirected request");
break;
}
}elseif (isset($_GET["set"])) {
switch ($_GET["set"]) {
case 'views':
if (!empty($_GET["id"])) {
$id = test_input($_GET["id"]);
$sql = "SELECT views, deleted FROM ids WHERE id='$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$views = $row["views"];
$deleted = $row["deleted"];
}
if ($deleted=="0") {
$sql = "UPDATE videos SET views=views + 1 WHERE id='$id' ";
if ($conn->query($sql) === TRUE) {
$return["error"]="true";
$return["type"]="410";
$return["description"]="The content referenced with this id was deleted from our servers! Sorry about that :/";
echo json_encode($return);
header("HTTP/1.0 200 Ok");
} else {
$return["error"]="true";
$return["type"]="500";
$return["description"]="An error happened while processing your request, we are very sorry! mysql said: ".$conn->error;
echo json_encode($return);
header("HTTP/1.0 500 Internal server error");
}
$return["views"] = $views;
echo json_encode($return);
}else{
$return["error"]="true";
$return["type"]="410";
$return["description"]="The content referenced with this id was deleted from our servers! Sorry about that :/";
echo json_encode($return);
header("HTTP/1.0 410 Gone");
}
} else {
$return["error"]="true";
$return["type"]="404";
$return["description"]="The content referenced with this id can not be found in our database! Sorry about that :/";
echo json_encode($return);
header("HTTP/1.0 404 Not Found");
}
$conn->close();
}
break;
default:
$return["error"]="true";
$return["type"]="421";
$return["description"]="The uri you requested is not a valid api request! Please try an other way and or look up the documentation at https://emalm.com/info/api";
echo json_encode($return);
header("HTTP/1.0 421 Misdirected request");
break;
}
}else{
$return["error"]="true";
$return["type"]="421";
$return["description"]="The uri you requested is not a valid api request! Please try an other way and or look up the documentation at https://emalm.com/info/api";
echo json_encode($return);
header("HTTP/1.0 421 Misdirected request");
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.emalm.com/js/include.js"></script>
<script src="https://cdn.emalm.com/js/setlang.js"></script>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
document.getElementById("upl").innerHTML = myObj.upl;
document.getElementById("img").innerHTML = myObj.img;
document.getElementById("vid").innerHTML = myObj.vid;
document.getElementById("randompw").innerHTML = myObj.randompw;
document.getElementById("infinite").innerHTML = myObj.infinite;
document.getElementById("search").innerHTML = myObj.search;
document.getElementById("login").innerHTML = myObj.login;
document.getElementById("reg").innerHTML = myObj.reg;
document.getElementById("about").innerHTML = myObj.about;
document.getElementById("lng").innerHTML = myObj.lng;
}
};
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
xmlhttp.open("GET", "https://emalm.com/api/?get=menu&language="+getCookie(language), true);
xmlhttp.send();
</script>
<nav class="navbar navbar-inverse navbar-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/">Emalm</a>
</div>
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="/upl/" id="upl">
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="/?upl=p" id="img"></a></li>
<li><a href="/?upl=v" id="vid"></a></li>
</ul>
</li>
<li><a href="/?vid" id="vid"> </a></li>
<li><a href="/?img" id="img"></a></li>
<li><a href="/randompw/" id="randompw"></a></li>
<li><a href="/infinite/" id="infinite"></a></li>
<li><a href="/about/" id="about"></a></li>
<li><a href="https://search.emalm.com" id="search"></a></li>
</ul><ul class="nav navbar-nav navbar-right">
<li><a href="/login/"><span class="glyphicon glyphicon-log-in"></span><div id="login"></div></a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" id="lng">
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#" onclick="setlang('en')">English</a></li>
<li><a href="#" onclick="setlang('hu')">Magyar</a></li>
</ul>
</li>
</ul>
</div>
</nav><br/>
\ No newline at end of file
......@@ -108,15 +108,10 @@ include $_SERVER["DOCUMENT_ROOT"].'/'.$displang.'/menu.html'; ?>
<tr width="90%"><td>
<b>Views:
<?php
//print out the views and count it
/*
print($obj["views"]++);
$json = json_encode($obj);
file_put_contents('/cdn/json/v_'.$browlin[0].'.json', $json);
/*/
echo $views++;
echo $views;
require $_SERVER["DOCUMENT_ROOT"].'/conn.php';
$sql = "UPDATE videos SET views='$views' WHERE id='$browlin[0]' ";
$sql = "UPDATE videos SET views=views + 1 WHERE id='$browlin[0]' ";
if ($conn->query($sql) === TRUE) {
} else {echo "Error: " . $sql . "<br>" . $conn->error;}
?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment