-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
51 lines (42 loc) · 1.34 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
*API-Dokumentation
*URL parametrar:
*id = Return MV with specified ID
*cnt = Return MV with ordered numbered specified
*add = Adds a new MV
*type >
*=daily
*=stories = Returns all
*no parameters = Returns all MVs
*
*returns json format
*/
include 'functions.php';
$db = new PDO('sqlite:zahabe.db');
if (isset($_GET['id'])) {
$rows = getMVByID($db, $_GET['id']);
} else if (isset($_GET['cnt'])) {
$rows = getMVByNumber($db, $_GET['cnt']);
} else if (isset($_GET['add'])) {
/*Not implemented*/
print "To be implemented";
} else if(isset($_GET['type'])) {
if ($_GET['type'] == "daily") {
$rows = getDailyMV($db);
} else if ($_GET['type'] == "stories"){
$rows = getAllStories($db);
}
} else {
$stmt = $db->prepare("SELECT Text, ID, Story, (select count(*) from MinnsDu b where a.id >= b.id) as cnt
FROM MinnsDu a LEFT JOIN Stories ON a.ID = Stories.MVID ORDER BY ID asc");
$stmt->execute();
$rows = $stmt->fetchAll();
}
if (empty($rows)){
echo json_encode(["error" => "404 not found"]);
http_response_code(404);
} else
print_r(json_encode($rows));
$db = NULL;
?>